/* ─────────────────────────────────────────
   MOTION — lightweight scroll-reveal + entry animations
   Paired with assets/js/motion.js.

   Performance rules followed here:
   - Only `opacity` and `translate` are animated (GPU-composited, no layout/paint).
   - `translate` is used instead of `transform`, so existing hover/slider
     transforms on the same elements keep working.
   - No `will-change`, no infinite animations, no scroll listeners.
   - Everything is scoped under `.cc-motion`, which motion.js only adds when
     the user has NOT asked for reduced motion. If JS fails, nothing is hidden.
───────────────────────────────────────── */

/* Scroll reveal: hidden state (class added by motion.js) */
.cc-motion .cc-reveal {
  opacity: 0;
  translate: 0 24px;
  transition:
    opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1),
    translate 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Scroll reveal: visible state (motion.js removes both classes afterwards) */
.cc-motion .cc-reveal.cc-in {
  opacity: 1;
  translate: none;
}

/* Entry animation for cards rendered from Supabase data.
   `backwards` fill only applies during the delay, so hover effects are untouched
   once the animation ends. Re-renders (filters, pagination) replay it. */
@keyframes cc-rise {
  from {
    opacity: 0;
    translate: 0 16px;
  }
  to {
    opacity: 1;
    translate: none;
  }
}

.cc-motion #product-grid .product-card,
.cc-motion .wishlist-card,
.cc-motion .review-card {
  animation: cc-rise 0.45s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

/* Small stagger for the first cards; the rest share the last delay. */
.cc-motion #product-grid .product-card:nth-child(2),
.cc-motion .wishlist-card:nth-child(2),
.cc-motion .review-card:nth-child(2) { animation-delay: 0.05s; }
.cc-motion #product-grid .product-card:nth-child(3),
.cc-motion .wishlist-card:nth-child(3),
.cc-motion .review-card:nth-child(3) { animation-delay: 0.1s; }
.cc-motion #product-grid .product-card:nth-child(4),
.cc-motion .wishlist-card:nth-child(4),
.cc-motion .review-card:nth-child(4) { animation-delay: 0.15s; }
.cc-motion #product-grid .product-card:nth-child(n + 5),
.cc-motion .wishlist-card:nth-child(n + 5),
.cc-motion .review-card:nth-child(n + 5) { animation-delay: 0.2s; }

/* Tab panels (account dashboard, admin dashboard): the animation replays
   automatically whenever a panel switches from display:none to visible. */
@keyframes cc-panel-in {
  from {
    opacity: 0;
    translate: 0 10px;
  }
  to {
    opacity: 1;
    translate: none;
  }
}

.cc-motion .dash-panel.active,
.cc-motion .admin-panel.active {
  animation: cc-panel-in 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ─────────────────────────────────────────
   INTERACTIONS — hover / press feedback
   - Layered ON TOP of each page's existing hover styles, never replacing them:
     only independent properties (`scale`, `translate`, `rotate`,
     text-decoration colour, pseudo-elements nobody else uses) are touched.
   - Hover effects are limited to real mouse/trackpad devices, so taps on
     phones don't leave "stuck" hover states.
───────────────────────────────────────── */

/* Text selection in brand colours (not motion — always on) */
::selection {
  background: rgba(255, 217, 61, 0.6);
  color: #111827;
}

/* Visible keyboard focus ring (accessibility; mouse clicks don't trigger it).
   Zero specificity via :where(), so any page's own focus style still wins. */
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--cc-yellow, #FFD93D);
  outline-offset: 2px;
}

/* Press feedback on every button: a quick squeeze while held.
   Uses an animation on `scale`, so existing `transition`/`transform` rules
   on buttons are left exactly as they were. */
@keyframes cc-press {
  to { scale: 0.96; }
}

.cc-motion :is(button, [class*="btn"], .featured-tab, .account-tab, .payment-option):not(:disabled):active {
  animation: cc-press 0.08s ease-out forwards;
}

@media (hover: hover) and (pointer: fine) {
  /* Light sweep across the main call-to-action buttons */
  .cc-motion :is(.hero-btn-primary, .top-seller-cta, .checkout-btn,
                 .place-order-btn, .account-btn, .purchase-info .btn) {
    position: relative;
    overflow: hidden;
  }

  .cc-motion :is(.hero-btn-primary, .top-seller-cta, .checkout-btn,
                 .place-order-btn, .account-btn, .purchase-info .btn)::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 35%, rgba(255, 255, 255, 0.45) 50%, transparent 65%);
    translate: -120% 0;
    pointer-events: none;
  }

  .cc-motion :is(.hero-btn-primary, .top-seller-cta, .checkout-btn,
                 .place-order-btn, .account-btn, .purchase-info .btn):not(:disabled):hover::after {
    translate: 120% 0;
    transition: translate 0.6s ease;
  }

  /* Images: gentle zoom inside cards that already clip (overflow: hidden) */
  .cc-motion .featured-grid .product-card img,
  .cc-motion .top-seller-image img,
  .cc-motion .wishlist-card img {
    transition: scale 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .cc-motion .featured-grid .product-card:hover img,
  .cc-motion .top-seller-card:hover .top-seller-image img,
  .cc-motion .wishlist-card:hover img {
    scale: 1.06;
  }

  /* Images: float up a little (hero photo, About Me illustrations) */
  .cc-motion .hero-image img,
  .cc-motion .about-me-panel-image img {
    transition:
      translate 0.45s cubic-bezier(0.16, 1, 0.3, 1),
      rotate 0.45s cubic-bezier(0.16, 1, 0.3, 1),
      scale 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .cc-motion .hero-image img:hover {
    translate: 0 -8px;
    rotate: -1deg;
  }

  .cc-motion .about-me-panel-image img:hover {
    translate: 0 -6px;
    scale: 1.03;
  }

  /* Headings: yellow underline slides in under the text on hover.
     text-decoration follows the actual text width, so layout never changes.
     The hero title is skipped (it is split into animated words by main.js). */
  .cc-motion :is(main, section) :is(h1, h2, h3):not(.hero h1) {
    text-decoration-line: underline;
    text-decoration-color: transparent;
    text-decoration-thickness: 3px;
    text-underline-offset: 8px;
    transition:
      text-decoration-color 0.3s ease,
      text-underline-offset 0.3s ease;
  }

  .cc-motion :is(main, section) :is(h1, h2, h3):not(.hero h1):hover {
    text-decoration-color: var(--cc-yellow, #FFD93D);
    text-underline-offset: 4px;
  }

  /* Sentences: motion.js wraps each sentence of static paragraphs in
     .cc-sent; hovering one sweeps a highlighter marker across it. */
  .cc-motion .cc-sent {
    background-image: linear-gradient(transparent 60%, rgba(255, 217, 61, 0.5) 60%);
    background-repeat: no-repeat;
    background-size: 0% 100%;
    transition: background-size 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .cc-motion .cc-sent:hover {
    background-size: 100% 100%;
  }
}

/* Belt and braces: if the OS setting changes after load, stop everything. */
@media (prefers-reduced-motion: reduce) {
  .cc-motion .cc-reveal {
    opacity: 1;
    translate: none;
    transition: none;
  }

  .cc-motion #product-grid .product-card,
  .cc-motion .wishlist-card,
  .cc-motion .review-card,
  .cc-motion .dash-panel.active,
  .cc-motion .admin-panel.active,
  .cc-motion :is(button, [class*="btn"]):active {
    animation: none;
  }

  .cc-motion img,
  .cc-motion :is(main, section) :is(h1, h2, h3),
  .cc-motion .cc-sent,
  .cc-motion [class*="btn"]::after {
    transition: none !important;
  }
}

@media print {
  .cc-motion .cc-reveal {
    opacity: 1;
    translate: none;
  }
}
