/**
 * 🧠 AI Personalization CSS
 * Mood-based styling and time-aware visual shifts
 */

/* ============================================================================
   AI PERSONALIZED ELEMENTS - Subtle highlight
   ============================================================================ */

.ai-personalized {
  position: relative;
}

/* Subtle shimmer effect on personalized text */
.ai-personalized::after {
  content: '';
  position: absolute;
  inset: -2px -8px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(74, 103, 65, 0.1) 50%,
    transparent 100%
  );
  border-radius: var(--radius-xs);
  opacity: 0;
  animation: ai-shimmer 2s ease-out 0.5s forwards;
  pointer-events: none;
}

@keyframes ai-shimmer {
  0% {
    opacity: 0;
    transform: translateX(-100%);
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(100%);
  }
}

.ai-returning-visitor {
  animation: returning-warmth 1s ease-out;
}

@keyframes returning-warmth {
  0% {
    opacity: 0;
    transform: translateY(-10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================================
   MOOD-BASED HERO STYLES
   ============================================================================ */

.hero {
  --hero-bg-warmth: 1;
  --hero-glow-opacity: 0.5;
  --hero-glow-spread: 100px;
}

/* Apply warmth filter to hero background */
.mood-intimate .hero__bg,
.mood-thoughtful .hero__bg {
  filter: sepia(0.05) saturate(1.1);
}

.mood-determined .hero__bg,
.mood-productive .hero__bg {
  filter: saturate(0.95) contrast(1.02);
}

/* Adjust glow based on mood */
.hero-ferni__glow {
  opacity: var(--hero-glow-opacity);
  filter: blur(var(--hero-glow-spread));
  transition: opacity 1s ease, filter 1s ease;
}

/* ============================================================================
   LATE NIGHT MODE - Special 2am vibes
   ============================================================================ */

.late-night-mode {
  /* Slightly dim everything */
  --brightness-modifier: 0.95;
}

.late-night-mode .hero {
  /* Warmer, more intimate */
  background: linear-gradient(
    180deg,
    hsl(35, 30%, 94%) 0%,
    hsl(35, 25%, 91%) 100%
  );
}

.late-night-mode .hero__tagline {
  /* More prominent for late-night message */
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
}

.late-night-mode .hero-ferni__glow {
  /* Warmer, more inviting glow */
  background: radial-gradient(
    circle,
    rgba(74, 103, 65, 0.4) 0%,
    rgba(74, 103, 65, 0.1) 50%,
    transparent 70%
  );
  animation: late-night-pulse 4s ease-in-out infinite;
}

@keyframes late-night-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.4;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.6;
  }
}

/* Highlight the 2am section when it's actually late */
.late-night-mode .two-am--highlighted {
  position: relative;
}

.late-night-mode .two-am--highlighted::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    rgba(74, 103, 65, 0.05) 0%,
    transparent 70%
  );
  pointer-events: none;
}

/* ============================================================================
   TIME-OF-DAY MOOD ACCENTS
   ============================================================================ */

/* Morning - Crisp, fresh */
.mood-energized .hero__headline-accent {
  background: linear-gradient(
    135deg,
    var(--color-ferni) 0%,
    var(--color-ferni) 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Midday - Balanced */
.mood-reflective .hero {
  --hero-glow-opacity: 0.4;
}

/* Evening - Warm unwinding */
.mood-unwinding .hero__bg-gradient {
  background: linear-gradient(
    180deg,
    var(--color-paper-cream) 0%,
    hsl(35, 35%, 90%) 100%
  );
}

/* Night - Thoughtful depth */
.mood-thoughtful .hero-ferni__ring {
  opacity: 0.4;
}

/* Intimate late-night - Extra warm presence */
.mood-intimate .hero-ferni__orb {
  box-shadow: 
    0 0 40px rgba(74, 103, 65, 0.3),
    inset 0 0 20px rgba(255, 255, 255, 0.1);
}

/* ============================================================================
   ADAPTIVE CTA STYLES
   ============================================================================ */

/* Shallow scroll - still browsing */
.btn--secondary {
  /* Default secondary style */
}

/* Engaged - read the content */
.btn--primary-emphasized {
  background: var(--color-ferni);
  color: white;
  box-shadow: 
    0 4px 12px rgba(74, 103, 65, 0.3),
    0 0 0 2px rgba(74, 103, 65, 0.1);
  transform: scale(1.02);
}

/* Ready to convert - scrolled most of page */
.btn--primary-urgent {
  background: linear-gradient(
    135deg,
    var(--color-ferni) 0%,
    var(--color-ferni-secondary) 100%
  );
  color: white;
}

/* ============================================================================
   VISITOR TIER RECOGNITION - Progressive warmth
   ============================================================================ */

/* First-time visitor - clean, inviting */
.visitor-new {
  /* Default styling */
}

/* Returning visitor - subtle recognition */
.visitor-returning .hero__tagline {
  opacity: 0;
  animation: tagline-reveal 0.8s ease-out 0.3s forwards;
}

@keyframes tagline-reveal {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Familiar visitor (3+ visits) - warmer recognition */
.visitor-familiar .hero__tagline::before {
  content: 'Welcome back. ';
  font-style: italic;
  opacity: 0.8;
}

.visitor-familiar .hero-ferni__orb {
  animation: familiar-pulse 0.6s ease-out;
}

@keyframes familiar-pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.04);
    filter: brightness(1.1);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

/* Loyal visitor (10+ visits) - special warmth */
.visitor-loyal .hero-ferni__glow {
  opacity: 0.6;
  animation: loyal-glow 3s ease-in-out infinite;
}

@keyframes loyal-glow {
  0%, 100% {
    transform: scale(1);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.15);
    opacity: 0.65;
  }
}

/* ============================================================================
   ENGAGEMENT STATE INDICATORS
   ============================================================================ */

/* High engagement - user is interested */
.engagement-high .btn--primary {
  position: relative;
  overflow: visible;
}

.engagement-high .btn--primary::before {
  content: '';
  position: absolute;
  inset: -2px;
  background: var(--color-ferni);
  border-radius: inherit;
  filter: blur(8px);
  opacity: 0.3;
  z-index: -1;
  animation: engagement-glow 2s ease-in-out infinite;
}

@keyframes engagement-glow {
  0%, 100% {
    opacity: 0.2;
    transform: scale(0.98);
  }
  50% {
    opacity: 0.35;
    transform: scale(1.02);
  }
}

/* Hesitating user - gentle nudge */
.user-hesitating .btn--secondary {
  animation: subtle-attention 2s ease-in-out infinite;
}

@keyframes subtle-attention {
  0%, 100% {
    box-shadow: 0 2px 8px rgba(74, 103, 65, 0.1);
  }
  50% {
    box-shadow: 0 4px 16px rgba(74, 103, 65, 0.2);
  }
}

/* Helpful nudge tooltip */
.helpful-nudge {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--color-background-elevated, white);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.05);
  opacity: 0;
  animation: nudge-appear 0.4s ease-out forwards;
}

.helpful-nudge::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--color-background-elevated, white);
}

@keyframes nudge-appear {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.helpful-nudge--fading {
  animation: nudge-fade 0.5s ease-out forwards;
}

@keyframes nudge-fade {
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(-4px);
  }
  box-shadow: 
    0 6px 20px rgba(74, 103, 65, 0.4),
    0 0 0 3px rgba(74, 103, 65, 0.15);
  animation: cta-pulse 2s ease-in-out infinite;
}

@keyframes cta-pulse {
  0%, 100% {
    box-shadow: 
      0 6px 20px rgba(74, 103, 65, 0.4),
      0 0 0 3px rgba(74, 103, 65, 0.15);
  }
  50% {
    box-shadow: 
      0 8px 28px rgba(74, 103, 65, 0.5),
      0 0 0 6px rgba(74, 103, 65, 0.1);
  }
}

/* High engagement state - user is very interested */
.btn--engaged {
  position: relative;
  overflow: visible;
}

.btn--engaged::before {
  content: '';
  position: absolute;
  inset: -3px;
  background: linear-gradient(
    135deg,
    rgba(74, 103, 65, 0.2) 0%,
    rgba(74, 103, 65, 0.4) 50%,
    rgba(74, 103, 65, 0.2) 100%
  );
  border-radius: inherit;
  z-index: -1;
  animation: engaged-glow 1.5s ease-out forwards;
}

@keyframes engaged-glow {
  0% {
    transform: scale(1);
    opacity: 0;
  }
  50% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(1.05);
    opacity: 0.7;
  }
}

/* Highlighted for high-intent users */
.btn--highlighted {
  animation: highlighted-attention 3s ease-in-out infinite;
}

@keyframes highlighted-attention {
  0%, 100% {
    transform: translateY(0);
    box-shadow: 0 4px 12px rgba(74, 103, 65, 0.25);
  }
  50% {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(74, 103, 65, 0.35);
  }
}

/* ============================================================================
   HESITATION DETECTION STYLES
   ============================================================================ */

/* Body class when user is hesitating */
.user-hesitating .btn--secondary {
  /* Subtle attention draw */
  animation: hesitation-hint 2s ease-in-out;
}

@keyframes hesitation-hint {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.85;
    box-shadow: 0 0 0 4px rgba(74, 103, 65, 0.1);
  }
}

/* Attention state for CTAs */
.btn--attention {
  position: relative;
}

.btn--attention::after {
  content: '';
  position: absolute;
  inset: -6px;
  border: 2px solid var(--color-ferni);
  border-radius: calc(var(--radius-lg, 8px) + 6px);
  opacity: 0;
  animation: attention-ring 2s ease-out forwards;
}

@keyframes attention-ring {
  0% {
    transform: scale(0.9);
    opacity: 0;
  }
  30% {
    opacity: 0.6;
  }
  100% {
    transform: scale(1.1);
    opacity: 0;
  }
}

/* Helpful nudge tooltip */
.helpful-nudge {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: var(--color-text-primary, var(--color-text-primary));
  color: var(--color-paper-cream, var(--color-bg-elevated));
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(44, 37, 32, 0.2);
  animation: nudge-appear 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  z-index: 100;
}

.helpful-nudge::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--color-text-primary, var(--color-text-primary));
}

@keyframes nudge-appear {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(8px) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

.helpful-nudge--fading {
  animation: nudge-fade 0.5s ease-out forwards;
}

@keyframes nudge-fade {
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(-4px);
  }
}

/* ============================================================================
   RETENTION ELEMENTS
   ============================================================================ */

.retention-highlight {
  position: relative;
}

.retention-highlight::before {
  content: '';
  position: absolute;
  inset: -20px;
  background: radial-gradient(
    ellipse at center,
    rgba(74, 103, 65, 0.03) 0%,
    transparent 60%
  );
  pointer-events: none;
  animation: retention-pulse 4s ease-in-out infinite;
}

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

/* ============================================================================
   READING PROGRESS INDICATOR (Optional)
   ============================================================================ */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--color-ferni);
  width: 0%;
  z-index: 9999;
  transition: width 0.1s ease-out;
  opacity: 0;
}

.reading-progress--visible {
  opacity: 1;
}

.reading-progress::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 100px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(74, 103, 65, 0.4)
  );
}

/* ============================================================================
   REDUCED MOTION
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  .ai-personalized::after,
  .ai-returning-visitor,
  .late-night-mode .hero-ferni__glow,
  .btn--primary-urgent {
    animation: none !important;
  }
}

