/* ====================================
   TYPEWRITER ANIMATION
   Premium Hero Text Effect
   ==================================== */

.typewriter-container {
  display: inline-flex;
  align-items: baseline;
  position: relative;
  min-height: 1.2em;
  vertical-align: bottom;
  padding-right: 0.12em;
}

.typewriter-container::before {
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 0.08em;
  height: 0.42em;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.18) 0%, rgba(139, 92, 246, 0.14) 45%, rgba(6, 182, 212, 0.08) 75%, transparent 100%);
  filter: blur(12px);
  opacity: 0.72;
  pointer-events: none;
}

.typewriter-container::after {
  content: '';
  position: absolute;
  inset: -0.08em -0.1em -0.04em -0.1em;
  border-radius: 0.24em;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(139, 92, 246, 0.06), rgba(6, 182, 212, 0.08));
  opacity: 0;
  filter: blur(16px);
  pointer-events: none;
}

.typewriter-container.ready::after {
  opacity: 0.42;
}

.typewriter-container.ready {
  animation: typeGlowPulse 4.2s ease-in-out infinite;
}

@keyframes typeGlowPulse {
  0%, 100% {
    filter: drop-shadow(0 0 3px rgba(99, 102, 241, 0.14))
            drop-shadow(0 0 8px rgba(139, 92, 246, 0.12));
  }
  50% {
    filter: drop-shadow(0 0 5px rgba(99, 102, 241, 0.2))
            drop-shadow(0 0 12px rgba(139, 92, 246, 0.16))
            drop-shadow(0 0 18px rgba(6, 182, 212, 0.1));
  }
}

@media (prefers-reduced-motion: reduce) {
  .typewriter-container.ready {
    animation: none;
    filter: drop-shadow(0 0 3px rgba(99, 102, 241, 0.14));
  }
}

@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .typewriter-text,
  .typewriter-text::after {
    background: none;
    -webkit-text-fill-color: initial;
    color: #8b5cf6;
  }
}

@supports (-webkit-text-stroke: 1px transparent) {
  .typewriter-text {
    -webkit-text-stroke: 0.18px rgba(255, 255, 255, 0.16);
  }
}

.typewriter-container[data-tone='white-glow'] {
  isolation: isolate;
  will-change: filter;
  transform: translateZ(0);
}

.typewriter-container[data-tone='white-glow'] .typewriter-text {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 24%, #c7d2fe 58%, #8b5cf6 85%, #38bdf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  text-rendering: geometricPrecision;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.typewriter-container[data-tone='white-glow'] .typewriter-text::after {
  background: linear-gradient(180deg, #ffffff 0%, #c7d2fe 55%, #38bdf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  opacity: 0.9;
  text-rendering: geometricPrecision;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.typewriter-container[data-tone='white-glow']::before {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.12) 0%, rgba(139, 92, 246, 0.16) 44%, rgba(56, 189, 248, 0.08) 74%, transparent 100%);
}

.typewriter-container[data-tone='white-glow']::after {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(139, 92, 246, 0.06), rgba(56, 189, 248, 0.06));
}

.typewriter-container[data-tone='white-glow'].ready {
  animation-name: typeGlowPulseWhite;
}

@keyframes typeGlowPulseWhite {
  0%, 100% {
    filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.1))
            drop-shadow(0 0 8px rgba(139, 92, 246, 0.12));
  }
  50% {
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.14))
            drop-shadow(0 0 10px rgba(139, 92, 246, 0.16))
            drop-shadow(0 0 16px rgba(56, 189, 248, 0.1));
  }
}

.typewriter-text {
  display: inline-block;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #06b6d4 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
  position: relative;
  white-space: nowrap;
  overflow: visible;
  /* No filter here — it doesn't render properly on background-clip:text elements */
}

/* Typing cursor */
.typewriter-text::after {
  content: '|';
  position: absolute;
  right: -2px;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: cursorBlink 1s step-end infinite;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Typing animation classes */
.typewriter-text.typing {
  animation: typing 2s steps(30, end);
}

.typewriter-text.deleting {
  animation: deleting 1.5s steps(30, end);
}

@keyframes typing {
  from { width: 0; }
  to { width: 100%; }
}

@keyframes deleting {
  from { width: 100%; }
  to { width: 0; }
}

/* Smooth appearance on load */
.typewriter-container.initializing .typewriter-text {
  opacity: 0;
}

.typewriter-container.ready .typewriter-text {
  opacity: 1;
  transition: opacity 0.3s ease;
}

/* Mobile optimization */
@media (max-width: 768px) {
  .typewriter-text {
    font-size: inherit;
    line-height: inherit;
  }
}

/* Ensure proper spacing for dynamic text */
.hero-title {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3em;
  align-items: baseline;
  justify-content: flex-start;
}

@media (max-width: 768px) {
  .hero-title {
    flex-direction: column;
    gap: 0.2em;
    align-items: flex-start;
  }

  .typewriter-container {
    width: 100%;
    justify-content: flex-start;
  }
}

/* Prevent layout shift */
.typewriter-text {
  min-width: 2ch;
}

/* Performance optimization */
.typewriter-container,
.typewriter-text,
.typewriter-text::after {
  will-change: width, opacity, filter;
}

/* Hide cursor during deleting animation */
.typewriter-text.deleting::after {
  animation: none;
  opacity: 0.5;
}
