/* ═══════════════════════════════════════════════════════════════════ */
/* BACKGROUND ANIMATIONS - Premium, Optimized, Performance-First */
/* ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg-anim-duration: 16s;
  --bg-anim-delay: 0s;
}

/* Animated blob gradient (hardware-accelerated) */
@keyframes drift {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  25% {
    transform: translate3d(2rem, -3rem, 0) scale(1.02);
  }
  50% {
    transform: translate3d(-1rem, 2rem, 0) scale(0.98);
  }
  75% {
    transform: translate3d(1.5rem, -1rem, 0) scale(1.01);
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes glow-pulse {
  0% {
    opacity: 0.3;
    filter: blur(20px) saturate(100%);
  }
  50% {
    opacity: 0.5;
    filter: blur(24px) saturate(125%);
  }
  100% {
    opacity: 0.3;
    filter: blur(20px) saturate(100%);
  }
}

@keyframes shimmer {
  0% {
    background-position: -1000% 0;
  }
  100% {
    background-position: 1000% 0;
  }
}

/* Reduce animations on low-power or reduced-motion mode */
@media (prefers-reduced-motion: reduce) {
  :root {
    --bg-anim-duration: 0.01s;
  }
  * {
    animation-duration: 0.01s !important;
    animation-delay: 0s !important;
    transition: none !important;
  }
}

/* For low-power Android, disable decorative animations */
html.low-power-android {
  --bg-anim-duration: 0.01s;
}

html.low-power-android body::before {
  animation: none;
  filter: blur(8px) saturate(80%) !important;
}

html.low-power-android body::after {
  animation: none;
}

/* Minimal base animations (always safe) */
body::before {
  animation: 
    drift var(--bg-anim-duration) ease-in-out infinite alternate,
    glow-pulse calc(var(--bg-anim-duration) * 0.875) ease-in-out infinite;
  will-change: transform, filter;
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Optional secondary floating element */
@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-8px) rotate(2deg); }
}

/* Smooth page transitions */
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slide-in-left {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

/* ═══════════════════════════════════════════════════════════════════ */
/* TRANSITION UTILITIES */
/* ═══════════════════════════════════════════════════════════════════ */

/* Smooth appearance for main content */
main {
  animation: fade-in 300ms ease-out;
}

/* Stagger items on page load */
.stagger-item {
  opacity: 0;
  animation: fade-in 400ms ease-out forwards;
}

.stagger-item:nth-child(1) { animation-delay: 0ms; }
.stagger-item:nth-child(2) { animation-delay: 40ms; }
.stagger-item:nth-child(3) { animation-delay: 80ms; }
.stagger-item:nth-child(4) { animation-delay: 120ms; }
.stagger-item:nth-child(5) { animation-delay: 160ms; }
.stagger-item:nth-child(6) { animation-delay: 200ms; }
.stagger-item:nth-child(7) { animation-delay: 240ms; }
.stagger-item:nth-child(8) { animation-delay: 280ms; }
.stagger-item:nth-child(n+9) { animation-delay: 320ms; }

@media (prefers-reduced-motion: reduce) {
  .stagger-item {
    animation: none;
    opacity: 1;
  }
}

/* ═══════════════════════════════════════════════════════════════════ */
/* QUESTION TRANSITION SYSTEM (for exams) */
/* ═══════════════════════════════════════════════════════════════════ */

.question-container {
  position: relative;
  overflow: hidden;
}

.question-item {
  opacity: 0;
  transform: translateY(8px);
  animation: fade-in 250ms cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.question-item.next {
  animation: slide-in-left 250ms cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.question-item.previous {
  animation-name: fade-in;
  animation-duration: 150ms;
}

/* Button feedback animations */
button, [role="button"] {
  position: relative;
  transition: 
    background-color 150ms ease-out,
    border-color 150ms ease-out,
    box-shadow 150ms ease-out,
    transform 100ms ease-out;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(125, 211, 252, 0.12);
}

button:active:not(:disabled) {
  transform: translateY(0);
  transition-duration: 80ms;
}

/* Disabled state */
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════════ */
/* INPUT FOCUS STATES */
/* ═══════════════════════════════════════════════════════════════════ */

input, textarea, select {
  transition: 
    border-color 150ms ease-out,
    background-color 150ms ease-out,
    box-shadow 150ms ease-out;
}

input:focus, 
textarea:focus, 
select:focus {
  outline: none;
  box-shadow: 
    0 0 0 2px rgba(3, 13, 31, 0.94),
    0 0 0 4px rgba(125, 211, 252, 0.26);
}

/* ═══════════════════════════════════════════════════════════════════ */
/* MODAL & DIALOG ANIMATIONS */
/* ═══════════════════════════════════════════════════════════════════ */

dialog {
  animation: scale-in 250ms ease-out;
}

dialog::backdrop {
  animation: fade-in 200ms ease-out;
  backdrop-filter: blur(8px);
}

@media (prefers-reduced-motion: reduce) {
  dialog,
  dialog::backdrop {
    animation: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════ */
/* FORM VALIDATION FEEDBACK */
/* ═══════════════════════════════════════════════════════════════════ */

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

.error-state {
  animation: shake 300ms ease-out;
}

/* ═══════════════════════════════════════════════════════════════════ */
/* LOADING & SKELETON ANIMATIONS */
/* ═══════════════════════════════════════════════════════════════════ */

@keyframes skeleton-loading {
  0% { background-position: -1000px 0; }
  100% { background-position: 1000px 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(125, 211, 252, 0.1),
    rgba(125, 211, 252, 0.2),
    rgba(125, 211, 252, 0.1)
  );
  background-size: 1000px 100%;
  animation: skeleton-loading 2s infinite;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
    background: rgba(125, 211, 252, 0.1);
  }
}

/* ═══════════════════════════════════════════════════════════════════ */
/* ACCESSIBILITY - FOCUS INDICATORS */
/* ═══════════════════════════════════════════════════════════════════ */

*:focus-visible {
  outline: 2px solid #7dd3fc;
  outline-offset: 2px;
}

/* Disable outline on mouse users (but keep for keyboard) */
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid #7dd3fc;
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════════ */
/* PERFORMANCE OPTIMIZATION HELPERS */
/* ═══════════════════════════════════════════════════════════════════ */

/* Use for elements that will be animated */
.animate-transform {
  will-change: transform;
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
}

.animate-opacity {
  will-change: opacity;
}

/* Clean up will-change when animation ends */
@media (prefers-reduced-motion: reduce) {
  .animate-transform,
  .animate-opacity {
    will-change: auto;
  }
}
