/* 06-animations.css — Keyframes, stagger, skeleton, HTMX transitions */

/* ─── Stagger Animations ─── */

.stagger > * {
  animation: cellar-rise 0.7s var(--ease-out) both;
}

.stagger > *:nth-child(2) {
  animation-delay: 0.08s;
}

.stagger > *:nth-child(3) {
  animation-delay: 0.16s;
}

.stagger > *:nth-child(4) {
  animation-delay: 0.24s;
}

.stagger > *:nth-child(5) {
  animation-delay: 0.32s;
}

.stagger > *:nth-child(6) {
  animation-delay: 0.4s;
}

.stagger > *:nth-child(7) {
  animation-delay: 0.48s;
}

.stagger > *:nth-child(8) {
  animation-delay: 0.56s;
}

/* Re-trigger stagger on HTMX swaps (snappier timing) */
.stagger--htmx > * {
  animation: cellar-rise 0.5s var(--ease-out) both;
}

.stagger--htmx > *:nth-child(2) { animation-delay: 0.06s; }
.stagger--htmx > *:nth-child(3) { animation-delay: 0.12s; }
.stagger--htmx > *:nth-child(4) { animation-delay: 0.18s; }
.stagger--htmx > *:nth-child(5) { animation-delay: 0.24s; }
.stagger--htmx > *:nth-child(6) { animation-delay: 0.3s; }

@keyframes cellar-rise {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cellar-exit {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(12px);
  }
}

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

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

/* Button spinner */
@keyframes cellar-spin {
  to { transform: rotate(360deg); }
}

/* ─── Loading / Polling States ─── */

.cellar-pulse {
  animation: cellar-pulse 2s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .stagger > *,
  .stagger--htmx > * {
    animation: none;
  }

  .wine-browse-card,
  .feature-card,
  .recommendations .card,
  .vintage-row,
  .btn,
  .form-control,
  .form-select,
  a {
    transition: none !important;
  }

  .skeleton {
    animation: none;
  }

  .cellar-pulse {
    animation: none;
    opacity: 1;
  }

  .toast {
    animation: none !important;
  }

  .toast--exiting {
    animation: none !important;
  }

  .hero__title,
  .hero__panel,
  .hero__lead,
  .hero__actions {
    animation: none;
  }
}

/* ─── Loading Skeleton (Dark) ─── */

/* ─── Skeleton Cards — match wine card anatomy ─── */

.skeleton-card {
  background: var(--noir-900);
  border: 1px solid var(--border-default);
  border-top: 2px solid rgba(139, 41, 66, 0.3);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.skeleton-card:nth-child(even) {
  border-top-color: rgba(79, 126, 163, 0.3);
}

.skeleton-card:nth-child(3n) {
  border-top-color: rgba(212, 184, 92, 0.3);
}

.skeleton-card__header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: var(--space-3);
}

.skeleton-card__stars {
  display: flex;
  gap: 4px;
  margin-top: var(--space-3);
}

.skeleton--dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.skeleton--badge {
  width: 48px;
  height: 10px;
  border-radius: var(--radius-sm);
}

.skeleton--title {
  width: 90%;
  height: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.skeleton--subtitle {
  width: 60%;
  height: 12px;
  border-radius: var(--radius-sm);
}

.skeleton--star {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

/* Shimmer with stagger */
.skeleton {
  background: var(--noir-700);
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.03) 50%, transparent 100%);
  animation: shimmer 1.8s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 0.15s);
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Legacy grid helpers (kept for backward compat) */
.skeleton-grid {
  display: none;
}

.htmx-request .skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.htmx-request ~ .skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

/* Star rating click pulse */
@keyframes cellar-star-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.star-rating__star--pulse {
  animation: cellar-star-pulse 0.4s ease-out;
}

/* ─── HTMX Transitions ─── */

/* HTMX swap transitions */
.htmx-swapping {
  opacity: 0.6;
  transition: opacity 0.15s ease-out;
}

.htmx-settling {
  opacity: 0;
  transform: translateY(8px);
}

.htmx-settling.htmx-added {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

/* ─── Scroll-Triggered Reveals ─── */

[data-reveal] {
  opacity: 0;
  transform: translateY(16px);
}

[data-reveal].revealed {
  animation: cellar-rise 0.5s var(--ease-out) forwards;
}

[data-reveal].revealed > .stagger {
  animation: cellar-rise 0.5s var(--ease-out) forwards;
}

@media (prefers-reduced-motion: reduce) {
  [data-reveal] {
    opacity: 1;
    transform: none;
  }
}
