/**
 * AI Search Styles
 * Gradient-animated AI search button with morphing icon
 */

/* AI Button Container */
.ai-search-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  z-index: 3;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-search-btn:active {
  transform: translateY(-50%) scale(0.9);
}

/* AI Icon - Simple Gem/Sparkle */
.ai-icon {
  width: 20px;
  height: 20px;
  position: relative;
}

/* Idle state - simple white icon */
.ai-icon svg {
  width: 100%;
  height: 100%;
  fill: white;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.ai-search-btn:hover .ai-icon svg {
  opacity: 0.8;
}

/* Focus state - animated gradient icon */
.search-input-compact:focus ~ .ai-search-btn .ai-icon svg {
  opacity: 1;
  animation: sparkle 2s ease-in-out infinite;
  fill: url(#ai-gradient);
}

/* Active state - spinning with gradient */
.ai-search-btn.active .ai-icon svg {
  opacity: 1;
  fill: white;
  animation: spin-sparkle 1.2s linear infinite;
}

/* Gradient definition for SVG */
.ai-gradients {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* Sparkle animation - subtle morph */
@keyframes sparkle {
  0%, 100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  25% {
    transform: scale(1.1) rotate(5deg);
    opacity: 0.9;
  }
  50% {
    transform: scale(1.05) rotate(-5deg);
    opacity: 1;
  }
  75% {
    transform: scale(1.1) rotate(5deg);
    opacity: 0.9;
  }
}

/* Spin animation for active state */
@keyframes spin-sparkle {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Adjust search input to make room for AI button */
.search-wrapper-compact .search-input-compact {
  padding-right: 40px;
}

/* Input focus state with "ask me" placeholder */
.search-input-compact:focus {
  border-color: var(--accent);
  background: var(--bg-card);
}

.search-input-compact:focus::placeholder {
  opacity: 0.8;
}

/* Active state - input fills with gradient */
.search-wrapper-compact.ai-active .search-input-compact {
  background: linear-gradient(
    90deg,
    var(--accent-board) 0%,
    var(--accent-deck) 50%,
    var(--accent-game) 100%
  );
  background-size: 200% 100%;
  animation: gradient-flow 3s ease infinite;
  color: white;
  border-color: transparent;
}

/* Gradient flow animation */
@keyframes gradient-flow {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* Status message styling */
.search-wrapper-compact.ai-active .search-input-compact::placeholder {
  color: rgba(255, 255, 255, 0.9);
  opacity: 1;
}

/* Hide autocomplete during AI search */
.search-wrapper-compact.ai-active .autocomplete-dropdown {
  display: none !important;
}

/* Disable search icon during AI active state */
.search-wrapper-compact.ai-active .search-icon {
  opacity: 0.3;
}

/* AI button stays visible and white during active state */
.search-wrapper-compact.ai-active .ai-search-btn {
  pointer-events: none;
}

/* Gradient animation on focus (subtle hint) */
.search-input-compact:focus ~ .ai-search-btn::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: linear-gradient(
    90deg,
    var(--accent-board) 0%,
    var(--accent-deck) 50%,
    var(--accent-game) 100%
  );
  opacity: 0;
  animation: pulse-glow 2s ease-in-out infinite;
  z-index: -1;
}

@keyframes pulse-glow {
  0%, 100% {
    opacity: 0;
    transform: scale(1);
  }
  50% {
    opacity: 0.3;
    transform: scale(1.3);
  }
}

/* Mobile adjustments */
@media (max-width: 500px) {
  .ai-search-btn {
    width: 28px;
    height: 28px;
    right: 6px;
  }

  .ai-icon {
    width: 22px;
    height: 22px;
  }

  .search-wrapper-compact .search-input-compact {
    padding-right: 38px;
  }
}

/* Accessibility - reduce motion */
@media (prefers-reduced-motion: reduce) {
  .ai-icon svg,
  .ai-search-btn,
  .search-wrapper-compact.ai-active .search-input-compact {
    animation: none !important;
  }

  .search-input-compact:focus ~ .ai-search-btn .ai-icon svg {
    animation: none;
  }
}
