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

html, body {
  background: transparent;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

#chat-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 100dvh;
  padding: 12px;
  padding-bottom: 20px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
}

#chat-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  pointer-events: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--theme-scrollbar, rgba(255,255,255,0.2)) transparent;
}

#chat-list::-webkit-scrollbar {
  width: 4px;
}

#chat-list::-webkit-scrollbar-track {
  background: transparent;
}

#chat-list::-webkit-scrollbar-thumb {
  background: var(--theme-scrollbar, rgba(255,255,255,0.2));
  border-radius: 2px;
}

.chat-message {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  font-size: 20px;
  line-height: 1.4;
  text-shadow: var(--theme-text-shadow, 1px 1px 3px rgba(0,0,0,0.9), 0 0 6px rgba(0,0,0,0.6));
  animation: slide-in 0.2s ease-out;
  word-break: break-word;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Platform logo icon */
.platform-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-shadow: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.7));
}

.platform-logo svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Kick badge icons */
.kick-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  text-shadow: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.7));
}

.kick-badge svg {
  width: 100%;
  height: 100%;
  display: block;
}

.chat-emote {
  height: 1.4em;
  width: auto;
  vertical-align: middle;
  display: inline-block;
}

.username {
  font-weight: 700;
  flex-shrink: 0;
}

.username::after {
  content: ':';
  color: var(--theme-text-secondary, #ccc);
}

.text {
  color: var(--theme-text-primary, #fff);
}

/* Preview mode: dark background so iframe in setup page looks correct */
body.preview-mode {
  background: #0d0d14;
}

/* Status bar: visible in browser tabs, hidden in OBS (transparent bg) */
#status-bar {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  pointer-events: none;
}

body.preview-mode #status-bar,
body.tab-mode #status-bar {
  display: flex;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--theme-status-bg, rgba(0,0,0,0.7));
  border: 1px solid var(--theme-status-border, rgba(255,255,255,0.12));
  color: var(--theme-text-secondary, #ccc);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 20px;
  backdrop-filter: blur(4px);
}

.status-chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-chip.connecting .dot { background: #888; animation: blink-dot 1.4s infinite; }
.status-chip.connected  .dot { background: #22c55e; }
.status-chip.error      .dot { background: #ef4444; }

@keyframes blink-dot {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

/* Scroll-to-bottom button */
#scroll-to-bottom {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  background: var(--theme-status-bg, rgba(0,0,0,0.75));
  border: 1px solid var(--theme-status-border, rgba(255,255,255,0.2));
  color: var(--theme-text-primary, #fff);
  border-radius: 20px;
  padding: 6px 14px 6px 10px;
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  cursor: pointer;
  backdrop-filter: blur(6px);
  z-index: 200;
}

#scroll-to-bottom svg {
  width: 20px;
  height: 20px;
}

#scroll-to-bottom.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* Hint shown when no URL params are set */
#hint {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--theme-card-bg, rgba(0,0,0,0.8));
  color: var(--theme-text-primary, #fff);
  padding: 20px 28px;
  border-radius: 10px;
  font-size: 16px;
  text-align: center;
  line-height: 1.6;
  pointer-events: auto;
}

#hint a {
  color: #9146FF;
}

/* === Moderation UI === */

/* Tappable messages glow on press */
.chat-message.mod-enabled {
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(255,255,255,0.08);
}

.chat-message.mod-enabled:active {
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
}

/* Deleted message fade */
.chat-message.mod-deleted {
  opacity: 0.3;
  text-decoration: line-through;
  pointer-events: none;
}

/* Popup container */
.mod-popup {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: auto;
}

/* Backdrop */
.mod-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  transition: background 0.25s ease;
}

.mod-popup-open .mod-backdrop {
  background: rgba(0, 0, 0, 0.5);
}

/* Bottom sheet */
.mod-sheet {
  position: relative;
  background: rgba(18, 18, 24, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px 16px 0 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom, 8px) + 12px);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.5);
  max-width: 100%;
}

.mod-popup-open .mod-sheet {
  transform: translateY(0);
}

/* Closing animation */
.mod-popup-closing .mod-backdrop {
  background: rgba(0, 0, 0, 0);
}

.mod-popup-closing .mod-sheet {
  transform: translateY(100%);
}

@keyframes mod-popup-close {
  to { opacity: 0; }
}

.mod-popup-closing {
  animation: mod-popup-close 0.25s ease forwards;
}

/* Handle indicator */
.mod-sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  margin: 0 auto 12px;
}

/* Header with username */
.mod-sheet-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 10px;
}

.mod-sheet-username {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

/* Action buttons */
.mod-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.mod-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  font-family: 'Segoe UI', system-ui, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, transform 0.1s ease;
  text-shadow: none;
}

.mod-btn:active {
  transform: scale(0.97);
}

.mod-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.mod-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* Delete — red */
.mod-btn-delete {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}
.mod-btn-delete:active {
  background: rgba(239, 68, 68, 0.25);
}

/* Timeout 5min — yellow/orange */
.mod-btn-timeout5 {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
}
.mod-btn-timeout5:active {
  background: rgba(251, 191, 36, 0.25);
}

/* Timeout 30min — orange */
.mod-btn-timeout30 {
  background: rgba(249, 115, 22, 0.15);
  color: #fb923c;
}
.mod-btn-timeout30:active {
  background: rgba(249, 115, 22, 0.25);
}

/* Ban — red */
.mod-btn-ban {
  background: rgba(220, 38, 38, 0.15);
  color: #ef4444;
}
.mod-btn-ban:active {
  background: rgba(220, 38, 38, 0.25);
}
.mod-btn-ban.mod-btn-confirmed {
  background: rgba(220, 38, 38, 0.3);
  color: #fca5a5;
}

/* Cancel — neutral */
.mod-btn-cancel {
  background: rgba(255, 255, 255, 0.08);
  color: #aaa;
  justify-content: center;
}
.mod-btn-cancel:active {
  background: rgba(255, 255, 255, 0.15);
}

/* Success state */
.mod-btn-success {
  background: rgba(34, 197, 94, 0.2) !important;
  color: #4ade80 !important;
}

/* Error state */
.mod-btn-error {
  background: rgba(239, 68, 68, 0.2) !important;
  color: #f87171 !important;
}

/* Loading spinner */
.mod-btn-loading {
  opacity: 0.6;
  pointer-events: none;
}

.mod-btn-loading::after {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: mod-spin 0.6s linear infinite;
  margin-left: auto;
}

@keyframes mod-spin {
  to { transform: rotate(360deg); }
}

/* Unban — green */
.mod-btn-unban {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}
.mod-btn-unban:active {
  background: rgba(34, 197, 94, 0.25);
}

/* Moderated user status badge in popup header */
.mod-sheet-status {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: auto;
}

.mod-sheet-status-ban {
  background: rgba(220, 38, 38, 0.2);
  color: #f87171;
}

.mod-sheet-status-timeout {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
}

/* Moderated message visual indicator */
.chat-message[data-moderated] {
  opacity: 0.45;
}

.chat-message[data-moderated]::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 2px;
}

.chat-message[data-moderated="ban"]::before {
  background: #ef4444;
}

.chat-message[data-moderated="timeout"]::before {
  background: #fbbf24;
}

.chat-message[data-moderated] {
  position: relative;
  padding-left: 8px;
}

/* === Chat Input Bar === */

#chat-input-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: rgba(12, 12, 18, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 8px 12px calc(env(safe-area-inset-bottom, 8px) + 8px);
  pointer-events: auto;
}

.chat-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

#chat-input {
  flex: 1;
  min-height: 48px;
  padding: 12px 14px;
  padding-right: 60px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: #fff;
  font-size: 16px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

#chat-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

#chat-input:focus {
  border-color: rgba(83, 252, 24, 0.5);
  background: rgba(255, 255, 255, 0.1);
}

.chat-input-counter {
  position: absolute;
  right: 56px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.3);
  font-family: 'Segoe UI', system-ui, sans-serif;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.chat-input-counter.visible {
  opacity: 1;
}

#chat-send-btn {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 12px;
  background: #53FC18;
  color: #0a0a0a;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

#chat-send-btn svg {
  width: 22px;
  height: 22px;
}

#chat-send-btn:active {
  transform: scale(0.93);
}

#chat-send-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

#chat-send-btn.sending {
  background: rgba(83, 252, 24, 0.4);
}

.chat-input-status {
  font-size: 12px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  padding: 0 4px;
  height: 0;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, height 0.2s ease;
  color: rgba(255, 255, 255, 0.5);
}

.chat-input-status.visible {
  height: 18px;
  opacity: 1;
  padding-top: 4px;
}

.chat-input-status.success {
  color: #4ade80;
}

.chat-input-status.error {
  color: #f87171;
}

/* Push scroll-to-bottom button up when input bar is present */
#chat-input-bar ~ #scroll-to-bottom,
body:has(#chat-input-bar) #scroll-to-bottom {
  bottom: 80px;
}
