/* =============================================================
   animations.css — Keyframes, scroll-driven, stagger, reveals
   A Love Letter to the Web
   ============================================================= */

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

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(2rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

@keyframes glow {
  0%, 100% {
    box-shadow: 0 0 8px oklch(60% 0.18 265 / 0.4);
  }
  50% {
    box-shadow: 0 0 24px oklch(60% 0.18 265 / 0.8), 0 0 48px oklch(60% 0.18 265 / 0.3);
  }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-12px); }
}

@keyframes rotate-slow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ── Scroll-driven Reveal ───────────────────────────────────── */
@supports (animation-timeline: view()) {
  .scroll-reveal {
    animation: fade-in-up linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 40%;
  }
}

/* JS-based fallback for .js-reveal */
.js-reveal {
  opacity: 0;
  transform: translateY(1.5rem);
  transition:
    opacity var(--duration-slow) var(--ease-out),
    transform var(--duration-slow) var(--ease-out);
}

.js-reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* ── Scroll Progress Bar ────────────────────────────────────── */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: var(--z-toast);
  background: linear-gradient(
    to right,
    var(--color-primary),
    var(--color-accent)
  );
  transform-origin: left;
  transform: scaleX(0);
}

@supports (animation-timeline: scroll()) {
  .scroll-progress {
    animation: grow-progress linear;
    animation-timeline: scroll(root);
    transform: none;
  }
}

@keyframes grow-progress {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* ── @starting-style Animations ─────────────────────────────── */
dialog[open] {
  animation: fade-in-scale var(--duration-slow) var(--ease-out) both;
}

@starting-style {
  dialog[open] {
    opacity: 0;
    transform: scale(0.92);
  }
}

[popover]:popover-open {
  animation: fade-in-up var(--duration-slow) var(--ease-out) both;
}

@starting-style {
  [popover]:popover-open {
    opacity: 0;
    transform: translateY(1rem);
  }
}

/* ── Stagger Children ───────────────────────────────────────── */
.stagger-children > * {
  animation: fade-in-up var(--duration-slow) var(--ease-out) both;
}

.stagger-children > *:nth-child(1) { animation-delay:   0ms; }
.stagger-children > *:nth-child(2) { animation-delay:  75ms; }
.stagger-children > *:nth-child(3) { animation-delay: 150ms; }
.stagger-children > *:nth-child(4) { animation-delay: 225ms; }
.stagger-children > *:nth-child(5) { animation-delay: 300ms; }
.stagger-children > *:nth-child(6) { animation-delay: 375ms; }
.stagger-children > *:nth-child(7) { animation-delay: 450ms; }
.stagger-children > *:nth-child(8) { animation-delay: 525ms; }

/* ── Utility Animation Classes ──────────────────────────────── */
.animate-fade-in       { animation: fade-in       var(--duration-slow)  var(--ease-out) both; }
.animate-fade-in-up    { animation: fade-in-up    var(--duration-slow)  var(--ease-out) both; }
.animate-fade-in-scale { animation: fade-in-scale var(--duration-slow)  var(--ease-out) both; }
.animate-pulse         { animation: pulse         2s                    ease-in-out infinite; }
.animate-glow          { animation: glow          2s                    ease-in-out infinite; }
.animate-float         { animation: float         4s                    ease-in-out infinite; }
.animate-rotate-slow   { animation: rotate-slow   12s                   linear infinite; }

/* ── Reduced Motion Overrides ───────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .scroll-reveal,
  .js-reveal,
  .stagger-children > *,
  .animate-fade-in,
  .animate-fade-in-up,
  .animate-fade-in-scale,
  .animate-pulse,
  .animate-glow,
  .animate-float,
  .animate-rotate-slow {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  .js-reveal.revealed {
    transition: none;
  }

  .scroll-progress {
    animation: none;
    display: none;
  }
}

/* Layer 1 / Task 1 — page load choreography */
@keyframes page-in-header {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes page-in-hero {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes page-in-accent {
  from { opacity: 0; }
  to   { opacity: 1; }
}

[data-enter="header"] { animation: page-in-header 300ms ease-out both; }
[data-enter="hero"]   { animation: page-in-hero 400ms cubic-bezier(.2,.8,.2,1) 200ms both; }
[data-enter="stagger"] > * {
  animation: page-in-header 300ms ease-out both;
  animation-delay: calc(var(--stagger, var(--i, 0)) * 75ms + 250ms);
}
[data-enter="accent"] { animation: page-in-accent 600ms ease-out 500ms both; }

@media (prefers-reduced-motion: reduce) {
  [data-enter],
  [data-enter="stagger"] > * {
    animation: none !important;
  }
}

/* Layer 1 / Task 3 — micro-interactions */
/* NOTE: .zone-node is intentionally omitted from the card-lift rule because
   hub.css defines .zone-node:hover with a translate(-50%,-50%) scale(1.15)
   transform that would fight a translateY(-4px). .component-demo is also
   omitted — it's an inner demo frame inside .component-card (already has
   its own hover), not a card itself. */

/* Button hover + press */
button:not(.no-micro), [role="button"]:not(.no-micro) {
  transition: transform 150ms cubic-bezier(.2,.8,.2,1), box-shadow 200ms ease;
}
button:not(.no-micro):hover, [role="button"]:not(.no-micro):hover { transform: scale(1.02); }
button:not(.no-micro):active, [role="button"]:not(.no-micro):active { transform: scale(0.98); }

/* Button ripple */
button.ripple { position: relative; overflow: hidden; }
button.ripple::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at var(--x, 50%) var(--y, 50%), rgba(255,255,255,0.45) 0%, transparent 60%);
  opacity: 0; pointer-events: none; transition: opacity 400ms ease;
}
button.ripple.ripple-active::after { opacity: 1; animation: ripple-expand 500ms ease-out both; }
@keyframes ripple-expand { from { background-size: 0% 0%; } to { background-size: 240% 240%; } }

/* Link underline */
a.anim-underline {
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 0 1px;
  background-repeat: no-repeat;
  background-position: 0 100%;
  transition: background-size 250ms cubic-bezier(.2,.8,.2,1);
}
a.anim-underline:hover, a.anim-underline:focus-visible { background-size: 100% 1px; }

/* Card lift */
.card {
  transition: transform 200ms cubic-bezier(.2,.8,.2,1), box-shadow 200ms ease;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px -12px oklch(0 0 0 / 0.4);
}

/* Input focus glow */
input:not([type="checkbox"]):not([type="radio"]):focus-visible,
textarea:focus-visible, select:focus-visible, [contenteditable]:focus-visible {
  box-shadow: 0 0 0 3px oklch(0.65 0.18 290 / 0.35);
}

/* ── Text Effects (Layer 1 / Task 4) ────────── */

@keyframes shimmer-bg {
  from { background-position: 0% 50%; }
  to   { background-position: 200% 50%; }
}
.text-shimmer {
  background-image: linear-gradient(90deg, currentColor 0%, oklch(0.8 0.18 290) 50%, currentColor 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer-bg 4s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .text-shimmer { animation: none; color: currentColor; background: none; } }

/* letter reveal — applied by JS-wrapped spans */
@keyframes letter-reveal {
  from { opacity: 0; clip-path: inset(0 100% 0 0); }
  to   { opacity: 1; clip-path: inset(0 0 0 0); }
}
.letter-reveal > span {
  display: inline-block;
  animation: letter-reveal 500ms cubic-bezier(.2,.8,.2,1) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}
@media (prefers-reduced-motion: reduce) { .letter-reveal > span { animation: none; opacity: 1; clip-path: none; } }

/* glitch for 404 */
@keyframes glitch-skew { 0%,100% { transform: skew(0); } 50% { transform: skew(-2deg,1deg); } }
@keyframes glitch-clip-r { 0%,100% { clip-path: inset(0 0 0 0); } 20% { clip-path: inset(0 0 45% 0); } 40% { clip-path: inset(50% 0 0 0); } }
.text-glitch { position: relative; animation: glitch-skew 3.2s infinite; }
.text-glitch::before, .text-glitch::after {
  content: attr(data-text); position: absolute; inset: 0; pointer-events: none;
}
.text-glitch::before { color: #ff00aa; transform: translate(-2px,0); animation: glitch-clip-r 2.4s infinite; }
.text-glitch::after  { color: #00aaff; transform: translate(2px,0);  animation: glitch-clip-r 2.4s infinite reverse; }
@media (prefers-reduced-motion: reduce) { .text-glitch, .text-glitch::before, .text-glitch::after { animation: none; transform: none; } }

/* ── Ambient Backgrounds (Layer 1 / Task 5) ────────── */
@keyframes ambient-drift { 0%,100% { transform: translate3d(0,0,0); } 50% { transform: translate3d(3%, -4%, 0); } }
@keyframes ambient-twinkle { 0%,100% { opacity: 0.2; } 50% { opacity: 0.9; } }
@keyframes ambient-pulse { 0%,100% { background-size: 40px 40px; } 50% { background-size: 44px 44px; } }
@keyframes ambient-aurora { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.ambient-bg { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .ambient-bg { display: none; } }

/* ── Loading States (Layer 1 / Task 8) ────────── */

.skeleton {
  background: linear-gradient(90deg, oklch(1 0 0 / 0.05), oklch(1 0 0 / 0.12), oklch(1 0 0 / 0.05));
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
  border-radius: 8px; color: transparent;
}
@keyframes skeleton-shimmer { from { background-position: -100% 0; } to { background-position: 100% 0; } }

.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent, var(--color-accent, oklch(0.65 0.18 290)));
  -webkit-mask: radial-gradient(circle, transparent 60%, black 62%);
          mask: radial-gradient(circle, transparent 60%, black 62%);
  animation: spinner-rotate 1s linear infinite;
}
@keyframes spinner-rotate { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .skeleton, .spinner { animation: none; }
}
