:root {
  --cb-primary: #2e5c38;
  --cb-primary-dark: #1a2f23;
  --cb-accent: #00ff9d;
  --cb-earth: #8b5a2b;

  --cb-bg-glass: rgba(26, 47, 35, 0.85);
  --cb-bg-glass-light: rgba(244, 241, 234, 0.95);

  --cb-text-main: #f4f1ea;
  --cb-text-dark: #1a2f23;

  --cb-border: rgba(0, 255, 157, 0.4);
  --cb-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.45);

  --cb-width: 380px;
  --cb-height: 550px;
  --cb-radius: 16px;

  --cb-font: "Inter", system-ui, -apple-system, sans-serif;
  --cb-font-mono: "Fira Code", monospace;
}

.cb-widget {
  font-family: var(--cb-font);
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 15px;
}

.cb-toggle {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: rgba(26, 47, 35, 0.9);
  backdrop-filter: blur(8px);
  border: 2px solid var(--cb-accent);
  cursor: pointer;
  box-shadow: 0 0 20px rgba(0, 255, 157, 0.25);
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cb-text-main);
  font-size: 32px;
  position: relative;
  overflow: hidden;
}

.cb-toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at center,
    rgba(0, 255, 157, 0.2),
    transparent 70%
  );
  opacity: 0;
  transition: opacity 0.3s;
}

.cb-toggle:hover {
  transform: scale(1.1) rotate(-5deg);
  box-shadow: 0 0 30px rgba(0, 255, 157, 0.5);
  border-color: #fff;
}

.cb-toggle:hover::before {
  opacity: 1;
}

.cb-window {
  width: var(--cb-width);
  height: var(--cb-height);
  background: var(--cb-bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--cb-border);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
  opacity: 0;
  transform: scale(0.8) translateY(40px) translateX(20px);
  pointer-events: none;
  visibility: hidden;
}

.cb-window.open {
  opacity: 1;
  transform: scale(1) translateY(0) translateX(0);
  pointer-events: auto;
  visibility: visible;
}

.cb-header {
  padding: 18px 24px;
  background: linear-gradient(to right, rgba(0, 255, 157, 0.05), transparent);
  border-bottom: 1px solid rgba(0, 255, 157, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cb-title {
  font-family: var(--cb-font-mono);
  font-weight: 700;
  font-size: 1rem;
  color: var(--cb-accent);
  display: flex;
  align-items: center;
  gap: 12px;
  letter-spacing: 0.5px;
  text-shadow: 0 0 10px rgba(0, 255, 157, 0.3);
}

.cb-status-dot {
  width: 10px;
  height: 10px;
  background: var(--cb-accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--cb-accent);
  animation: pulse 2s infinite;
}

.cb-close {
  background: transparent;
  border: none;
  color: var(--cb-text-main);
  opacity: 0.5;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.cb-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
  color: var(--cb-accent);
}

.cb-messages {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.cb-messages::-webkit-scrollbar {
  width: 6px;
}

.cb-messages::-webkit-scrollbar-track {
  background: transparent;
}

.cb-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 255, 157, 0.2);
  border-radius: 3px;
}

.cb-message-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  width: 100%;
}

.cb-message-row.bot {
  justify-content: flex-start;
}

.cb-message-row.user {
  justify-content: flex-end;
}

.cb-avatar {
  width: 36px;
  height: 36px;
  background: rgba(255, 215, 0, 0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border: 1px solid rgba(255, 215, 0, 0.4);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from {
    transform: scale(0);
  }
  to {
    transform: scale(1);
  }
}

.cb-message {
  max-width: 75%;
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.6;
  position: relative;
  animation: messageIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
  transform: translateY(20px) scale(0.9);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.cb-message.bot {
  background: rgba(255, 255, 255, 0.08);
  color: var(--cb-text-main);
  border-bottom-left-radius: 4px;
  border-top-left-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(4px);
}

.cb-message.user {
  background: var(--cb-accent);
  color: var(--cb-primary-dark);
  border-bottom-right-radius: 4px;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(0, 255, 157, 0.2);
}

.cb-message.demon {
  background: linear-gradient(135deg, #2a0a0a, #4a0000);
  color: #ff6b6b;
  border: 1px solid #ff4444;
  box-shadow: 0 0 20px rgba(255, 0, 0, 0.3);
  font-family: var(--cb-font-mono);
}

.cb-input-area {
  padding: 20px;
  border-top: 1px solid var(--cb-border);
  display: flex;
  gap: 12px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
}

.cb-input {
  flex: 1;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.4);
  color: var(--cb-text-main);
  font-family: var(--cb-font);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.3s;
}

.cb-input:focus {
  border-color: var(--cb-accent);
  background: rgba(0, 0, 0, 0.6);
  box-shadow: 0 0 0 2px rgba(0, 255, 157, 0.2);
}

.cb-input::placeholder {
  color: rgba(244, 241, 234, 0.4);
}

.cb-send {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--cb-primary);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

.cb-send:hover {
  background: var(--cb-accent);
  color: var(--cb-primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 255, 157, 0.3);
}

.cb-send:active {
  transform: translateY(0);
}

@keyframes messageIn {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 255, 157, 0.6);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(0, 255, 157, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(0, 255, 157, 0);
  }
}

.cb-typing {
  display: flex;
  gap: 6px;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  border-bottom-left-radius: 2px;
  width: fit-content;
  align-self: flex-start;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.cb-dot {
  width: 8px;
  height: 8px;
  background: var(--cb-accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
  opacity: 0.7;
}

.cb-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.cb-dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 480px) {
  .cb-widget {
    bottom: 15px;
    right: 15px;
    z-index: 99999;
  }

  .cb-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    transform: translateY(100%);
    opacity: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
  }

  .cb-window.open {
    transform: translateY(0);
    opacity: 1;
  }

  .cb-header {
    padding: 15px 20px;
    padding-top: max(15px, env(safe-area-inset-top));
    background: rgba(26, 47, 35, 0.95);
  }

  .cb-messages {
    padding: 15px;
  }

  .cb-input-area {
    padding: 15px;
    padding-bottom: max(15px, env(safe-area-inset-bottom));
    background: rgba(26, 47, 35, 0.95);
  }

  .cb-toggle {
    width: 56px;
    height: 56px;
    font-size: 28px;
    /* Hide toggle when window is open on mobile */
    transition:
      opacity 0.3s,
      transform 0.3s;
  }

  .cb-widget:has(.cb-window.open) .cb-toggle {
    opacity: 0;
    pointer-events: none;
    transform: scale(0);
  }
}

#cb-turnstile {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0.01 !important;
  pointer-events: none !important;
  z-index: 9999 !important;
}
