*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #333;
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #6c5ce7;
  --accent-hover: #7c6cf7;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --success: #2ecc71;
  --warning: #f39c12;
  --radius: 8px;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface2: #e8e8e8;
  --border: #d0d0d0;
  --text: #1a1a1a;
  --text-dim: #666;
  --accent: #6c5ce7;
  --accent-hover: #7c6cf7;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --success: #2ecc71;
  --warning: #f39c12;
}

[data-theme="light"] ::-webkit-scrollbar-track { background: #f0f0f0; }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: #ccc; }
[data-theme="light"] #user-context-menu { box-shadow: 0 4px 12px rgba(0,0,0,0.15); }

body {
  font-family: system-ui, sans-serif;
  font-size: 18px;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

/* --- Join Screen --- */
#join-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  padding: 20px;
}

.join-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}

.join-box h1 {
  font-size: 1.5rem;
  margin-bottom: 4px;
  text-align: center;
}

.join-box .subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 24px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.field input:focus {
  border-color: var(--accent);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-dim);
}

.checkbox-row input { cursor: pointer; }

#password-field { display: none; }

#join-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 12px;
  min-height: 1.2em;
}

/* Color swatches */
.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--text); transform: scale(1.15); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--accent-hover); }

.disclaimer {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 1rem;
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.75rem;
  border-radius: 4px;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover { background: var(--danger-hover); }

/* --- Chat Screen --- */
#chat-screen {
  display: none;
  height: 100dvh;
  flex-direction: column;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header h2 { font-size: 1.1rem; }

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.header-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
}

.header-btn:hover { background: var(--border); }

#user-count { white-space: nowrap; }

#slow-mode-badge {
  display: none;
  background: var(--warning);
  color: #000;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

#mod-toggle-btn {
  display: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
}

/* Main layout */
.chat-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Messages area */
.messages-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Reconnect banner */
#reconnect-banner {
  display: none;
  background: var(--warning);
  color: #000;
  text-align: center;
  padding: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
}

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
#reconnect-banner.active { display: block; animation: pulse 1.5s infinite; }

/* Messages */
.msg {
  padding: 4px 0;
  font-size: 1.05rem;
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
}

.msg .time {
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-right: 6px;
}

body.ts-hidden .msg .time { display: none; }

.msg .nick {
  font-weight: 600;
  cursor: default;
  margin-right: 4px;
}

.msg .nick.mod-nick { cursor: pointer; }

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

.msg.roll { font-style: italic; opacity: 0.85; }
.msg.roll .nick { font-style: italic; }

.msg .text code {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.9em;
}

.msg .text pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  overflow-x: auto;
  margin: 4px 0;
  display: inline-block;
  max-width: 100%;
}

.msg .text pre > code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85em;
}

.msg .text .blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 8px;
  color: var(--text-dim);
  margin: 2px 0;
}

.msg .text s { opacity: 0.7; }

.msg .text a {
  color: var(--accent);
  text-decoration: underline;
}

.msg .text a:hover { opacity: 0.8; }

.spoiler {
  background: var(--text);
  color: transparent;
  border-radius: 3px;
  cursor: pointer;
  padding: 0 2px;
  transition: background 0.2s, color 0.2s;
}
.spoiler.revealed {
  background: var(--surface2);
  color: var(--text);
}

.action-bar .delete-btn {
  font-size: 0.85rem;
}
.action-bar .report-btn {
  color: var(--warning);
  font-size: 0.85rem;
}
.action-bar .edit-btn {
  font-size: 0.85rem;
}

/* Mentions */
.mention { color: var(--accent); font-weight: 600; }
.mention-me { background: rgba(108, 92, 231, 0.2); border-radius: 3px; padding: 0 2px; }

/* Edited tag */
.edited-tag { font-size: 0.7rem; color: var(--text-dim); margin-left: 4px; }

/* Edit input */
.msg .edit-input {
  background: var(--surface2);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 4px;
  padding: 2px 6px;
  font: inherit;
  width: 100%;
}

/* Report dialog */
.report-dialog-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.report-dialog-overlay.active { display: flex; }

.report-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  margin: 20px;
}

.report-dialog h3 { margin-bottom: 4px; font-size: 1.1rem; }
.report-dialog .report-msg-preview {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-dialog textarea {
  width: 100%;
  padding: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.9rem;
  resize: vertical;
  min-height: 60px;
  max-height: 120px;
  margin-bottom: 12px;
  outline: none;
}

.report-dialog textarea:focus { border-color: var(--accent); }

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

/* Report badge on mod toggle */
.report-badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  margin-left: 6px;
  display: none;
}

.report-badge.active { display: inline; }

/* Report items in mod panel */
.report-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
  font-size: 0.8rem;
}

.report-item .report-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  color: var(--text-dim);
  font-size: 0.75rem;
}

.report-item .report-message-text {
  margin-bottom: 4px;
  word-wrap: break-word;
}

.report-item .report-reason {
  color: var(--text-dim);
  font-style: italic;
  margin-bottom: 6px;
}

.report-item .report-item-actions {
  display: flex;
  gap: 6px;
}

.report-item .report-status {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.report-item .report-status.resolved { color: var(--success); }
.report-item .report-status.dismissed { color: var(--text-dim); }

#report-list {
  max-height: 300px;
  overflow-y: auto;
}

/* Reply quote */
.reply-quote {
  padding: 4px 8px;
  margin-bottom: 2px;
  border-left: 3px solid var(--accent);
  background: var(--surface2);
  border-radius: 0 4px 4px 0;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-quote:hover { background: var(--border); }

/* Action bar (on hover) */
.action-bar {
  display: none;
  position: absolute;
  top: -28px;
  right: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2px 4px;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  align-items: center;
}
.action-bar::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 30px;
}

.msg.selected { background: var(--surface2); border-radius: var(--radius); }
.msg:hover .action-bar,
.msg.selected .action-bar { display: flex; }

.action-bar > button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  font-size: 1rem;
  padding: 3px 6px;
  border-radius: 4px;
  line-height: 1;
  opacity: 0.8;
}
.action-bar > button:active { opacity: 1; }
.action-bar > button:hover { background: var(--surface2); opacity: 1; }

.react-btn-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.react-btn-wrap > button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
.react-btn-wrap > button:hover { background: var(--surface2); }

.emoji-picker {
  display: none;
  align-items: center;
}
.action-bar.picking > button,
.action-bar.picking > .react-btn-wrap { display: none; }
.action-bar.picking > .emoji-picker { display: flex; }
.emoji-picker button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
.emoji-picker button:hover { background: var(--surface2); }

/* Reaction pills */
.reactions-container {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 0.75rem;
  cursor: pointer;
}

.reaction-pill:hover { background: var(--border); }
.reaction-pill.mine { border-color: var(--accent); }

/* Message highlight on reply scroll */
.msg.highlight { background: var(--surface2); transition: background 0.3s; }

.system-msg {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-style: italic;
  padding: 2px 0;
}

#muted-notice {
  display: none;
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: 6px;
  font-size: 0.85rem;
}

/* Now Playing (inline in header) */
#now-playing {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-dim);
  margin-left: 10px;
}

#now-playing:not(:empty)::before {
  content: '— ';
}

/* Reply preview */
.reply-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.reply-preview .reply-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}

.reply-preview .reply-cancel {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 4px;
}

/* Input area */
.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  resize: none;
  overflow-y: hidden;
  min-height: 38px;
  max-height: 120px;
  font-family: inherit;
  line-height: 1.4;
}

#message-input:focus { border-color: var(--accent); }

#send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 1rem;
  cursor: pointer;
}

#send-btn:hover { background: var(--accent-hover); }

/* --- Mod Panel (sidebar) --- */
#mod-panel {
  display: none;
  width: 280px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 16px;
}

#mod-panel h3 {
  font-size: 0.95rem;
  margin-bottom: 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mod-section {
  margin-bottom: 20px;
}

.mod-section h4 {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.mod-section .inline-form {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.mod-section .inline-form input {
  flex: 1;
  padding: 6px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 0.8rem;
}

.tag .remove {
  cursor: pointer;
  color: var(--danger);
  font-weight: bold;
}

/* Audit log */
#audit-log {
  max-height: 200px;
  overflow-y: auto;
}

.audit-entry {
  padding: 4px 0;
  font-size: 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
}

.audit-entry .audit-time { margin-right: 6px; }
.audit-entry .audit-action { font-weight: 600; color: var(--accent); margin-right: 4px; }

/* Deleted messages log */
#deleted-messages-log {
  max-height: 250px;
  overflow-y: auto;
}

.deleted-entry {
  padding: 6px 0;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
}

.deleted-entry .deleted-meta {
  color: var(--text-dim);
  font-size: 0.7rem;
  margin-bottom: 2px;
}

.deleted-entry .deleted-text {
  word-wrap: break-word;
}

/* User context menu */
#user-context-menu {
  display: none;
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 0;
  z-index: 1000;
  min-width: 120px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

#user-context-menu > button {
  display: block;
  width: 100%;
  padding: 8px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

#user-context-menu > button:hover {
  background: var(--surface2);
}

.mute-submenu {
  display: none;
  padding: 4px 8px 8px;
}

.mute-submenu button {
  display: inline-block;
  padding: 4px 8px;
  font-size: 0.75rem;
  margin: 2px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
}

.mute-submenu button:hover { background: var(--border); }

/* User mute menu (client-side) */
#user-mute-menu {
  display: none;
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 0;
  z-index: 1000;
  min-width: 120px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

#user-mute-menu > button {
  display: block;
  width: 100%;
  padding: 8px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

#user-mute-menu > button:hover {
  background: var(--surface2);
}

.user-item.client-muted { opacity: 0.4; }
.user-item.client-muted::after { content: ' 🔇'; font-size: 0.7rem; }

/* Banned screen */
#banned-screen {
  display: none;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  text-align: center;
  padding: 20px;
}

#banned-screen h1 {
  color: var(--danger);
  margin-bottom: 8px;
}

#banned-screen p {
  color: var(--text-dim);
}

/* Users sidebar */
.users-sidebar {
  width: 180px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 12px;
}

.users-sidebar h4 {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.user-item {
  padding: 4px 0;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.user-item.muted { color: var(--text-dim); text-decoration: line-through; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Custom emotes (inline images in chat) */
.custom-emote {
  height: 1.5em;
  vertical-align: middle;
  display: inline;
  margin: 0 1px;
}

/* Emoji/Emote Picker */
.chat-input-area { position: relative; }

#emote-picker-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.2rem;
  padding: 6px 10px;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}

#emote-picker-btn:hover { background: var(--border); }

#emote-picker-panel {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 340px;
  max-height: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 4px;
  flex-direction: column;
  z-index: 50;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
}

#emote-picker-panel.open { display: flex; }

.emote-picker-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 4px 4px 0;
  gap: 0;
  flex-shrink: 0;
  justify-content: space-around;
}

.emote-picker-tab {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  padding: 4px 6px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  line-height: 1;
}

.emote-picker-tab:hover { color: var(--text); }
.emote-picker-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.emote-picker-search {
  margin: 6px;
  padding: 6px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  flex-shrink: 0;
}

.emote-picker-search:focus { border-color: var(--accent); }

.emote-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 4px 6px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.emote-picker-item {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.emote-picker-item:hover { background: var(--surface2); }
.emote-picker-item img { height: 1.5em; width: 1.5em; object-fit: contain; }

/* Mod panel emote file input */
#emote-file-input {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  width: 100%;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .users-sidebar { display: none; }
  #mod-panel { width: 100%; position: absolute; top: 0; left: 0; height: 100%; z-index: 100; }
  .join-box { padding: 24px 20px; }
}
