/* ── BASE STYLES ─────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  zoom: 1.3125;
}

html,
body {
  height: 100%;
  background: var(--bg-body);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 14px;
  line-height: 1.5;
  transition: background 0.3s ease;
}

/* topbar custom controls */
#topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

#rain-btn.rain-on {
  background: var(--bg-input);
  box-shadow: var(--shadow-input);
  color: var(--text-main);
}

#rain-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  transition: opacity 1.2s ease;
}

#rain-canvas.rain-visible {
  opacity: 1;
}

.tb-toggle {
  display: flex;
  border: var(--border-main);
  border-radius: var(--radius-btn);
  overflow: hidden;
  box-shadow: var(--shadow-btn);
  flex-shrink: 0;
}

.tb-toggle-btn {
  background: var(--bg-btn);
  color: var(--text-btn);
  border: none;
  padding: 5px 10px;
  font-family: inherit;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  outline: none;
  line-height: 1.4;
}

.tb-toggle-btn+.tb-toggle-btn {
  border-left: var(--border-main);
}

.tb-toggle-btn:hover {
  background: var(--bg-btn-hover);
}

.tb-toggle-btn.tb-active {
  background: var(--bg-input);
  box-shadow: var(--shadow-input);
  color: var(--text-main);
}

.tb-theme-wrap {
  position: relative;
  flex-shrink: 0;
}

.tb-theme-btn {
  background: var(--bg-btn);
  color: var(--text-btn);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  border-radius: var(--radius-btn);
  padding: 5px 10px;
  font-family: inherit;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  outline: none;
}

.tb-theme-btn:hover {
  background: var(--bg-btn-hover);
}

.tb-theme-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.tb-theme-arrow {
  font-size: 9px;
  opacity: 0.7;
}

.tb-theme-hotkey {
  font-size: 9px;
  font-weight: 700;
  opacity: 0.4;
  letter-spacing: 0;
  background: rgba(128, 128, 128, 0.18);
  border-radius: 3px;
  padding: 1px 4px;
  margin-left: 1px;
  font-family: monospace;
  line-height: 1.5;
}

.tb-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  left: auto;
  background: var(--bg-panel);
  border: var(--border-main);
  box-shadow: var(--shadow-panel);
  border-radius: var(--radius-btn);
  overflow: hidden;
  z-index: 9999;
  min-width: 130px;
  display: none;
}

.tb-dropdown.tb-open {
  display: block;
}

.tb-dd-item {
  padding: 8px 13px;
  font-size: 12px;
  font-weight: bold;
  color: var(--text-main);
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 7px;
}

.tb-dd-item:hover {
  background: rgba(128, 128, 128, 0.15);
}

.tb-dd-item.tb-cur {
  color: var(--text-dim);
  cursor: default;
}

.tb-dd-item.tb-cur::before {
  content: '\2713';
  font-size: 10px;
}

/* ── App size presets (desktop only) ──────────────────────────────────── */
body.app-size-2 #chat-screen-inner {
  max-width: 72%;
  margin: 0 auto;
}

body.app-size-3 #chat-screen-inner {
  max-width: 62%;
  margin: 0 auto;
}

#size-toggle {
  display: flex;
  border: var(--border-main);
  border-radius: var(--radius-btn);
  overflow: hidden;
  box-shadow: var(--shadow-btn);
  flex-shrink: 0;
}

#size-toggle .sz-btn {
  background: var(--bg-btn);
  color: var(--text-btn);
  border: none;
  padding: 5px 9px;
  font-family: inherit;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  outline: none;
  line-height: 1.4;
}

#size-toggle .sz-btn+.sz-btn {
  border-left: var(--border-main);
}

#size-toggle .sz-btn:hover {
  background: var(--bg-btn-hover);
}

#size-toggle .sz-btn.sz-active {
  background: var(--bg-input);
  box-shadow: var(--shadow-input);
  color: var(--text-main);
}

/* ==========================================================================
   JOIN SCREEN & MODALS
   ========================================================================== */

#join-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

#join-controls label {
  font-size: 11px;
  font-weight: bold;
  color: var(--text-dim);
  text-transform: uppercase;
  white-space: nowrap;
  margin: 0;
}

.join-ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

#join-theme-select,
#join-rounded-select {
  background: var(--bg-input);
  color: var(--text-main);
  border: var(--border-main);
  box-shadow: var(--shadow-input);
  border-radius: var(--radius-input);
  padding: 7px 8px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  width: 100%;
}

#join-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

#join-screen h1 {
  font-size: 1.6rem;
  font-weight: bold;
  color: var(--text-main);
  letter-spacing: 0.01em;
}

#join-card {
  background: var(--bg-panel);
  border: var(--border-main);
  border-radius: var(--radius-panel);
  padding: 20px 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 260px;
  box-shadow: var(--shadow-panel);
}

#username-input {
  background: var(--bg-input);
  border: var(--border-main);
  box-shadow: var(--shadow-input);
  color: var(--text-main);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  border-radius: var(--radius-input);
  width: 100%;
  text-align: center;
}

#username-input::placeholder {
  color: var(--text-dim);
  opacity: 0.6;
}

/* ── AVATAR UPLOAD ─────────────────────────────────────────────────────── */
#avatar-upload-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

#avatar-clear-btn {
  display: none;
}

#avatar-preview {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-msg);
  border: var(--border-main);
  background: var(--bg-input);
  box-shadow: var(--shadow-input);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-dim);
  cursor: pointer;
  transition: opacity 0.15s, border-color 0.15s;
  position: relative;
}

body:not(.no-radius) #avatar-preview {
  border-radius: var(--radius-panel);
}

#avatar-preview:hover {
  opacity: 0.8;
}

#avatar-preview img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#avatar-preview.has-image #avatar-placeholder-icon,
#avatar-preview.has-image #avatar-hint {
  display: none;
}

#avatar-hint {
  font-size: 10px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.5;
}

#avatar-clear-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0;
  font-family: inherit;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  opacity: 0.5;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#avatar-clear-btn:hover {
  opacity: 1;
  color: var(--text-main);
}

#join-btn {
  background: var(--bg-btn);
  color: var(--text-btn);
  border: var(--border-main);
  padding: 11px;
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-btn);
  width: 100%;
}

#join-btn:hover {
  background: var(--bg-btn-hover);
}

#join-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

#color-picker-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#color-picker-row label {
  font-size: 12px;
  font-weight: bold;
  color: var(--text-dim);
  text-transform: uppercase;
}

#color-swatches {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  box-sizing: border-box;
  transition: transform 0.1s, border-color 0.1s;
  flex-shrink: 0;
  outline: 1px solid rgba(128, 128, 128, 0.25);
}

.color-swatch:hover {
  transform: scale(1.2);
}

.color-swatch.selected {
  border-color: var(--text-main);
  transform: scale(1.2);
}

#join-error {
  color: #ff5555;
  font-size: 13px;
  min-height: 20px;
  text-align: center;
  font-weight: bold;
}

/* ==========================================================================
   CHAT SCREEN & SIDEBAR LAYOUT
   ========================================================================== */

#chat-screen {
  display: none;
  height: 100%;
  flex-direction: row;
  padding: 2vh 2vw;
}

#chat-screen-inner {
  display: flex;
  flex: 1;
  border-radius: var(--radius-panel);
  overflow: hidden;
  border: var(--border-main);
  box-shadow: var(--shadow-panel);
  background: var(--bg-panel);
}

#sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: var(--border-main);
  display: flex;
  flex-direction: column;
}

#sidebar-header {
  padding: 20px 18px 14px;
  background: var(--bg-header);
  border-bottom: var(--border-main);
  flex-shrink: 0;
}

#sidebar-header h1 {
  font-size: 18px;
  font-weight: bold;
}

#online-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 12px;
  font-weight: bold;
  color: var(--text-dim);
}

#online-badge::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--led-glow);
  box-shadow: 0 0 6px var(--led-glow), inset 0 -1px 2px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.5);
  display: inline-block;
}

#user-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

#user-list-label {
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 4px 8px 12px;
}

#user-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-item {
  font-size: 13px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-btn);
  flex-wrap: wrap;
}

.user-item>div:not(.user-avatar):not(.admin-actions) {
  overflow: hidden;
}

.user-item:hover {
  background: rgba(128, 128, 128, 0.1);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: bold;
  color: #fff;
  flex-shrink: 0;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.4), 0 1px 3px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.3);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
}

.user-name {
  word-break: break-word;
}

.user-name.me {
  font-style: italic;
}

.user-status {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
  line-height: 1.3;
  margin-top: 1px;
}

.user-status-emoji {
  margin-right: 3px;
}

#my-status-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  cursor: pointer;
  border-radius: var(--radius-btn);
  padding: 4px 6px;
  margin-left: -6px;
  transition: background 0.15s;
}

#my-status-row:hover {
  background: rgba(128, 128, 128, 0.1);
}

#my-status-text {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

#my-status-edit-icon {
  font-size: 11px;
  opacity: 0.45;
  flex-shrink: 0;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#topbar {
  height: 62px;
  background: var(--bg-header);
  border-bottom: var(--border-main);
  display: flex;
  align-items: center;
  padding: 0 24px;
  flex-shrink: 0;
  gap: 12px;
}

#topbar-title {
  font-size: 16px;
  font-weight: bold;
}

#topbar-count {
  font-size: 13px;
  font-weight: bold;
  color: var(--text-dim);
}

#reconnect-banner {
  display: none;
  background: #8a0000;
  border-bottom: 1px solid #4a0000;
  color: #fff;
  font-weight: bold;
  font-size: 13px;
  padding: 8px 24px;
  text-align: center;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#messages::-webkit-scrollbar {
  width: 14px;
}

#messages::-webkit-scrollbar-track {
  background: var(--bg-input);
  border-left: var(--border-main);
}

#messages::-webkit-scrollbar-thumb {
  background: var(--bg-btn);
  border: var(--border-main);
  border-radius: var(--radius-btn);
}

#empty-state {
  margin: auto;
  color: var(--text-dim);
  font-size: 15px;
  text-align: center;
  font-weight: bold;
}

/* ==========================================================================
   CROSS-MODE: ENTRANCE KINETICS & MENTIONS
   ========================================================================== */

@keyframes msg-slide-in {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes msg-row-flash {
  0% {
    background: rgba(255, 200, 50, 0.25);
  }

  100% {
    background: transparent;
  }
}

.msg.msg-flash {
  animation: msg-row-flash 1.2s ease-out;
  border-radius: var(--radius-msg);
}

.msg.mentioned {
  background: rgba(250, 166, 26, 0.1) !important;
  box-shadow: inset 3px 0 0 0 #faa61a !important;
  border-radius: 4px;
}

.msg-text .mention {
  background: rgba(250, 166, 26, 0.2) !important;
  color: #db8b0b;
  border-radius: 3px;
  padding: 1px 4px;
  font-weight: bold;
}

/* ==========================================================================
   ORIGINAL BASE MESSAGE STYLES (BUBBLE MODE DEFAULT)
   ========================================================================== */

.msg {
  position: relative;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 0;
  animation: msg-slide-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  will-change: transform, opacity;
}

.msg.grouped {
  padding-top: 2px;
}

/* Original Action Buttons inside bubble */
.msg-actions {
  position: absolute;
  top: 4px;
  right: 2px;
  display: none;
  gap: 1px;
  background: var(--bg-panel);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  border-radius: var(--radius-btn);
  z-index: 50;
  padding: 2px;
}

.msg:hover .msg-actions {
  display: flex;
}

.msg-action-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14px;
  padding: 0;
  border-radius: var(--radius-btn);
  line-height: 1;
}

.msg-action-btn:hover {
  color: var(--text-main);
  background: rgba(128, 128, 128, 0.18);
}

.msg-avatar-col {
  width: 36px;
  flex-shrink: 0;
}

.msg.grouped .msg-avatar-col {
  visibility: hidden;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.4), 0 2px 4px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.3);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
}

body:not(.no-radius) .msg-avatar {
  border-radius: 50%;
}

body:not(.no-radius) .user-avatar {
  border-radius: 50%;
}

.msg-body {
  flex: 1;
  min-width: 0;
}

.msg-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}

.msg.grouped .msg-header {
  display: none;
}

.msg-user {
  font-weight: bold;
  font-size: 13px;
}

.msg-time {
  font-size: 11px;
  color: var(--text-dim);
}

.msg-text {
  display: inline-block;
  background: var(--bg-msg);
  border: var(--border-main);
  box-shadow: var(--shadow-msg);
  color: var(--text-main);
  font-size: 14px;
  word-break: break-word;
  line-height: 1.5;
  white-space: pre-wrap;
  padding: 10px 14px;
  border-radius: var(--radius-msg);
}

.msg.own .msg-text {
  background: var(--bg-msg-own);
}

.msg-edited {
  font-size: 10px;
  opacity: 0.45;
  margin-left: 4px;
  font-style: italic;
  user-select: none;
}

.msg-system {
  text-align: center;
  padding: 12px 0;
  animation: none;
}

.msg-system-inner {
  display: inline-block;
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: bold;
  border: var(--border-main);
  border-radius: var(--radius-btn);
  padding: 4px 12px;
}

.msg-hover-time {
  display: none;
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  width: 36px;
  text-align: right;
  padding-top: 3px;
  user-select: none;
  line-height: 1.3;
}

.msg.grouped:hover .msg-avatar-col {
  visibility: visible;
}

.msg.grouped:hover .msg-avatar {
  display: none;
}

.msg.grouped:hover .msg-hover-time {
  display: block;
}

/* ── Base Reply Anatomy (Original L-Bracket) ── */
.msg-reply-preview {
  flex: 0 0 100%;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0;
  padding-bottom: 1px;
  cursor: pointer;
  min-width: 0;
}

.msg-reply-connector {
  width: 36px;
  flex-shrink: 0;
  height: 14px;
  position: relative;
  margin-right: 12px;
}

.msg-reply-connector::after {
  content: '';
  position: absolute;
  left: 17px;
  top: 4px;
  right: 0;
  bottom: -4px;
  border-top: 2px solid rgba(128, 128, 128, 0.28);
  border-left: 2px solid rgba(128, 128, 128, 0.28);
  border-top-left-radius: 7px;
}

.msg-reply-content {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  opacity: 0.75;
  transition: opacity 0.1s;
  min-width: 0;
}

.msg-reply-preview:hover .msg-reply-content {
  opacity: 1;
}

.msg-reply-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
}

.msg-reply-avatar {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  overflow: hidden;
}

.msg-reply-user {
  font-size: 12px;
  font-weight: bold;
  flex-shrink: 0;
  white-space: nowrap;
}

.msg-reply-text {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}


/* ==========================================================================
   COZY MODE (Discord / Modern Slack Standard)
   ========================================================================== */

/* Strip bubbles */
body.layout-cozy .msg-text,
body.layout-cozy .msg.own .msg-text {
  display: block !important;
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  border-radius: 0 !important;
}

/* Full-Row Hover Tracking & Block Chunking */
body.layout-cozy .msg {
  margin-left: -16px;
  margin-right: -16px;
  padding-left: 16px;
  padding-right: 16px;
  border-radius: 4px;
  transition: background 0.08s ease;
}

body.layout-cozy .msg:not(.grouped) {
  margin-top: 14px;
  padding-top: 4px;
  padding-bottom: 4px;
}

body.layout-cozy .msg.grouped {
  padding-top: 2px !important;
  padding-bottom: 2px !important;
}

body.layout-cozy .msg:hover {
  background: rgba(128, 128, 128, 0.06);
}

body.layout-cozy .msg.mentioned {
  padding-left: 16px;
}

/* The Safe Gutter (Overlap Fix) */
body.layout-cozy .msg-body {
  padding-right: 60px;
}

/* Elevated Action Pill for Cozy */
body.layout-cozy .msg-actions {
  top: -14px;
  right: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--bg-body);
  border-radius: 6px;
  transform: translateY(4px);
  opacity: 0;
  pointer-events: none;
}

body.layout-cozy .msg:hover .msg-actions {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Optical Avatar Alignment & Sweep Curve */
body.layout-cozy .msg-avatar {
  margin-top: 2px;
  border-radius: 50%;
}

body.layout-cozy .msg.grouped .msg-avatar {
  display: none !important;
}

body.layout-cozy .msg.grouped .msg-avatar-col {
  visibility: visible;
}

body.layout-cozy .msg.grouped:hover .msg-hover-time {
  display: block;
  font-size: 9px;
  text-align: center;
  line-height: 1.5;
  padding-top: 0;
  color: var(--text-dim);
}

body.layout-cozy .msg-reply-connector::after {
  top: 10px;
  border-top: 2px solid rgba(128, 128, 128, 0.3);
  border-left: 2px solid rgba(128, 128, 128, 0.3);
  border-top-left-radius: 12px;
}

/* Subdued Meta-data */
body.layout-cozy .msg-header {
  align-items: baseline;
  margin-bottom: 2px;
}

body.layout-cozy .msg-time {
  opacity: 0.6;
  font-size: 11px;
  letter-spacing: 0.02em;
}


/* ==========================================================================
   COMPACT MODE (IRC / Terminal Standard)
   ========================================================================== */

/* Structural reset */
body.layout-compact .msg {
  display: block;
  padding: 1px 0;
}

body.layout-compact .msg-avatar-col {
  display: none;
}

body.layout-compact .msg-body {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  min-width: 0;
  gap: 0;
}

/* Strip bubbles */
body.layout-compact .msg-text,
body.layout-compact .msg.own .msg-text {
  display: block !important;
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 0 0 6px !important;
  flex: 1;
  min-width: 0;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 0 !important;
}

/* Full-Row Tracking */
body.layout-compact .msg {
  margin-left: -12px;
  margin-right: -12px;
  padding-left: 12px;
  padding-right: 12px;
  transition: background 0.08s;
}

body.layout-compact .msg:hover {
  background: rgba(128, 128, 128, 0.08);
}

body.layout-compact .msg.mentioned {
  padding-left: 12px;
}

/* The Safe Gutter (Overlap Fix) */
body.layout-compact .msg-body {
  padding-right: 60px;
}

/* Elevated Action Pill for Compact */
body.layout-compact .msg-actions {
  top: -10px;
  right: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--bg-body);
  border-radius: 6px;
  transform: translateY(4px);
  opacity: 0;
  pointer-events: none;
}

body.layout-compact .msg:hover .msg-actions {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Terminal 90px Left Column */
body.layout-compact .msg-header {
  position: relative;
  display: flex !important;
  flex-direction: row;
  align-items: baseline;
  justify-content: flex-end;
  flex-shrink: 0;
  width: 90px;
  min-width: 90px;
  max-width: 90px;
  overflow: hidden;
  margin-bottom: 0;
  gap: 4px;
}

/* Tabular Typography & Formatting */
body.layout-compact .msg-time {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
  font-size: 10px;
  letter-spacing: -0.02em;
  opacity: 0.6;
  white-space: nowrap;
  flex-shrink: 1;
  overflow: hidden;
  line-height: 1.5;
}

body.layout-compact .msg-user {
  font-size: 12px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.5;
  flex-shrink: 1;
  min-width: 0;
}

body.layout-compact .msg-user::after {
  content: ':';
  margin-left: 1px;
  opacity: 0.6;
}

/* Ghost Timestamps (Grouped Mode) */
body.layout-compact .msg.grouped .msg-header {
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.15s ease;
}

body.layout-compact .msg.grouped:hover .msg-header {
  visibility: visible;
  opacity: 1;
}

body.layout-compact .msg.grouped:hover .msg-user {
  display: none;
}

body.layout-compact .msg.grouped:hover .msg-time {
  flex: 1;
  text-align: right;
  opacity: 0.4;
  overflow: visible;
}

body.layout-compact .msg.grouped:hover .msg-user::after {
  display: none;
}

/* COMPACT: Reply Preview Redesign (The ┌ Bracket) */
body.layout-compact .msg-reply-preview {
  display: flex;
  padding-left: 0;
  align-items: center;
}

body.layout-compact .msg-reply-connector {
  display: block;
  width: 90px;
  min-width: 90px;
  margin-right: 0;
  height: 14px;
  position: relative;
}

body.layout-compact .msg-reply-connector::after {
  content: '';
  position: absolute;
  left: auto;
  right: 6px;
  top: 50%;
  bottom: -6px;
  width: 12px;
  border-top: 2px solid rgba(128, 128, 128, 0.35);
  border-left: 2px solid rgba(128, 128, 128, 0.35);
  border-top-left-radius: 4px;
  border-right: none;
  border-bottom: none;
}

body.layout-compact .msg-reply-content {
  padding-left: 6px;
}

body.layout-compact .msg-reply-dot,
body.layout-compact .msg-reply-avatar {
  display: none;
}


/* ==========================================================================
   FLOATING LAYOUT SWITCHER
   ========================================================================== */

#layout-switcher {
  position: fixed;
  z-index: 200;
  display: none;
  width: 220px;
  border: var(--border-main);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-btn);
  overflow: hidden;
  left: -9999px;
  top: -9999px;
}

#layout-switcher .tb-toggle-btn {
  flex: 1;
  width: 33.33%;
  padding: 8px 0;
  font-size: 11px;
  text-align: center;
  border-left: var(--border-main);
}

#layout-switcher .tb-toggle-btn:first-child {
  border-left: none;
}

#layout-switcher {
  display: none;
}

body.app-size-3 #layout-switcher {
  display: flex;
}

/* ==========================================================================
   EDIT / REPLY BANNERS
   ========================================================================== */

#edit-banner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 0;
  font-size: 11px;
  font-weight: bold;
  color: var(--text-dim);
}

#edit-banner.visible {
  display: flex;
}

#edit-banner-label {
  flex: 1;
}

#edit-cancel-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
}

#edit-cancel-btn:hover {
  color: var(--text-main);
}

#reply-banner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 0;
  font-size: 11px;
  font-weight: bold;
  color: var(--text-dim);
}

#reply-banner.visible {
  display: flex;
}

#reply-banner-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#reply-banner-label em {
  font-weight: normal;
  font-style: normal;
  opacity: 0.75;
}

#reply-banner-text {
  font-weight: normal;
  opacity: 0.55;
  margin-left: 2px;
}

#reply-cancel-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
}

#reply-cancel-btn:hover {
  color: var(--text-main);
}


/* ==========================================================================
   INPUT AREA & BOTTOM CHROME
   ========================================================================== */

#bottom-chrome {
  background: var(--bg-bottom);
  border-top: var(--border-main);
  flex-shrink: 0;
}

#status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px 0;
  min-height: 26px;
}

#typing-bar {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: bold;
}

.msg-seen {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 3px 0 2px;
}

.seen-label {
  font-size: 10px;
  font-weight: bold;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.seen-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: bold;
  color: #fff;
  flex-shrink: 0;
  cursor: default;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.4), 0 1px 2px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.3);
}

#input-bar {
  padding: 10px 24px 20px;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

#msg-input {
  flex: 1;
  background: var(--bg-input);
  border: var(--border-main);
  box-shadow: var(--shadow-input);
  border-radius: var(--radius-input);
  padding: 10px 14px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  overflow-y: auto;
}

#msg-input::-webkit-scrollbar {
  width: 10px;
}

#msg-input::-webkit-scrollbar-thumb {
  background: var(--bg-btn);
  border-radius: var(--radius-btn);
  border: var(--border-main);
}

#msg-input::placeholder {
  color: var(--text-dim);
}

#msg-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#input-right {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#char-counter {
  font-size: 11px;
  font-weight: bold;
  color: var(--text-dim);
  min-width: 32px;
  text-align: right;
}

#char-counter.warn {
  color: #ffaa00;
}

#char-counter.limit {
  color: #ff5555;
}

#send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-btn);
  background: var(--bg-btn);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}

#send-btn:hover {
  background: var(--bg-btn-hover);
}

#send-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

#send-btn:disabled {
  filter: grayscale(1);
  opacity: 0.4;
  cursor: default;
  transform: none;
  box-shadow: none;
}

#send-btn svg path {
  stroke: var(--text-btn);
}

/* Global taps */
button,
input,
select,
textarea,
.color-swatch,
.user-item,
.tb-toggle-btn,
.tb-theme-btn,
.ctx-item,
.tb-dd-item {
  touch-action: manipulation;
}


/* ==========================================================================
   ATTACHMENTS & MEDIA
   ========================================================================== */

.msg-image {
  margin-top: 6px;
  max-width: 320px;
  border-radius: var(--radius-msg);
  overflow: hidden;
  cursor: pointer;
  display: block;
  border: var(--border-main);
  box-shadow: var(--shadow-msg);
}

.msg-image img {
  width: 100%;
  display: block;
}

#mic-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: var(--radius-btn);
  background: var(--bg-btn);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-btn);
  padding: 0;
  touch-action: manipulation;
}

#mic-btn:hover {
  background: var(--bg-btn-hover);
}

#mic-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

#mic-btn.mic-recording {
  color: #ff4c4c;
  animation: ar-pulse 1.15s ease-in-out infinite;
}

@keyframes ar-pulse {

  0%,
  100% {
    opacity: 1
  }

  50% {
    opacity: 0.35
  }
}

#rec-inline {
  display: none;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

#rec-dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #ff4c4c;
  animation: ar-pulse 1.15s ease-in-out infinite;
}

#rec-timer {
  font-size: 13px;
  font-weight: bold;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-main);
}

#rec-hint {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-main);
}

.msg-audio {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.30);
  border-radius: var(--radius-msg);
  padding: 7px 12px 7px 8px;
  margin-top: 4px;
  max-width: 300px;
  width: 300px;
  box-sizing: border-box;
}

.own .msg-audio {
  background: rgba(0, 0, 0, 0.22);
}

.audio-play-btn {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.26);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  padding: 0;
  touch-action: manipulation;
  transition: background 0.12s, transform 0.08s;
}

.audio-play-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.audio-play-btn:active {
  transform: scale(0.90);
}

.audio-waveform {
  flex: 1;
  min-width: 0;
  height: 36px;
  display: block;
}

.audio-dur {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.52);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-main);
}

#paste-preview {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 24px 0;
}

#paste-preview.visible {
  display: flex;
}

#paste-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-input);
  object-fit: cover;
  border: var(--border-main);
}

#paste-info {
  flex: 1;
  font-size: 12px;
  font-weight: bold;
}

#paste-cancel {
  background: var(--bg-btn);
  border: var(--border-main);
  color: var(--text-main);
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  padding: 4px 8px;
  border-radius: var(--radius-btn);
}

#paste-cancel:hover {
  background: #ff5555;
  color: #fff;
}

#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 32px;
}

#lightbox.visible {
  display: flex;
}

#lightbox img {
  max-width: min(88vw, 1100px);
  max-height: 82vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-panel);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  display: block;
}

#lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 19px;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10001;
  flex-shrink: 0;
  touch-action: manipulation;
}

#lightbox-close:active {
  background: rgba(255, 255, 255, 0.25);
}


/* ==========================================================================
   ADMIN PANEL
   ========================================================================== */

#admin-panel {
  border-top: var(--border-main);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

#admin-panel-row {
  display: flex;
  gap: 6px;
}

#admin-input {
  flex: 1;
  background: var(--bg-input);
  border: var(--border-main);
  box-shadow: var(--shadow-input);
  color: var(--text-main);
  padding: 6px 8px;
  font-family: inherit;
  font-size: 12px;
  outline: none;
  border-radius: var(--radius-input);
  min-width: 0;
}

#admin-input::placeholder {
  color: var(--text-dim);
  opacity: 0.6;
}

#admin-btn {
  background: var(--bg-btn);
  color: var(--text-btn);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  border-radius: var(--radius-btn);
  white-space: nowrap;
  flex-shrink: 0;
}

#admin-btn:hover {
  background: var(--bg-btn-hover);
}

#admin-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

body.is-admin #admin-panel {
  display: none;
}

#admin-status {
  font-size: 11px;
  font-weight: bold;
  min-height: 14px;
}

#admin-status.ok {
  color: #22c55e;
}

#admin-status.err {
  color: #ff5555;
}

.admin-actions {
  display: none;
  width: 100%;
  flex-direction: column;
  gap: 4px;
  padding: 6px 0 4px 0;
  border-top: 1px solid rgba(128, 128, 128, 0.2);
}

.admin-actions-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.admin-actions select {
  flex: 1;
  background: var(--bg-input);
  border: var(--border-main);
  color: var(--text-main);
  font-family: inherit;
  font-size: 11px;
  padding: 3px 4px;
  border-radius: var(--radius-input);
  min-width: 0;
}

.admin-action-btn {
  font-family: inherit;
  font-size: 11px;
  font-weight: bold;
  padding: 3px 7px;
  border-radius: var(--radius-btn);
  cursor: pointer;
  border: var(--border-main);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-kick {
  background: #ff5555;
  color: #fff;
  border-color: #cc3333;
}

.btn-kick:hover {
  background: #cc3333;
}

.btn-mute {
  background: #ffaa00;
  color: #000;
  border-color: #cc8800;
}

.btn-mute:hover {
  background: #cc8800;
  color: #fff;
}

.btn-purge {
  background: var(--bg-btn);
  color: var(--text-btn);
}

.btn-purge:hover {
  background: var(--bg-btn-hover);
}

.btn-unmute {
  background: #22c55e;
  color: #fff;
  border-color: #16a34a;
}

.btn-unmute:hover {
  background: #16a34a;
}

body.is-admin .user-item {
  cursor: pointer;
}

body.is-admin .user-item.expanded .admin-actions {
  display: flex;
}

.user-item.expanded {
  background: rgba(128, 128, 128, 0.08);
}

.msg-admin-notify {
  text-align: center;
  padding: 4px 0;
  font-size: 12px;
  font-weight: bold;
  color: #ffaa00;
}

.msg-muted-notice {
  text-align: center;
  padding: 4px 12px;
  font-size: 12px;
  color: #ffaa00;
  font-style: italic;
}

.admin-self-label {
  display: none;
  font-size: 10px;
  font-weight: bold;
  color: #ffaa00;
  letter-spacing: 0.04em;
  padding: 2px 0 6px 12px;
}

body.is-admin .admin-self-label {
  display: block;
}

.muted-badge {
  display: none;
  font-size: 9px;
  font-weight: bold;
  color: #ffaa00;
  border: 1px solid #ffaa00;
  padding: 1px 4px;
  border-radius: var(--radius-btn);
  margin-left: 4px;
}

body.is-admin .muted-badge {
  display: inline-block;
}

#admin-badge {
  display: none;
  font-size: 11px;
  font-weight: bold;
  color: #ffaa00;
  border: 1px solid #ffaa00;
  padding: 2px 7px;
  border-radius: var(--radius-btn);
  margin-left: 8px;
  flex-shrink: 0;
}

body.is-admin #admin-badge {
  display: inline-block;
}

.kick-btn {
  display: none;
  margin-left: auto;
  background: none;
  border: 1px solid #ff5555;
  color: #ff5555;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: var(--radius-btn);
  flex-shrink: 0;
  line-height: 1.4;
}

.kick-btn:hover {
  background: #ff5555;
  color: #fff;
}

body.is-admin .kick-btn {
  display: inline-block;
}

#kicked-screen {
  display: none;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

#kicked-screen h2 {
  font-size: 1.4rem;
  font-weight: bold;
  color: #ff5555;
}

#kicked-screen p {
  color: var(--text-dim);
  font-size: 14px;
}

.user-admin-crown {
  color: #ffaa00;
  font-size: 12px;
  margin-left: 2px;
}


/* ==========================================================================
   DM CONTEXT MENU & WINDOWS
   ========================================================================== */

#dm-ctx-menu {
  position: fixed;
  z-index: 9000;
  background: var(--bg-panel);
  border: var(--border-main);
  box-shadow: var(--shadow-panel);
  border-radius: var(--radius-btn);
  overflow: hidden;
  min-width: 168px;
  display: none;
}

#dm-ctx-menu.visible {
  display: block;
}

.ctx-item {
  padding: 9px 14px;
  font-size: 13px;
  font-weight: bold;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.ctx-item:hover {
  background: rgba(128, 128, 128, .15);
}

.dm-win {
  position: fixed;
  width: 300px;
  border-radius: var(--radius-panel);
  border: var(--border-main);
  box-shadow: var(--shadow-panel);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 220px;
  min-height: 40px;
}

.dm-win.dm-hidden {
  display: none !important;
}

.dm-win.dm-active {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15), 0 20px 60px rgba(0, 0, 0, .9);
}

.dm-titlebar {
  height: 40px;
  background: var(--bg-header);
  border-bottom: var(--border-main);
  display: flex;
  align-items: center;
  padding: 0 8px 0 10px;
  gap: 8px;
  cursor: grab;
  flex-shrink: 0;
  user-select: none;
}

.dm-titlebar:active {
  cursor: grabbing;
}

.dm-tb-avatar {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  color: #fff;
  flex-shrink: 0;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, .3), 0 1px 2px rgba(0, 0, 0, .5);
  border: 1px solid rgba(0, 0, 0, .3);
}

.dm-tb-name {
  flex: 1;
  font-size: 13px;
  font-weight: bold;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-unread {
  background: #ff5555;
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  padding: 1px 5px;
  border-radius: 10px;
  display: none;
  flex-shrink: 0;
}

.dm-unread.visible {
  display: block;
}

.dm-wb {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-btn);
  background: var(--bg-btn);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  color: var(--text-main);
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

.dm-wb:hover {
  background: var(--bg-btn-hover);
}

.dm-wb:active {
  transform: translateY(1px);
}

.dm-wb.dm-close-btn:hover {
  background: #ff5555;
  color: #fff;
}

.dm-back-btn {
  display: none;
}

.dm-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.dm-win.dm-minimized .dm-body {
  display: none;
}

.dm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 260px;
}

.dm-messages::-webkit-scrollbar {
  width: 10px;
}

.dm-messages::-webkit-scrollbar-track {
  background: var(--bg-input);
}

.dm-messages::-webkit-scrollbar-thumb {
  background: var(--bg-btn);
  border-radius: var(--radius-btn);
  border: var(--border-main);
}

.dm-msg {
  display: flex;
  flex-direction: column;
  padding: 3px 0;
}

.dm-msg.dm-grouped {
  padding-top: 1px;
}

.dm-msg-header {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 3px;
}

.dm-msg.dm-grouped .dm-msg-header {
  display: none;
}

.dm-msg-user {
  font-size: 11px;
  font-weight: bold;
}

.dm-msg-time {
  font-size: 10px;
  color: var(--text-dim);
}

.dm-msg-text {
  display: inline-block;
  background: var(--bg-msg);
  border: var(--border-main);
  box-shadow: var(--shadow-msg);
  color: var(--text-main);
  font-size: 13px;
  word-break: break-word;
  line-height: 1.5;
  white-space: pre-wrap;
  padding: 6px 10px;
  border-radius: var(--radius-msg);
}

.dm-msg.dm-own .dm-msg-text {
  background: var(--bg-msg-own);
}

.dm-msg-img {
  margin-top: 3px;
  max-width: 200px;
  border-radius: var(--radius-msg);
  overflow: hidden;
  cursor: pointer;
  display: block;
  border: var(--border-main);
  box-shadow: var(--shadow-msg);
}

.dm-msg-img img {
  width: 100%;
  display: block;
}

.dm-sys {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  padding: 5px 0;
}

.dm-e2e-lock {
  font-size: 10px;
  opacity: 0.55;
  user-select: none;
  vertical-align: middle;
}

.dm-paste-row {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 0;
  border-top: var(--border-main);
}

.dm-paste-row.visible {
  display: flex;
}

.dm-paste-thumb {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: var(--radius-input);
  border: var(--border-main);
}

.dm-paste-lbl {
  flex: 1;
  font-size: 11px;
  font-weight: bold;
  color: var(--text-dim);
}

.dm-paste-x {
  background: var(--bg-btn);
  border: var(--border-main);
  color: var(--text-main);
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: var(--radius-btn);
}

.dm-paste-x:hover {
  background: #ff5555;
  color: #fff;
}

.dm-inputbar {
  padding: 7px 10px 9px;
  display: flex;
  gap: 7px;
  align-items: flex-end;
  border-top: var(--border-main);
  background: var(--bg-bottom);
}

.dm-input {
  flex: 1;
  background: var(--bg-input);
  border: var(--border-main);
  box-shadow: var(--shadow-input);
  border-radius: var(--radius-input);
  padding: 7px 9px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  resize: none;
  min-height: 32px;
  max-height: 72px;
  overflow-y: auto;
}

.dm-input::placeholder {
  color: var(--text-dim);
}

.dm-input:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.dm-sendbtn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-btn);
  background: var(--bg-btn);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}

.dm-sendbtn:hover {
  background: var(--bg-btn-hover);
}

.dm-sendbtn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.dm-sendbtn:disabled {
  filter: grayscale(1);
  opacity: .4;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.dm-sendbtn svg path {
  stroke: var(--text-btn);
}

.dm-img-btn {
  display: none;
}


/* ==========================================================================
   UI BUTTONS & SIDEBAR EXTRAS
   ========================================================================== */

#hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: var(--bg-btn);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  border-radius: var(--radius-btn);
  cursor: pointer;
  padding: 0;
}

#hamburger-btn:hover {
  background: var(--bg-btn-hover);
}

#hamburger-btn svg {
  display: block;
}

#img-attach-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: var(--bg-btn);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  border-radius: var(--radius-btn);
  cursor: pointer;
  padding: 0;
}

#img-attach-btn:hover {
  background: var(--bg-btn-hover);
}

#img-attach-btn svg {
  display: block;
}

#img-attach-input {
  display: none;
}

#sidebar-settings {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 10px;
  border-top: var(--border-main);
  flex-shrink: 0;
}

#sidebar-settings-title {
  font-size: 10px;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 2px 0 4px 2px;
  letter-spacing: 0.06em;
}

#sidebar-rain-btn {
  background: var(--bg-btn);
  color: var(--text-btn);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  border-radius: var(--radius-btn);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  text-align: left;
  width: 100%;
  display: none;
}

#sidebar-rain-btn:hover {
  background: var(--bg-btn-hover);
}

.sidebar-settings-row {
  display: none;
  gap: 6px;
  align-items: center;
}

.sidebar-settings-label {
  font-size: 11px;
  font-weight: bold;
  color: var(--text-dim);
  width: 50px;
  flex-shrink: 0;
}

.sidebar-settings-select {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-main);
  border: var(--border-main);
  box-shadow: var(--shadow-input);
  border-radius: var(--radius-input);
  padding: 7px 8px;
  font-family: inherit;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1999;
}

body.sidebar-open #sidebar-backdrop {
  display: block;
}


/* ==========================================================================
   STATUS PICKER MODAL
   ========================================================================== */

#status-picker {
  position: fixed;
  inset: 0;
  z-index: 6000;
  display: none;
  align-items: center;
  justify-content: center;
}

#status-picker.visible {
  display: flex;
}

#status-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

#status-picker-panel {
  position: relative;
  background: var(--bg-panel);
  border: var(--border-main);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
  width: 300px;
  max-width: calc(100vw - 32px);
  overflow: hidden;
}

#status-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  background: var(--bg-header);
  border-bottom: var(--border-main);
}

#status-picker-title {
  font-size: 13px;
  font-weight: bold;
  color: var(--text-main);
}

#status-picker-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  touch-action: manipulation;
}

#status-picker-close:hover {
  color: var(--text-main);
}

#status-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 14px 14px 10px;
}

.status-preset {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  border-radius: var(--radius-btn);
  cursor: pointer;
  border: var(--border-main);
  background: var(--bg-btn);
  box-shadow: var(--shadow-btn);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.status-preset:hover {
  background: var(--bg-btn-hover);
}

.status-preset:active {
  transform: scale(0.95);
}

.status-preset.active {
  background: var(--bg-input);
  box-shadow: var(--shadow-input);
  border-color: rgba(128, 128, 128, 0.5);
}

.status-preset-emoji {
  display: none;
}

.status-preset-label {
  font-size: 11px;
  font-weight: bold;
  color: var(--text-main);
  text-align: center;
}

#status-custom-row {
  padding: 0 14px 14px;
  display: flex;
  gap: 8px;
  align-items: center;
}

#status-custom-input {
  flex: 1;
  background: var(--bg-input);
  border: var(--border-main);
  box-shadow: var(--shadow-input);
  border-radius: var(--radius-input);
  padding: 8px 10px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

#status-custom-input::placeholder {
  color: var(--text-dim);
}

#status-save-btn {
  background: var(--bg-btn);
  color: var(--text-btn);
  border: var(--border-main);
  box-shadow: var(--shadow-btn);
  border-radius: var(--radius-btn);
  padding: 8px 13px;
  font-family: inherit;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

#status-save-btn:hover {
  background: var(--bg-btn-hover);
}

#status-save-btn:active {
  transform: translateY(1px);
}

#status-clear-btn {
  display: block;
  width: calc(100% - 28px);
  margin: 0 14px 14px;
  padding: 8px;
  background: none;
  border: var(--border-main);
  border-radius: var(--radius-btn);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  touch-action: manipulation;
}

#status-clear-btn:hover {
  color: #ff5555;
  border-color: #ff5555;
}


/* ==========================================================================
   TAXONOMY CARDS (in chat)
   ========================================================================== */

.taxonomy-card {
  margin: 3px 0;
  border-radius: var(--radius-msg);
  border: var(--border-main);
  background: var(--bg-panel);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  width: fit-content;
  max-width: 520px;
  min-width: 220px;
  flex-shrink: 0;
  box-sizing: border-box;
  display: flex;
  position: relative;
}

.taxonomy-card::before {
  content: '';
  display: block;
  width: 3px;
  flex-shrink: 0;
  background: var(--tc-accent, #666);
  border-radius: var(--radius-msg) 0 0 var(--radius-msg);
}

.taxonomy-card.tc-fallacy {
  --tc-accent: var(--fallacy-txt, #9e7060);
}

.taxonomy-card.tc-bias {
  --tc-accent: var(--bias-txt, #6888a8);
}

.taxonomy-card.tc-assumption {
  --tc-accent: var(--assumption-txt, #8e8050);
}

.taxonomy-card:hover {
  border-color: var(--border2);
  background: var(--bg-msg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.tc-meta {
  display: none;
}

.tc-body {
  padding: 7px 10px 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.tc-top {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  min-width: 0;
}

.tc-pill {
  font-size: 8px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 1px 5px;
  border-radius: var(--radius-btn);
  flex-shrink: 0;
  line-height: 1.6;
}

.tc-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tc-byline {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: auto;
  white-space: nowrap;
  flex-shrink: 0;
  padding-left: 6px;
  opacity: 0.7;
}

.tc-hint {
  font-size: 9px;
  color: var(--tc-accent, var(--text-dim));
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.taxonomy-card:hover .tc-hint {
  opacity: 0.8;
}

.tc-def {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.45;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.taxonomy-card:hover .tc-def {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
}

.tax-cmd-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.tax-cmd-pill {
  font-family: 'JetBrains Mono', monospace, monospace;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--bg-input, #111);
  border: var(--border-main);
  border-radius: var(--radius-btn);
  padding: 3px 8px;
  letter-spacing: 0.02em;
}

#taxonomy-panel {
  position: fixed;
  z-index: 100;
  background: var(--bg-panel);
  border: var(--border-main);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  left: -9999px;
  top: -9999px;
  transition: opacity 0.18s ease;
}

#taxonomy-panel.tax-open {
  pointer-events: all;
}

#tax-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 12px;
  border-bottom: var(--border-main);
  background: var(--bg-header);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
}

#tax-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  overflow: hidden;
}

#tax-title-text {
  font-size: 17px;
  font-weight: bold;
  color: var(--text-main);
}

#tax-count {
  font-size: 10px;
  font-weight: bold;
  color: var(--text-dim);
}

#tax-close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  line-height: 1;
  flex-shrink: 0;
}

#tax-close-btn:hover {
  color: var(--text-main);
}

#tax-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: var(--border-main);
  flex-shrink: 0;
  color: var(--text-dim);
}

#tax-search {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 12px;
  min-width: 0;
}

#tax-search::placeholder {
  color: var(--text-dim);
  opacity: 0.6;
}

#tax-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 20px;
}

#tax-list::-webkit-scrollbar {
  width: 4px;
}

#tax-list::-webkit-scrollbar-track {
  background: transparent;
}

#tax-list::-webkit-scrollbar-thumb {
  background: var(--border-main, #333);
  border-radius: 4px;
}

.tax-group-hdr {
  font-size: 9px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 14px 8px 6px;
  white-space: nowrap;
}

.tax-group-hdr:first-child {
  padding-top: 6px;
}

.tax-item {
  border-radius: var(--radius-btn);
  padding: 7px 8px;
  cursor: pointer;
  margin-bottom: 1px;
  transition: background 0.12s;
}

.tax-item:hover {
  background: rgba(128, 128, 128, 0.1);
}

.tax-item.tax-active {
  background: rgba(128, 128, 128, 0.08);
}

.tax-item-name {
  font-size: 12px;
  font-weight: bold;
  color: var(--text-main);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tax-item-def {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 4px;
  display: none;
}

.tax-item.tax-active .tax-item-def {
  display: block;
}

.tax-item.tax-active .tax-item-name {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  color: var(--text-main);
  margin-bottom: 2px;
}

.tax-empty {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  padding: 32px 12px;
  font-style: italic;
}

#tax-detail {
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  display: none;
}

.tax-detail-sticky {
  flex-shrink: 0;
  background: var(--bg-panel);
  border-bottom: var(--border-main);
  z-index: 1;
}

.tax-detail-scroll {
  flex: 1;
  overflow-y: auto;
}

.tax-detail-scroll::-webkit-scrollbar {
  width: 4px;
}

.tax-detail-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.tax-detail-scroll::-webkit-scrollbar-thumb {
  background: var(--border2, #333);
  border-radius: 4px;
}

.tax-detail-back,
.tax-back-btn {
  display: none;
}

.tax-detail-header {
  padding: 10px 12px 9px;
  border-bottom: var(--border-main);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}

.tax-detail-header--back {
  cursor: pointer;
  transition: background 0.13s;
}

.tax-detail-header--back:hover {
  background: rgba(128, 128, 128, 0.08);
}

.tax-back-arrow {
  font-size: 14px;
  color: var(--text-dim);
  opacity: 0.35;
  transition: opacity 0.15s, transform 0.15s;
  transform: translateX(0);
  flex-shrink: 0;
  line-height: 1;
}

.tax-detail-header--back:hover .tax-back-arrow {
  opacity: 1;
  transform: translateX(-2px);
}

.tax-detail-pill {
  display: inline-flex;
  align-items: center;
  font-size: 8px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: var(--radius-btn);
  flex-shrink: 0;
  line-height: 1.5;
}

.tax-pill-fallacy {
  background: var(--fallacy-bg);
  color: var(--fallacy-txt);
  border: 1px solid var(--fallacy-bdr);
}

.tax-pill-bias {
  background: var(--bias-bg);
  color: var(--bias-txt);
  border: 1px solid var(--bias-bdr);
}

.tax-pill-assumption {
  background: var(--assumption-bg);
  color: var(--assumption-txt);
  border: 1px solid var(--assumption-bdr);
}

.tax-detail-name {
  font-size: 13px;
  font-weight: bold;
  color: var(--text-main);
  line-height: 1.3;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tax-detail-meta {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  border-bottom: var(--border-main);
  flex-shrink: 0;
}

.tax-meta-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px 10px 6px;
  border-right: var(--border-main);
}

.tax-meta-item:last-child {
  border-right: none;
}

.tax-meta-sep {
  display: none;
}

.tax-meta-label {
  font-size: 8px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  opacity: 0.7;
}

.tax-meta-value {
  font-size: 11px;
  font-weight: bold;
  color: var(--text-main);
  line-height: 1.3;
}

.tax-detail-body {
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tax-section-label {
  font-size: 9px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.tax-section-text {
  font-size: 12px;
  color: var(--text-main);
  line-height: 1.6;
}

#tax-toggle-btn.tax-btn-active {
  background: var(--bg-input);
  box-shadow: var(--shadow-input);
  color: var(--text-main);
}


/* Hide mobile-only elements on desktop */
#mobile-action-sheet {
  display: none;
}

/* ==========================================================================
   MOBILE / RESPONSIVE OVERRIDES
   ========================================================================== */

@media (max-width: 640px) {
  #taxonomy-panel {
    display: none;
  }

  #tax-toggle-btn {
    display: none;
  }

  .taxonomy-card {
    max-width: 100%;
  }

  .tc-hint {
    display: none;
  }

  /* Kill glass-theme border/shadow overrides on chat container */
  body.theme-vista-grey #chat-screen-inner,
  body.theme-polycarbonate-clear #chat-screen-inner,
  body.theme-aurora #chat-screen-inner {
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  body.theme-vista-grey #sidebar,
  body.theme-polycarbonate-clear #sidebar,
  body.theme-aurora #sidebar {
    box-shadow: 6px 0 32px rgba(0, 0, 0, 0.7) !important;
  }

  body.theme-vista-grey:not(.sidebar-open) #sidebar,
  body.theme-polycarbonate-clear:not(.sidebar-open) #sidebar,
  body.theme-aurora:not(.sidebar-open) #sidebar {
    box-shadow: none !important;
  }

  /* Disable heavy blur */
  body.theme-vista-grey #chat-screen-inner,
  body.theme-vista-grey #sidebar,
  body.theme-vista-grey .dm-win,
  body.theme-polycarbonate-clear #chat-screen-inner,
  body.theme-polycarbonate-clear #sidebar,
  body.theme-polycarbonate-clear .dm-win,
  body.theme-aurora #chat-screen-inner,
  body.theme-aurora #sidebar,
  body.theme-aurora .dm-win,
  body.theme-vista-grey #messages,
  body.theme-polycarbonate-clear #messages,
  body.theme-aurora #messages {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  body.theme-vista-grey::before,
  body.theme-polycarbonate-clear::before,
  body.theme-aurora::before,
  body.theme-aurora::after {
    display: none !important;
  }

  html {
    zoom: 1;
  }

  html,
  body {
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  #chat-screen {
    padding: 0 !important;
    height: 100dvh;
  }

  #chat-screen-inner {
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    height: 100%;
    max-width: 100% !important;
    margin: 0 !important;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 82vw);
    z-index: 2000;
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: var(--border-main);
    padding-left: env(safe-area-inset-left, 0px);
  }

  body.sidebar-open #sidebar {
    transform: translateX(0);
    box-shadow: 6px 0 32px rgba(0, 0, 0, 0.7);
  }

  #sidebar-settings,
  #sidebar-rain-btn,
  .sidebar-settings-row {
    display: flex;
  }

  .km-btn-row,
  #topbar-controls,
  #size-toggle,
  #topbar-count,
  #char-counter,
  #rec-hint {
    display: none;
  }

  #sidebar-header {
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
  }

  #main {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  #topbar {
    padding: 0 10px;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: calc(10px + env(safe-area-inset-left, 0px));
    padding-right: calc(10px + env(safe-area-inset-right, 0px));
    gap: 8px;
    min-height: 48px;
    height: auto;
    flex-shrink: 0;
  }

  #hamburger-btn {
    display: flex;
    width: 36px;
    height: 36px;
  }

  #messages,
  .dm-messages {
    flex: 1;
    min-height: 0;
    padding: 10px 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  #messages::-webkit-scrollbar,
  .dm-messages::-webkit-scrollbar,
  #msg-input::-webkit-scrollbar,
  .dm-input::-webkit-scrollbar,
  #user-list-wrap::-webkit-scrollbar {
    display: none;
  }

  #bottom-chrome {
    flex-shrink: 0;
    padding-bottom: max(6px, env(safe-area-inset-bottom, 6px));
    box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.05);
  }

  #status-row {
    padding: 5px 12px 0;
    min-height: 22px;
  }

  #paste-preview {
    padding: 8px 12px 0;
  }

  #input-bar {
    padding: 6px 8px 4px;
    padding-left: calc(8px + env(safe-area-inset-left, 0px));
    padding-right: calc(8px + env(safe-area-inset-right, 0px));
    gap: 6px;
    align-items: flex-end;
  }

  #img-attach-btn {
    display: flex;
    width: 38px;
    height: 38px;
  }

  #msg-input {
    font-size: 16px;
    min-height: 38px;
    padding: 9px 10px;
    min-width: 0;
    flex: 1 1 0%;
  }

  #send-btn,
  #mic-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
  }

  #input-right {
    gap: 6px;
    flex-shrink: 0;
  }

  .msg-audio {
    width: min(280px, 72vw);
  }

  .msg-image {
    max-width: min(260px, 72vw);
  }

  .msg-text {
    font-size: 15px;
  }

  #join-screen {
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #join-card {
    width: 100%;
    max-width: 400px;
    padding: 20px 16px;
  }

  #join-controls {
    flex-direction: column;
    gap: 8px;
  }

  #join-controls .join-ctrl-group {
    width: 100%;
  }

  #color-swatches {
    gap: 8px;
  }

  .color-swatch {
    width: 28px;
    height: 28px;
  }

  #username-input,
  #join-btn {
    font-size: 16px;
  }

  #join-btn {
    padding: 14px;
    min-height: 48px;
  }

  .user-item {
    padding: 10px 8px;
    min-height: 44px;
  }

  .admin-action-btn {
    min-height: 36px;
    padding: 6px 10px;
  }

  #admin-panel {
    display: flex;
    padding: 8px 10px;
  }

  /* Mobile DM overrides */
  .dm-win {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
    z-index: 3000 !important;
    min-width: unset !important;
    min-height: unset !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .dm-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .dm-messages {
    height: auto !important;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  .dm-titlebar {
    cursor: default !important;
    height: calc(52px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: calc(10px + env(safe-area-inset-left, 0px));
    padding-right: 10px;
    padding-bottom: 0;
    flex-shrink: 0;
  }

  .dm-inputbar {
    padding: 7px 10px;
    padding-bottom: calc(9px + env(safe-area-inset-bottom, 0px));
    padding-right: calc(10px + env(safe-area-inset-right, 0px));
    flex-shrink: 0;
  }

  .dm-input {
    font-size: 16px;
    min-height: 44px;
  }

  .dm-sendbtn {
    width: 44px;
    height: 44px;
  }

  .dm-img-btn {
    display: flex;
  }

  .dm-wb {
    width: 32px;
    height: 32px;
  }

  .dm-back-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 44px;
    margin-left: -6px;
    margin-right: 2px;
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 22px;
    font-weight: bold;
    cursor: pointer;
    padding: 0 8px;
    border-radius: var(--radius-btn);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
  }

  .dm-back-btn:active {
    background: rgba(128, 128, 128, 0.18);
    transform: scale(0.93);
  }

  .dm-min-btn,
  .dm-close-btn,
  #dm-ctx-menu {
    display: none !important;
  }

  #lightbox {
    padding: 60px 16px 24px;
    cursor: default;
  }

  #lightbox img {
    max-width: 96vw;
    max-height: 75vh;
  }

  #lightbox-close {
    display: flex;
  }

  #mobile-action-sheet {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: none;
    flex-direction: column;
    justify-content: flex-end;
  }

  #mobile-action-sheet.visible {
    display: flex;
  }

  #mobile-action-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
  }

  #mobile-action-sheet-panel {
    position: relative;
    background: var(--bg-panel);
    border-top: var(--border-main);
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
    padding: 0 0 calc(12px + env(safe-area-inset-bottom, 0px)) 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
    overflow: hidden;
  }

  #mobile-action-sheet-title {
    font-size: 12px;
    font-weight: bold;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 14px 20px 10px;
    border-bottom: var(--border-main);
  }

  .mobile-action-btn {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 16px 20px;
    background: none;
    border: none;
    border-bottom: var(--border-main);
    color: var(--text-main);
    font-family: inherit;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    text-align: left;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-action-btn:last-child {
    border-bottom: none;
  }

  .mobile-action-btn:active {
    background: rgba(128, 128, 128, 0.15);
  }

  .mobile-action-btn-icon {
    display: none;
  }

  .mobile-action-btn.cancel-btn {
    color: var(--text-dim);
  }

  #kicked-screen {
    padding: 24px 16px;
    padding-top: calc(24px + env(safe-area-inset-top, 0px));
  }

  #my-status-row {
    min-height: 36px;
    align-items: center;
  }

  * {
    -webkit-tap-highlight-color: transparent;
  }

  #topbar,
  #bottom-chrome,
  .dm-titlebar,
  #sidebar-header,
  .user-item,
  #user-list-label {
    user-select: none;
    -webkit-user-select: none;
  }

  button:active {
    opacity: 0.72;
    transform: scale(0.97);
  }

  #send-btn:active,
  #join-btn:active {
    transform: scale(0.95) translateY(1px);
    opacity: 1;
  }

  .user-item:active {
    background: rgba(128, 128, 128, 0.18) !important;
  }

  #dm-tray-btn {
    display: none;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    flex-shrink: 0;
    background: var(--bg-btn);
    border: var(--border-main);
    box-shadow: var(--shadow-btn);
    border-radius: var(--radius-btn);
    color: var(--text-btn);
    font-family: inherit;
    font-size: 12px;
    font-weight: bold;
    padding: 6px 10px;
    cursor: pointer;
    touch-action: manipulation;
    white-space: nowrap;
  }

  #dm-tray-btn.has-unread {
    background: #ff5555;
    border-color: #cc3333;
    color: #fff;
  }

  #dm-tray-btn:active {
    opacity: 0.75;
    transform: scale(0.96);
  }

  .dm-bubble {
    position: fixed;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    cursor: pointer;
    z-index: 4000;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
    border: 2.5px solid rgba(255, 255, 255, 0.18);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.12s, box-shadow 0.12s;
    will-change: transform;
  }

  .dm-bubble:active {
    transform: scale(0.92);
  }

  .dm-bubble-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ff3b30;
    color: #fff;
    font-size: 10px;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--bg-panel, #222);
    pointer-events: none;
  }

  .dm-bubble-badge.hidden {
    display: none;
  }
}