/* app/assets/stylesheets/animations/typography.css */

/* ===============================================
   TYPOGRAPHY ANIMATIONS - DARK THEME WITH OSWALD
   =============================================== */

/* ===============================================
   TYPEWRITER ANIMATION
   =============================================== */

/* Typewriter Animation - Character by character with cursor */
.typewriter-text {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  letter-spacing: var(--tracking-wide);
  display: inline-block;
  overflow: hidden;
  border-right: 2px solid var(--accent-primary);
  white-space: nowrap;
  margin: 0 auto;
  width: 0;
  animation:
    typing 3.5s steps(30, end) forwards,
    blink 0.75s step-end infinite,
    hide-cursor 0s linear 5s forwards;
}

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

@keyframes blink {
  from, to { border-color: transparent; }
  50% { border-color: var(--accent-primary); }
}

@keyframes hide-cursor {
  to { border-right: none; }
}

/* Remove cursor after animation completes */
.typewriter-text.complete {
  border-right: none;
  animation: none;
}

/* ===============================================
   FADE IN ANIMATIONS
   =============================================== */

.fade-in {
  opacity: 0;
  animation: fadeIn 0.8s ease-out forwards;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Staggered fade-in delays */
.fade-in-delay-1 {
  animation-delay: 0.2s;
}

.fade-in-delay-2 {
  animation-delay: 0.4s;
}

.fade-in-delay-3 {
  animation-delay: 0.6s;
}

.fade-in-delay-4 {
  animation-delay: 0.8s;
}

.fade-in-delay-5 {
  animation-delay: 1.0s;
}

/* ===============================================
   SLIDE UP ANIMATIONS
   =============================================== */

.slide-up {
  opacity: 0;
  animation: slideUp 0.6s ease-out forwards;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Staggered slide-up delays */
.slide-up-delay-1 {
  animation-delay: 0.1s;
}

.slide-up-delay-2 {
  animation-delay: 0.2s;
}

.slide-up-delay-3 {
  animation-delay: 0.3s;
}

.slide-up-delay-4 {
  animation-delay: 0.4s;
}

.slide-up-delay-5 {
  animation-delay: 0.5s;
}

/* ===============================================
   CHARACTER ANIMATION
   =============================================== */

.char-animate {
  display: inline-block;
  opacity: 0;
  animation: charFadeIn 0.5s ease-out forwards;
  font-family: var(--font-display);
  color: var(--text-primary);
}

@keyframes charFadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px) rotateX(90deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotateX(0deg);
  }
}

/* Staggered character animations */
.char-1 { animation-delay: 0.05s; }
.char-2 { animation-delay: 0.10s; }
.char-3 { animation-delay: 0.15s; }
.char-4 { animation-delay: 0.20s; }
.char-5 { animation-delay: 0.25s; }
.char-6 { animation-delay: 0.30s; }
.char-7 { animation-delay: 0.35s; }
.char-8 { animation-delay: 0.40s; }
.char-9 { animation-delay: 0.45s; }
.char-10 { animation-delay: 0.50s; }

/* ===============================================
   SPLIT TEXT ANIMATION
   =============================================== */

.split-text {
  overflow: hidden;
}

.split-text.animate .word {
  display: inline-block;
  animation: wordSlideIn 0.6s ease-out forwards;
}

.split-text.animate .char {
  display: inline-block;
  opacity: 0;
  transform: translateY(100%);
  transition: all 0.3s ease-out;
}

.split-text.animate .char.animate {
  opacity: 1;
  transform: translateY(0);
}

@keyframes wordSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===============================================
   HIGHLIGHT ANIMATION
   =============================================== */

.highlight-text {
  position: relative;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  display: inline-block;
}

.highlight-text::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-info));
  border-radius: 2px;
  transition: width 0.6s ease-out;
}

.highlight-text.animate::after {
  width: 100%;
}

/* ===============================================
   TEXT REVEAL ANIMATION
   =============================================== */

.text-reveal {
  position: relative;
  overflow: hidden;
  color: var(--text-primary);
  font-family: var(--font-display);
}

.text-reveal::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--accent-primary);
  transform: translateX(-100%);
  transition: transform 0.8s ease-out;
}

.text-reveal::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--accent-primary);
  transform: translateX(0);
  transition: transform 0.8s ease-out 0.4s;
}

.text-reveal.animate::before {
  transform: translateX(0);
}

.text-reveal.animate::after {
  transform: translateX(100%);
}

/* ===============================================
   GLOW ANIMATION
   =============================================== */

.glow-text {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  text-shadow: 0 0 5px var(--accent-primary);
  animation: textGlow 2s ease-in-out infinite alternate;
}

@keyframes textGlow {
  from {
    text-shadow:
      0 0 5px var(--accent-primary),
      0 0 10px var(--accent-primary),
      0 0 15px var(--accent-primary);
  }
  to {
    text-shadow:
      0 0 10px var(--accent-primary),
      0 0 20px var(--accent-primary),
      0 0 30px var(--accent-primary);
  }
}

/* ===============================================
   WORKOUT-SPECIFIC ANIMATIONS
   =============================================== */

.workout-title-animate {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  opacity: 0;
  transform: translateY(-20px);
  animation: workoutTitleSlide 0.8s ease-out 0.2s forwards;
}

@keyframes workoutTitleSlide {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.muscle-label-animate {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  color: var(--accent-success);
  opacity: 0;
  transform: scale(0.8);
  animation: muscleLabelPop 0.5s ease-out 0.4s forwards;
}

@keyframes muscleLabelPop {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.ready-status-pulse {
  color: var(--accent-success);
  font-family: var(--font-accent);
  font-weight: var(--weight-bold);
  animation: readyPulse 1.5s ease-in-out infinite;
}

@keyframes readyPulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.05);
  }
}

/* ===============================================
   STAGGERED ANIMATIONS FOR LISTS
   =============================================== */

.stagger-container .stagger-item {
  opacity: 0;
  transform: translateY(20px);
  animation: staggerFadeIn 0.5s ease-out forwards;
}

.stagger-item:nth-child(1) { animation-delay: 0.1s; }
.stagger-item:nth-child(2) { animation-delay: 0.2s; }
.stagger-item:nth-child(3) { animation-delay: 0.3s; }
.stagger-item:nth-child(4) { animation-delay: 0.4s; }
.stagger-item:nth-child(5) { animation-delay: 0.5s; }
.stagger-item:nth-child(6) { animation-delay: 0.6s; }
.stagger-item:nth-child(7) { animation-delay: 0.7s; }
.stagger-item:nth-child(8) { animation-delay: 0.8s; }

@keyframes staggerFadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===============================================
   PAGE TRANSITION ANIMATIONS
   =============================================== */

.page-enter {
  opacity: 0;
  transform: translateY(30px);
  animation: pageEnter 0.6s ease-out forwards;
}

@keyframes pageEnter {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page-exit {
  opacity: 1;
  animation: pageExit 0.4s ease-in forwards;
}

@keyframes pageExit {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* ===============================================
   LOADING ANIMATIONS
   =============================================== */

.text-loading {
  position: relative;
  color: var(--text-secondary);
  font-family: var(--font-primary);
}

.text-loading::after {
  content: '...';
  position: absolute;
  right: -1em;
  animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

.skeleton-text {
  background: linear-gradient(90deg, var(--surface-hover) 25%, var(--surface-active) 50%, var(--surface-hover) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s infinite;
  border-radius: 4px;
  height: 1em;
  margin: 0.25em 0;
}

@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===============================================
   MOBILE OPTIMIZATIONS
   =============================================== */

@media (max-width: 768px) {
  .typewriter-text {
    font-size: var(--text-2xl);
  }

  .char-animate {
    font-size: var(--text-base);
  }

  .highlight-text::after {
    height: 2px;
  }

  .glow-text {
    font-size: var(--text-lg);
    animation-duration: 3s;
  }

  /* Reduce motion on mobile for battery */
  .fade-in,
  .slide-up {
    animation-duration: 0.4s;
  }

  .char-animate {
    animation-duration: 0.3s;
  }
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .typewriter-text {
    border-right: none;
    animation: none;
    width: auto;
  }

  .char-animate,
  .fade-in,
  .slide-up,
  .highlight-text,
  .text-reveal,
  .glow-text,
  .ready-status-pulse {
    opacity: 1;
    transform: none;
    animation: none;
  }

  .highlight-text::after {
    width: 100%;
    transition: none;
  }
}

/* ===============================================
   HIGH CONTRAST MODE
   =============================================== */

@media (prefers-contrast: high) {
  .highlight-text::after {
    background: currentColor;
    height: 4px;
  }

  .glow-text {
    text-shadow: none;
    font-weight: var(--weight-bold);
  }

  .text-reveal::before,
  .text-reveal::after {
    background: currentColor;
  }
}

/* ===============================================
   PRINT STYLES
   =============================================== */

@media print {
  .typewriter-text,
  .char-animate,
  .fade-in,
  .slide-up,
  .text-reveal,
  .glow-text {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }

  .highlight-text::after {
    display: none;
  }

  .skeleton-text {
    background: transparent;
    border: 1px solid #000;
  }
}
