/**
 * Text Animations CSS
 * Typography effects and text reveal utilities
 */

/* ========================================
   Word Wrapper for Line-by-Line Reveals
   ======================================== */

/* Word wrapper for overflow control */
.word-wrapper {
    display: inline-block;
    overflow: hidden;
    vertical-align: top;
    padding: 0.05em 0;
}

.word {
    display: inline-block;
    transform-origin: bottom center;
}

/* Ensure text remains readable during animation */
.word-wrapper,
.word {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Optional: Add shimmer effect to animated text */
.hero-title .word,
.section-heading .word {
    background: linear-gradient(
        120deg,
        currentColor 0%,
        currentColor 40%,
        rgba(255, 255, 255, 0.3) 50%,
        currentColor 60%,
        currentColor 100%
    );
    background-size: 200% 100%;
    background-clip: text;
    -webkit-background-clip: text;
}

/* Prevent layout shift during animation */
.hero-title,
.section-heading,
.section-title {
    min-height: 1.2em;
}

/* ========================================
   Text Reveal Animations
   ======================================== */

.text-reveal {
    overflow: hidden;
    display: inline-block;
}

.text-reveal span {
    display: inline-block;
    opacity: 0;
    transform: translateY(100%);
    transition: opacity 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.text-reveal.is-visible span {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger delays for word-by-word animation */
.text-reveal span:nth-child(1) { transition-delay: 0s; }
.text-reveal span:nth-child(2) { transition-delay: 0.05s; }
.text-reveal span:nth-child(3) { transition-delay: 0.1s; }
.text-reveal span:nth-child(4) { transition-delay: 0.15s; }
.text-reveal span:nth-child(5) { transition-delay: 0.2s; }
.text-reveal span:nth-child(6) { transition-delay: 0.25s; }
.text-reveal span:nth-child(7) { transition-delay: 0.3s; }
.text-reveal span:nth-child(8) { transition-delay: 0.35s; }
.text-reveal span:nth-child(9) { transition-delay: 0.4s; }
.text-reveal span:nth-child(10) { transition-delay: 0.45s; }

/* ========================================
   Gradient Text Effects
   ======================================== */

.text-gradient {
    background: linear-gradient(135deg, #8B0000 0%, #FFD700 50%, #8B0000 100%);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.text-gradient-animated {
    background: linear-gradient(90deg, #8B0000 0%, #FFD700 50%, #8B0000 100%);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientFlow 3s ease infinite;
}

@keyframes gradientFlow {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

/* ========================================
   Typing Effect
   ======================================== */

.typing-effect {
    overflow: hidden;
    border-right: 2px solid #8B0000;
    white-space: nowrap;
    animation: typing 3.5s steps(40, end), blink 0.75s step-end infinite;
}

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

@keyframes blink {
    from, to {
        border-color: transparent;
    }
    50% {
        border-color: #8B0000;
    }
}

/* ========================================
   Text Glow Effects
   ======================================== */

.text-glow {
    text-shadow: 0 0 10px rgba(139, 0, 0, 0.5),
                 0 0 20px rgba(139, 0, 0, 0.3),
                 0 0 30px rgba(139, 0, 0, 0.2);
}

.text-glow-gold {
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5),
                 0 0 20px rgba(255, 215, 0, 0.3),
                 0 0 30px rgba(255, 215, 0, 0.2);
}

.text-glow-pulse {
    animation: glowPulse 2s ease-in-out infinite;
}

@keyframes glowPulse {
    0%, 100% {
        text-shadow: 0 0 10px rgba(139, 0, 0, 0.5),
                     0 0 20px rgba(139, 0, 0, 0.3);
    }
    50% {
        text-shadow: 0 0 20px rgba(139, 0, 0, 0.8),
                     0 0 40px rgba(139, 0, 0, 0.5),
                     0 0 60px rgba(139, 0, 0, 0.3);
    }
}

/* ========================================
   Text Underline Effects
   ======================================== */

.text-underline-animated {
    position: relative;
    display: inline-block;
}

.text-underline-animated::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, #8B0000, #FFD700, #8B0000);
    transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.text-underline-animated:hover::after,
.text-underline-animated.active::after {
    width: 100%;
}

/* ========================================
   Split Text Animations
   ======================================== */

.split-chars {
    display: inline-block;
}

.split-chars span {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px) rotate(-5deg);
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.split-chars.animate span {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
}

/* Stagger animation for characters */
.split-chars span:nth-child(n) {
    transition-delay: calc(0.03s * var(--char-index, 0));
}

/* ========================================
   Number Counter Animation
   ======================================== */

.counter {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum';
}

.counter-animate {
    animation: counterPulse 0.3s ease;
}

@keyframes counterPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* ========================================
   Text Highlight Effects
   ======================================== */

.text-highlight {
    position: relative;
    display: inline-block;
}

.text-highlight::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40%;
    background: rgba(255, 215, 0, 0.3);
    z-index: -1;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.text-highlight.is-visible::before {
    transform: scaleX(1);
}

/* ========================================
   Fade-In Text Effects
   ======================================== */

.text-fade-in {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.text-fade-in.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.text-fade-in-left {
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.text-fade-in-left.is-visible {
    opacity: 1;
    transform: translateX(0);
}

.text-fade-in-right {
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.text-fade-in-right.is-visible {
    opacity: 1;
    transform: translateX(0);
}

/* ========================================
   Reduced Motion Support
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .text-reveal span,
    .text-fade-in,
    .text-fade-in-left,
    .text-fade-in-right,
    .split-chars span {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
    
    .text-gradient-animated,
    .typing-effect,
    .text-glow-pulse {
        animation: none !important;
    }
    
    .text-underline-animated::after {
        width: 100% !important;
        transition: none !important;
    }
}

/* ========================================
   Utility Classes
   ======================================== */

.text-smooth {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.text-sharp {
    -webkit-font-smoothing: auto;
    -moz-osx-font-smoothing: auto;
}

.text-balance {
    text-wrap: balance;
}

/* ========================================
   Accessibility: Respect Reduced Motion
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .word-wrapper,
    .word {
        transform: none !important;
        opacity: 1 !important;
        animation: none !important;
        transition: none !important;
    }
}
