.rex {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: var(--font-body);
}

/* Toggle button */
.rex__toggle {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0d2540, #0a1931);
  border: 2px solid rgba(0, 246, 255, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s var(--ease-out-expo);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), 0 0 30px rgba(0, 246, 255, 0.1);
}

.rex__toggle:hover {
  transform: scale(1.1);
  border-color: rgba(0, 246, 255, 0.6);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3), 0 0 50px rgba(0, 246, 255, 0.2);
}

.rex__toggle-dino {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rex__dino-icon {
  width: 100%;
  height: 100%;
  color: var(--cyan);
  animation: rexIdle 3s ease-in-out infinite;
}

.rex__dino-icon--small {
  width: 34px;
  height: 34px;
  animation: none;
}

@keyframes rexIdle {

  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }

  25% {
    transform: translateY(-2px) rotate(1deg);
  }

  75% {
    transform: translateY(1px) rotate(-1deg);
  }
}

/* Pulse ring */
.rex__toggle-pulse {
  position: absolute;
  inset: -4px;
  border: 2px solid var(--cyan);
  border-radius: 50%;
  animation: rexPulse 2.5s ease-out infinite;
  pointer-events: none;
}

@keyframes rexPulse {
  0% {
    transform: scale(1);
    opacity: 0.6;
  }

  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

/* Tooltip (Speech Bubble) */
.rex__tooltip {
  position: absolute;
  bottom: 80px;
  right: 0;
  padding: 0.75rem 1.2rem;
  background: rgba(13, 33, 55, 0.98);
  border: 1px solid var(--cyan);
  border-radius: 16px 16px 4px 16px;
  backdrop-filter: blur(12px);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--white);
  white-space: nowrap;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.4s var(--ease-out-expo);
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 15px rgba(0, 246, 255, 0.1);
  z-index: -1;
}

/* Speech bubble tail */
.rex__tooltip::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 20px;
  width: 15px;
  height: 15px;
  background: rgba(13, 33, 55, 0.98);
  border-right: 1px solid var(--cyan);
  border-bottom: 1px solid var(--cyan);
  transform: rotate(45deg);
}

.rex__tooltip.visible {
  opacity: 1;
  transform: translateY(0);
  z-index: 1000;
  animation: bubbleFloat 3s ease-in-out infinite;
}

@keyframes bubbleFloat {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-5px);
  }
}

/* Chat window */
.rex__window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  max-height: 520px;
  background: linear-gradient(160deg, rgba(13, 31, 60, 0.97), rgba(10, 25, 49, 0.98));
  border: 1px solid rgba(0, 246, 255, 0.12);
  border-radius: 20px;
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4), 0 0 40px rgba(0, 246, 255, 0.06);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: all 0.4s var(--ease-out-expo);
  overflow: hidden;
}

.rex__window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Header */
.rex__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.15);
}

.rex__header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.rex__avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--cyan-dim);
  border: 1px solid rgba(0, 246, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--cyan);
  flex-shrink: 0;
}

.rex__name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--white);
}

.rex__status {
  font-size: 0.7rem;
  color: var(--cyan);
  font-weight: 500;
}

.rex__close {
  background: none;
  border: none;
  color: var(--grey-500);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem;
  transition: color 0.2s;
  line-height: 1;
}

.rex__close:hover {
  color: var(--white);
}

/* Messages area */
.rex__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 340px;
  min-height: 200px;
  scroll-behavior: smooth;
}

.rex__messages::-webkit-scrollbar {
  width: 4px;
}

.rex__messages::-webkit-scrollbar-track {
  background: transparent;
}

.rex__messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

/* Message bubbles */
.rex-msg {
  max-width: 88%;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.55;
  animation: msgIn 0.3s var(--ease-out-expo);
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.rex-msg--bot {
  align-self: flex-start;
  background: rgba(0, 246, 255, 0.06);
  border: 1px solid rgba(0, 246, 255, 0.1);
  border-bottom-left-radius: 4px;
  color: var(--grey-200);
}

.rex-msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(0, 246, 255, 0.15), rgba(0, 180, 255, 0.1));
  border: 1px solid rgba(0, 246, 255, 0.2);
  border-bottom-right-radius: 4px;
  color: var(--white);
}

.rex-msg strong {
  color: var(--white);
  font-weight: 600;
}

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

/* Option buttons inside messages */
.rex-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.rex-opt {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.9rem;
  background: rgba(0, 246, 255, 0.05);
  border: 1px solid rgba(0, 246, 255, 0.12);
  border-radius: 10px;
  color: var(--cyan);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  width: 100%;
}

.rex-opt:hover {
  background: rgba(0, 246, 255, 0.12);
  border-color: rgba(0, 246, 255, 0.25);
  transform: translateX(4px);
}

.rex-opt--back {
  color: var(--grey-500);
  border-color: rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.78rem;
}

.rex-opt--back:hover {
  color: var(--grey-300);
  background: rgba(255, 255, 255, 0.04);
}

/* Typing indicator */
.rex-typing {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 1rem;
  align-self: flex-start;
}

.rex-typing__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cyan);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.rex-typing__dot:nth-child(2) {
  animation-delay: 0.15s;
}

.rex-typing__dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingBounce {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.3;
  }

  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Input */
.rex__input-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.1);
}

.rex__input {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  color: var(--white);
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.rex__input:focus {
  border-color: rgba(0, 246, 255, 0.3);
}

.rex__input::placeholder {
  color: var(--grey-500);
}

.rex__send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--cyan);
  border: none;
  color: var(--midnight);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.rex__send:hover {
  background: #33f8ff;
  transform: scale(1.05);
}

/* Rex dino animation states */
.rex__toggle.rex--thinking .rex__dino-icon {
  animation: rexThink 1s ease-in-out infinite;
}

@keyframes rexThink {

  0%,
  100% {
    transform: translateY(0) rotate(0);
  }

  50% {
    transform: translateY(-4px) rotate(-10deg);
  }
}

.rex__toggle.rex--typing .rex__dino-icon {
  animation: rexType 0.3s ease-in-out infinite alternate;
}

@keyframes rexType {
  from {
    transform: rotate(-3deg) translateY(0);
  }

  to {
    transform: rotate(3deg) translateY(-2px);
  }
}

.rex__toggle.rex--greeting .rex__dino-icon {
  animation: rexGreet 0.6s var(--ease-out-expo);
}

@keyframes rexGreet {
  0% {
    transform: translateY(0) scale(1);
  }

  40% {
    transform: translateY(-10px) scale(1.15) rotate(5deg);
  }

  100% {
    transform: translateY(0) scale(1) rotate(0);
  }
}

/* Mobile responsive */
@media (max-width: 480px) {
  .rex__window {
    width: calc(100vw - 32px);
    right: -8px;
    bottom: 72px;
    max-height: 70vh;
  }

  .rex {
    bottom: 16px;
    right: 16px;
  }

  .rex__toggle {
    width: 56px;
    height: 56px;
  }

  .rex__toggle-dino {
    width: 30px;
    height: 30px;
  }
}

/* In-chat avatar animation states */
.rex-avatar--thinking {
  animation: avatarThink 1s ease-in-out infinite;
}

.rex-avatar--typing {
  animation: avatarType 0.4s ease-in-out infinite alternate;
}

.rex-avatar--greeting {
  animation: avatarGreet 0.6s var(--ease-out-expo);
}

@keyframes avatarThink {

  0%,
  100% {
    transform: translateY(0) rotate(0);
  }

  30% {
    transform: translateY(-3px) rotate(-5deg);
  }

  60% {
    transform: translateY(-1px) rotate(5deg);
  }
}

@keyframes avatarType {
  from {
    transform: scale(1) rotate(-2deg);
  }

  to {
    transform: scale(1.05) rotate(2deg);
  }
}

@keyframes avatarGreet {
  0% {
    transform: scale(1) translateY(0);
  }

  40% {
    transform: scale(1.2) translateY(-5px);
  }

  100% {
    transform: scale(1) translateY(0);
  }
}

