:root {
  --bubble-bg:          rgba(18, 18, 18, 0.92);
  --bubble-bg-hover:    rgba(30, 30, 30, 0.95);
  --bubble-highlight:   rgba(55, 55, 55, 0.55);
  --bubble-system:      rgba(28, 28, 28, 0.70);
  --bubble-donation:    rgba(40, 35, 28, 0.55);
  --bubble-subscriber:  rgba(25, 25, 25, 0.65);
  --bubble-border:      rgba(255, 255, 255, 0.06);
  --bubble-border-hover:rgba(255, 255, 255, 0.12);

  --color-text-primary:    #e8e8e8;
  --color-text-secondary:  rgba(190, 190, 190, 0.75);
  --color-text-muted:      rgba(140, 140, 140, 0.55);
  --color-nick-default:    #c8c8c8;

  --color-accent:        #a0a0a0;
  --color-accent-pink:   #d4a054;
  --color-accent-blue:   #8a8a8a;
  --color-mention:       #b0b0b0;
  --color-cheer:         #d4a054;

  --shadow-bubble:       0 2px 12px rgba(0, 0, 0, 0.30),
                         0 1px 4px rgba(0, 0, 0, 0.18);
  --shadow-bubble-hover: 0 4px 20px rgba(0, 0, 0, 0.35),
                         0 2px 6px rgba(0, 0, 0, 0.20);

  --font-main:  'Segoe UI', 'Inter', -apple-system, 'Helvetica Neue', Arial, sans-serif;

  --chat-gap:        10px;
  --avatar-size:     56px;
  --bubble-radius:   20px;
  --tail-width:      12px;
  --tail-height:     16px;

  --anim-duration-in:  0.35s;
  --anim-duration-out: 3s;
  --anim-easing:       cubic-bezier(0.22, 1, 0.36, 1);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: transparent !important;
  font-family: var(--font-main);
  color: var(--color-text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#chat-container {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  gap: var(--chat-gap);
  width: 100%;
  height: 100vh;
  padding: 24px 28px;
  overflow: hidden;
  pointer-events: none;
}

.chat-message {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  max-width: 60%;
  pointer-events: auto;
  cursor: default;

  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 1.5s ease,
              transform 1.5s ease,
              filter 1.5s ease;
}

.chat-message.appearing {
  animation: messageIn var(--anim-duration-in) var(--anim-easing) forwards;
}

.msg-avatar {
  flex-shrink: 0;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 50%;
  overflow: hidden;
  background: rgba(35, 35, 35, 0.50);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
  transition: box-shadow 0.3s ease;
  align-self: flex-end;
}

.chat-message:hover .msg-avatar {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15);
}

.msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.msg-avatar .avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text-primary);
  background: linear-gradient(135deg, #2a2a2a, #404040);
}

.msg-body {
  position: relative;
  background: var(--bubble-bg);
  border: 1px solid var(--bubble-border);
  border-radius: var(--bubble-radius) var(--bubble-radius) var(--bubble-radius) 6px;
  padding: 11px 18px 12px 18px;
  max-width: 100%;
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  box-shadow: var(--shadow-bubble);
  transition: background 0.25s ease,
              box-shadow 0.25s ease,
              border-color 0.25s ease;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
}

.msg-body::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: calc(-1 * var(--tail-width));
  width: var(--tail-width);
  height: var(--tail-height);
  background: var(--bubble-bg);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  transition: background 0.25s ease;
}

.chat-message:hover .msg-body::before {
  background: var(--bubble-bg-hover);
}

.chat-message:hover .msg-body {
  background: var(--bubble-bg-hover);
  border-color: var(--bubble-border-hover);
  box-shadow: var(--shadow-bubble-hover);
}

.chat-message.highlight .msg-body {
  background: var(--bubble-highlight);
  border-color: rgba(255, 255, 255, 0.10);
}

.chat-message.highlight .msg-body::before {
  background: var(--bubble-highlight);
}

.chat-message.subscriber .msg-body {
  background: var(--bubble-subscriber);
  border-color: rgba(255, 255, 255, 0.08);
}

.chat-message.subscriber .msg-body::before {
  background: var(--bubble-subscriber);
}

.chat-message.first-time .msg-body {
  border-left: 4px solid var(--color-accent-pink);
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}

.chat-message.donation .msg-body {
  background: var(--bubble-donation);
  border-color: rgba(212, 160, 84, 0.20);
  box-shadow: var(--shadow-bubble),
              0 0 24px rgba(212, 160, 84, 0.08);
}

.chat-message.donation .msg-body::before {
  background: var(--bubble-donation);
}

.chat-message.donation .msg-body::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg,
    var(--color-accent-pink),
    var(--color-accent),
    var(--color-accent-blue));
  border-radius: var(--bubble-radius) var(--bubble-radius) 0 0;
}

.chat-message.system .msg-body {
  background: var(--bubble-system);
  border-color: rgba(255, 255, 255, 0.08);
  border-radius: 14px;
}

.chat-message.system .msg-body::before {
  display: none;
}

.chat-message.system .msg-text {
  font-size: 18px;
  color: var(--color-text-secondary);
  font-style: italic;
}

.chat-message.fade-dim {
  opacity: 0.35;
  transform: translateY(-6px) scale(0.98);
  filter: blur(0.5px);
}

.chat-message.fading {
  opacity: 0 !important;
  transform: translateY(-24px) scale(0.94) !important;
  filter: blur(3px) !important;
  transition: opacity 3s ease, transform 3s ease, filter 3s ease !important;
}

@keyframes messageIn {
  0% {
    opacity: 0;
    transform: translateY(24px) scale(0.96);
  }
  60% {
    opacity: 1;
    transform: translateY(-3px) scale(1.005);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 3px;
  flex-wrap: wrap;
}

.msg-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.msg-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}

.msg-badge img {
  height: 22px;
  width: 22px;
  display: block;
  object-fit: contain;
  image-rendering: auto;
}

.msg-badge.badge-pending {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  min-width: 22px;
  min-height: 22px;
}

.msg-badge .badge-text-fallback {
  display: none;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
}

.msg-badge.badge-pending .badge-text-fallback {
  display: block;
}

.msg-badge:not(.badge-pending) .badge-text-fallback {
  display: none;
}

.msg-nickname {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.msg-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 9px 2px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  line-height: 1.4;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.50);
  background: linear-gradient(
    90deg,
    var(--c1, #ff5ea8) 0%,
    var(--c2, #ffd86b) 25%,
    var(--c3, #7af7ff) 50%,
    var(--c2, #ffd86b) 75%,
    var(--c1, #ff5ea8) 100%
  );
  background-size: 300% 100%;
  box-shadow:
    0 1px 5px rgba(0, 0, 0, 0.30),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  animation: msgTagShimmer var(--tag-speed, 3s) linear infinite;
  vertical-align: middle;
  white-space: nowrap;
  user-select: none;
}

@keyframes msgTagShimmer {
  0%   { background-position:   0% 50%; }
  100% { background-position: 300% 50%; }
}

.msg-text {
  font-size: 22px;
  line-height: 1.50;
  color: var(--color-text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  min-height: 1.5em;
}

.msg-text .emote {
  display: inline-block;
  vertical-align: middle;
  height: 32px;
  width: auto;
  margin: -5px 3px;
  image-rendering: auto;
}

.msg-text .emote.emote-large {
  height: 48px;
  width: auto;
  margin: -7px 3px;
}

.msg-text .mention {
  color: var(--color-mention);
  font-weight: 600;
  cursor: pointer;
}

.msg-text .cheer {
  color: var(--color-cheer);
  font-weight: 700;
}

.typewriter-char {
  display: inline;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.typewriter-char.visible {
  opacity: 1;
}

.typewriter-char img.emote {
  display: inline-block;
  vertical-align: middle;
  height: 32px;
  width: auto;
}

#status-indicator {
  position: fixed;
  bottom: 16px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 16px;
  background: rgba(14, 14, 14, 0.80);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-muted);
  transition: opacity 0.4s ease, color 0.3s ease, border-color 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

#status-indicator.status-connected {
  color: #34d058;
  border-color: rgba(52, 208, 88, 0.25);
}

#status-indicator.status-error {
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.25);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-muted);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.status-connected .status-dot {
  background: #34d058;
  box-shadow: 0 0 8px rgba(52, 208, 88, 0.50);
  animation: pulse-dot 2s infinite;
}

.status-error .status-dot {
  background: #ff6b6b;
  box-shadow: 0 0 8px rgba(255, 107, 107, 0.50);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#chat-container::-webkit-scrollbar {
  width: 4px;
}
#chat-container::-webkit-scrollbar-track {
  background: transparent;
}
#chat-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
}

@media (max-width: 400px) {
  :root {
    --avatar-size: 44px;
    --bubble-radius: 16px;
    --tail-width: 10px;
    --tail-height: 14px;
  }
  .msg-text { font-size: 18px; }
  .msg-nickname { font-size: 16px; }
  .msg-body { padding: 9px 14px 10px 14px; }
  .chat-message { max-width: 85%; }
}

@media (min-width: 1200px) {
  :root {
    --chat-gap: 12px;
    --avatar-size: 60px;
    --bubble-radius: 22px;
    --tail-width: 14px;
    --tail-height: 18px;
  }
  .msg-text { font-size: 24px; }
  .msg-body { padding: 13px 20px 14px 20px; }
  .chat-message { max-width: 75%; }
}

.hide-status #status-indicator {
  opacity: 0;
}
