/* ==========================================================================
   AVENTRA IMPEX — Spice Concept Page Preloader + Page Entrance Motion
   Shown on every page load; fades out once the page is ready.
   ========================================================================== */

/* ---------- Lock scroll + hide content while loading ---------- */
html.is-loading,
html.is-loading body {
  overflow: hidden;
}

/* Keep the page behind the overlay until the loader lifts, so nothing flashes.
   The failsafe animation restores visibility even if the script never runs. */
html.is-loading body > *:not(.spice-preloader) {
  visibility: hidden;
  animation: plFailsafe 0.01s linear 6s forwards;
}

@keyframes plFailsafe {
  to { visibility: visible; }
}

/* ---------- Overlay ---------- */
.spice-preloader {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 560px at 50% 38%, rgba(200, 150, 62, 0.16), transparent 66%),
    linear-gradient(145deg, #041a0d 0%, #0b2e1b 55%, #0e3a21 100%);
  opacity: 1;
  transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.7s;
}

.spice-preloader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Warm grain texture over the backdrop */
.spice-preloader::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 18% 22%, rgba(234, 88, 12, 0.14), transparent 34%),
    radial-gradient(circle at 82% 74%, rgba(250, 204, 21, 0.12), transparent 36%);
  animation: plBackdrop 9s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes plBackdrop {
  from { transform: scale(1)    translateY(0); opacity: 0.85; }
  to   { transform: scale(1.12) translateY(-16px); opacity: 1; }
}

.pl-inner {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.85rem;
  padding: 0 1.5rem;
  text-align: center;
}

/* ---------- The grinding bowl ---------- */
.pl-stage {
  position: relative;
  width: 160px;
  height: 160px;
  display: grid;
  place-items: center;
}

/* Rotating dashed ring — the "mill" */
.pl-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px dashed rgba(212, 163, 75, 0.45);
  animation: plSpin 7s linear infinite;
}

.pl-ring-2 {
  inset: 16px;
  border-style: solid;
  border-color: rgba(212, 163, 75, 0.18);
  border-top-color: var(--gold-500, #d4a34b);
  animation: plSpin 1.5s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

@keyframes plSpin {
  to { transform: rotate(360deg); }
}

/* Centre bowl with the mortar & pestle mark */
.pl-bowl {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(212, 163, 75, 0.35);
  box-shadow: inset 0 0 28px rgba(200, 150, 62, 0.22), 0 14px 34px -16px rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
}

.pl-mp {
  width: 48px;
  height: 48px;
  color: var(--gold-400, #eab308);
  overflow: visible;
}

/* only the pestle moves — the bowl stays put, like real grinding */
.pl-pestle {
  transform-origin: 46% 58%;
  animation: plGrind 1.6s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}

@keyframes plGrind {
  0%, 100% { transform: rotate(-9deg) translate(1px, 1px); }
  50%      { transform: rotate(9deg)  translate(-1px, -2px); }
}

/* Orbiting spice grains */
.pl-orbit {
  position: absolute;
  inset: -10px;
  animation: plSpin 4.5s linear infinite;
}

.pl-orbit-2 {
  inset: 4px;
  animation: plSpin 6.5s linear infinite reverse;
}

.pl-grain {
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  transform-origin: 0 0;
}

.pl-grain.g-turmeric { width: 9px;  height: 9px; background: #facc15; box-shadow: 0 0 12px rgba(250, 204, 21, 0.75); }
.pl-grain.g-chili    { width: 6px;  height: 11px; border-radius: 3px 60% 60% 3px; background: #ea580c; box-shadow: 0 0 10px rgba(234, 88, 12, 0.7); }
.pl-grain.g-cumin    { width: 5px;  height: 12px; background: #c8963e; box-shadow: 0 0 9px rgba(200, 150, 62, 0.6); }
.pl-grain.g-pepper   { width: 7px;  height: 7px;  background: #e7dcc4; box-shadow: 0 0 9px rgba(231, 220, 196, 0.5); }
.pl-grain.g-leaf     { width: 6px;  height: 10px; border-radius: 60% 10% 60% 10%; background: #2ecc71; box-shadow: 0 0 10px rgba(46, 204, 113, 0.5); }

/* Positions around the orbit */
.pl-grain:nth-child(1) { transform: rotate(0deg)   translateX(88px); }
.pl-grain:nth-child(2) { transform: rotate(72deg)  translateX(88px); }
.pl-grain:nth-child(3) { transform: rotate(144deg) translateX(88px); }
.pl-grain:nth-child(4) { transform: rotate(216deg) translateX(88px); }
.pl-grain:nth-child(5) { transform: rotate(288deg) translateX(88px); }

.pl-orbit-2 .pl-grain:nth-child(1) { transform: rotate(36deg)  translateX(64px); }
.pl-orbit-2 .pl-grain:nth-child(2) { transform: rotate(126deg) translateX(64px); }
.pl-orbit-2 .pl-grain:nth-child(3) { transform: rotate(216deg) translateX(64px); }
.pl-orbit-2 .pl-grain:nth-child(4) { transform: rotate(306deg) translateX(64px); }

/* Falling spice dust under the bowl */
.pl-fall {
  position: absolute;
  left: 50%;
  top: 58%;
  width: 46px;
  height: 70px;
  margin-left: -23px;
  overflow: hidden;
  pointer-events: none;
}

.pl-fall span {
  position: absolute;
  top: -8px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gold-400, #eab308);
  opacity: 0;
  animation: plFall 1.8s linear infinite;
}

.pl-fall span:nth-child(1) { left: 8px;  animation-delay: 0s;    background: #facc15; }
.pl-fall span:nth-child(2) { left: 20px; animation-delay: 0.35s; background: #ea580c; }
.pl-fall span:nth-child(3) { left: 31px; animation-delay: 0.7s;  background: #c8963e; }
.pl-fall span:nth-child(4) { left: 14px; animation-delay: 1.05s; background: #e7dcc4; }
.pl-fall span:nth-child(5) { left: 26px; animation-delay: 1.4s;  background: #2ecc71; }

@keyframes plFall {
  0%   { opacity: 0;    transform: translateY(0)    scale(1); }
  18%  { opacity: 0.95; }
  80%  { opacity: 0.5; }
  100% { opacity: 0;    transform: translateY(66px) scale(0.5); }
}

/* ---------- Wordmark ---------- */
.pl-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.pl-brand-name {
  font-family: 'Outfit', 'Plus Jakarta Sans', system-ui, sans-serif;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  margin: 0;
  background: linear-gradient(100deg, #f5e6c8 0%, #d4a34b 38%, #c8963e 62%, #f5e6c8 100%);
  background-size: 230% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation: plShimmer 3.2s linear infinite;
}

@keyframes plShimmer {
  to { background-position: 230% center; }
}

.pl-brand-sub {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  text-transform: uppercase;
  color: rgba(244, 239, 230, 0.55);
}

/* ---------- Progress ---------- */
.pl-bar {
  position: relative;
  width: min(230px, 62vw);
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.pl-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--emerald-500, #229954), var(--gold-500, #d4a34b), var(--spice-600, #ea580c));
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.pl-note {
  margin: 0;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(244, 239, 230, 0.45);
}

/* ---------- Page entrance after the loader lifts ---------- */
.page-enter > header,
.page-enter > .top-bar,
.page-enter > section,
.page-enter > footer {
  animation: pageRise 0.85s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.page-enter > .top-bar  { animation-delay: 0.02s; }
.page-enter > header    { animation-delay: 0.08s; }
.page-enter > section:first-of-type { animation-delay: 0.16s; }

@keyframes pageRise {
  from { opacity: 0; transform: translateY(26px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Hero content staggers in a touch later */
.page-enter .hero-slide.active .hero-content > * {
  animation: heroStagger 0.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.page-enter .hero-slide.active .hero-content > *:nth-child(1) { animation-delay: 0.30s; }
.page-enter .hero-slide.active .hero-content > *:nth-child(2) { animation-delay: 0.40s; }
.page-enter .hero-slide.active .hero-content > *:nth-child(3) { animation-delay: 0.50s; }
.page-enter .hero-slide.active .hero-content > *:nth-child(4) { animation-delay: 0.60s; }
.page-enter .hero-slide.active .hero-content > *:nth-child(5) { animation-delay: 0.70s; }

@keyframes heroStagger {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .spice-preloader *,
  .page-enter > *,
  .page-enter .hero-slide.active .hero-content > * {
    animation: none !important;
    transition: none !important;
  }
  .pl-bar-fill { width: 100% !important; }
}

/* ---------- Leaving the page ---------- */
body.is-leaving {
  animation: pageLeave 0.3s cubic-bezier(0.4, 0, 1, 1) both;
}

@keyframes pageLeave {
  to { opacity: 0.35; transform: translateY(-8px); }
}

@media (prefers-reduced-motion: reduce) {
  body.is-leaving { animation: none !important; }
}
