/* ============================================================================
   SHARED ANIMATION UTILITIES
   Стандартизированные анимации для всего проекта.
   Подключается на всех страницах через <link href="/assets/animations.css">.
   Уважает prefers-reduced-motion (см. lightB-components.css).
   ============================================================================ */

/* =============================================================================
   KEYFRAMES — Единый набор для проекта
   ============================================================================= */

/* --- Fade --- */
@keyframes a-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes a-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* --- Slide + Fade --- */
@keyframes a-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes a-slide-down {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes a-slide-in-right {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* --- Scale --- */
@keyframes a-scale-in {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

/* --- Emphasis --- */
@keyframes a-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

@keyframes a-pulse-once {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.03); }
}

/* --- Progress / bars --- */
@keyframes a-grow-width {
  from { width: 0%; }
}

@keyframes a-count-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Shimmer (skeleton loader) --- */
@keyframes a-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* =============================================================================
   UTILITY CLASSES — Apply via class attribute
   ============================================================================= */

/* Entrance animations */
.anim-fade-in {
  animation: a-fade-in 0.3s ease-out both;
}

.anim-slide-up {
  animation: a-slide-up 0.4s ease-out both;
}

.anim-slide-down {
  animation: a-slide-down 0.35s ease-out both;
}

.anim-slide-in-right {
  animation: a-slide-in-right 0.35s ease-out both;
}

.anim-scale-in {
  animation: a-scale-in 0.3s ease-out both;
}

/* Emphasis */
.anim-shake {
  animation: a-shake 0.4s ease;
}

.anim-pulse-once {
  animation: a-pulse-once 0.3s ease-out;
}

/* Stagger delays (for lists/grids — add to children) */
.anim-delay-1 { animation-delay: 0.05s; }
.anim-delay-2 { animation-delay: 0.10s; }
.anim-delay-3 { animation-delay: 0.15s; }
.anim-delay-4 { animation-delay: 0.20s; }
.anim-delay-5 { animation-delay: 0.25s; }
.anim-delay-6 { animation-delay: 0.30s; }

/* =============================================================================
   INTERACTION PATTERNS — Reusable hover/active/focus
   ============================================================================= */

/* Card lift on hover (subtle) */
.interact-lift {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.interact-lift:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.interact-lift:active {
  transform: translateY(0) scale(0.98);
}

/* Button press feedback */
.interact-press {
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}
.interact-press:active {
  transform: scale(0.97);
}

/* Smooth color transition (links, nav items, badges) */
.interact-color {
  transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast);
}

/* Smooth all (general-purpose) */
.interact-all {
  transition: all var(--transition-normal);
}

/* =============================================================================
   PROGRESS BAR — Smooth width transitions
   ============================================================================= */
.progress-animated {
  transition: width 0.6s ease-out;
}

.progress-grow {
  animation: a-grow-width 0.8s ease-out both;
}

/* =============================================================================
   STAT COUNTER — Entrance for numeric stats
   ============================================================================= */
.stat-enter {
  animation: a-count-up 0.4s ease-out both;
}

/* =============================================================================
   DETAIL / ACCORDION PANEL — Smooth expand/collapse
   ============================================================================= */
.panel-expand {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.25s ease, padding 0.3s ease;
}

.panel-expand.collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* =============================================================================
   PAGE ENTRANCE — Whole-page fade+slide for first render
   ============================================================================= */
.page-enter {
  animation: a-slide-up 0.45s ease-out both;
}

/* =============================================================================
   MODAL — Standard open/close
   ============================================================================= */
.modal-animated {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-animated.open {
  opacity: 1;
  visibility: visible;
}

.modal-animated .modal-content {
  transform: scale(0.96) translateY(8px);
  transition: transform 0.25s ease;
}

.modal-animated.open .modal-content {
  transform: scale(1) translateY(0);
}

/* =============================================================================
   PAGE TRANSITION - Shared navigation enter/leave
   Theme-safe: only opacity/transform (no color overlay).
   ============================================================================= */
.app-page-transition {
  transition: opacity 140ms ease;
  will-change: opacity;
}

.app-page-enter {
  opacity: 0;
}

.app-page-enter-active {
  opacity: 1;
}

.app-page-leave {
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .app-page-transition {
    transition: none !important;
  }

  .app-page-enter,
  .app-page-enter-active,
  .app-page-leave {
    opacity: 1 !important;
  }
}

/* =============================================================================
   SUCCESS / FAILURE GAME EFFECTS
   ============================================================================= */

/* --- Animated SVG Checkmark --- */
.success-checkmark-circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  animation: a-checkmark-circle 0.5s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.success-checkmark-check {
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: a-checkmark-draw 0.35s cubic-bezier(0.65, 0, 0.45, 1) 0.35s forwards;
}

.success-checkmark-svg {
  animation: a-checkmark-scale 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}

@keyframes a-checkmark-circle {
  to { stroke-dashoffset: 0; }
}

@keyframes a-checkmark-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes a-checkmark-scale {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Animated SVG Error Cross --- */
.error-cross-circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  animation: a-checkmark-circle 0.5s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.error-cross-line {
  stroke-dasharray: 30;
  stroke-dashoffset: 30;
  animation: a-cross-draw 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.35s forwards;
}

.error-cross-line-2 {
  animation-delay: 0.45s;
}

.error-cross-svg {
  animation: a-checkmark-scale 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}

@keyframes a-cross-draw {
  to { stroke-dashoffset: 0; }
}

/* --- Result Box Glow (theme-aware via --_glow set by JS) --- */
@keyframes a-result-glow {
  0%   { box-shadow: 0 0 0 0 transparent; }
  40%  { box-shadow: 0 0 20px 4px var(--_glow); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.result-glow-success,
.result-glow-error {
  animation: a-result-glow 1s ease-out;
}

/* --- Result Title Bounce --- */
@keyframes a-title-bounce {
  0%   { transform: scale(0.3); opacity: 0; }
  50%  { transform: scale(1.08); opacity: 1; }
  70%  { transform: scale(0.96); }
  100% { transform: scale(1); opacity: 1; }
}

.result-title-bounce {
  animation: a-title-bounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* --- Next Button Glow (theme-aware via --_glow set by JS) --- */
@keyframes a-next-btn-glow {
  0%   { box-shadow: 0 0 0 0 transparent; transform: scale(0.95); }
  20%  { transform: scale(1.05); }
  40%  { box-shadow: 0 0 16px 4px var(--_glow); transform: scale(1); }
  70%  { box-shadow: 0 0 8px 2px var(--_glow); }
  100% { box-shadow: 0 0 0 0 transparent; transform: scale(1); }
}

.next-btn-glow {
  animation: a-next-btn-glow 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* --- Progress Bar Shimmer --- */
@keyframes a-progress-shimmer {
  0%   { background-position: -100% 0; }
  100% { background-position: 200% 0; }
}

.progress-shimmer {
  background-image: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.5) 50%,
    transparent 100%
  );
  background-size: 50% 100%;
  background-repeat: no-repeat;
  animation: a-progress-shimmer 0.8s ease-out;
}

/* --- Streak Badge --- */
.streak-badge {
  margin-left: auto;
  flex-shrink: 0;
}

.streak-badge-inner {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(245, 158, 11, 0.2));
  color: var(--color-warning-dark, #92400e);
  border: 1px solid rgba(245, 158, 11, 0.3);
  animation: a-streak-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.streak-badge-hot .streak-badge-inner,
.streak-badge-hot {
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.2), rgba(239, 68, 68, 0.15));
  border-color: rgba(249, 115, 22, 0.4);
}

.streak-badge-epic .streak-badge-inner,
span.streak-badge-inner.streak-badge-epic {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(168, 85, 247, 0.2));
  border-color: rgba(239, 68, 68, 0.4);
  animation: a-streak-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both,
             a-streak-pulse 1.5s ease-in-out 0.4s 2;
}

@keyframes a-streak-pop {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes a-streak-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}

/* --- Reduced motion: disable all game effects --- */
@media (prefers-reduced-motion: reduce) {
  .success-checkmark-circle,
  .success-checkmark-check,
  .success-checkmark-svg,
  .error-cross-circle,
  .error-cross-line,
  .error-cross-svg,
  .result-glow-success,
  .result-glow-error,
  .result-title-bounce,
  .next-btn-glow,
  .progress-shimmer,
  .streak-badge-inner,
  .streak-badge-epic .streak-badge-inner {
    animation: none !important;
  }

  .success-checkmark-circle,
  .error-cross-circle {
    stroke-dashoffset: 0;
  }

  .success-checkmark-check,
  .error-cross-line {
    stroke-dashoffset: 0;
  }
}
