/*
 * Radhi Waala — page loader
 *
 * A kabadi truck drives in, scrap bales drop onto the roof, and it drives off.
 * One 3.6s timeline (--pl-dur) drives the truck, the wheels, the road dashes
 * and the wind streaks, so they can never drift out of sync with each other.
 *
 *   0 – 30%   truck rolls in, wheels turning, road slides
 *  30 – 64%   truck idles while the bales drop on
 *  64 – 100%  truck drives off
 *
 * public/js/preloader.js holds the overlay for the same 3.6s (so the truck is
 * gone as the page fades in) and adds `is-loaded` to <body> to dismiss it.
 */

:root { --pl-dur: 3.6s; }

.preloader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 45%, #1f5a35 0%, #0f3a22 46%, #07160d 100%);
  /* Fade out, then flip visibility once the fade has finished. */
  transition: opacity .55s ease, visibility 0s linear .55s;
}

body.is-loaded .preloader {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* No scrolling behind the overlay while it's up. */
body:not(.is-loaded) { overflow: hidden; }

.pl-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 20px;
}

/* ── scene ─────────────────────────────────────────────────────────────── */

.pl-scene {
  position: relative;
  width: min(88vw, 460px);
}

.pl-truck {
  width: clamp(200px, 52vw, 290px);
  margin: 0 auto;
  animation: pl-drive var(--pl-dur) both;
}

.pl-bob {
  animation: pl-bob .32s ease-in-out infinite alternate;
}

.pl-svg { display: block; width: 100%; height: auto; overflow: visible; }

.pl-road {
  position: relative;
  height: 10px;
  border-radius: 4px;
  background: linear-gradient(#2c312c, #151815);
  box-shadow: 0 16px 34px -6px rgba(0, 0, 0, .65);
}

.pl-dashes {
  position: absolute;
  left: 0; right: 0; top: 4px;
  height: 2px;
  background: linear-gradient(90deg, #e9e3d0 0 20px, transparent 20px) 0 0 / 46px 100% repeat-x;
  animation: pl-dashes var(--pl-dur) linear both;
}

.pl-wheel {
  transform-box: fill-box;
  transform-origin: center;
  animation: pl-spin var(--pl-dur) linear both;
}

/* Bales wait invisible until the truck has parked, then drop in one by one. */
.pl-bale {
  animation: pl-drop .45s cubic-bezier(.3, 1.4, .5, 1) both;
  animation-delay: calc(var(--pl-dur) * .3 + var(--i) * .14s);
}

.pl-wind i {
  position: absolute;
  height: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .38);
  opacity: 0;
  animation: pl-wind var(--pl-dur) linear both;
}
.pl-wind i:nth-child(1) { left: 6%;  top: 22%; width: 56px; }
.pl-wind i:nth-child(2) { left: 14%; top: 46%; width: 88px; animation-delay: .08s; }
.pl-wind i:nth-child(3) { left: 3%;  top: 68%; width: 64px; animation-delay: .16s; }

/* ── wordmark ──────────────────────────────────────────────────────────── */

.pl-brand {
  margin-top: 34px;
  font-family: 'Caveat', cursive;
  font-size: 40px;
  line-height: 1;
  color: #f4ede0;
  animation: pl-rise .7s ease .5s both;
}
.pl-brand span { color: #4ade80; }

.pl-tag {
  margin-top: 9px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(244, 237, 224, .55);
  animation: pl-rise .7s ease .8s both;
}

/* ── keyframes ─────────────────────────────────────────────────────────── */

@keyframes pl-drive {
  0%   { transform: translateX(-85vw); animation-timing-function: cubic-bezier(.2, .7, .3, 1); }
  30%  { transform: translateX(0);     animation-timing-function: linear; }
  64%  { transform: translateX(0);     animation-timing-function: cubic-bezier(.55, 0, .9, .5); }
  100% { transform: translateX(95vw); }
}

@keyframes pl-spin {
  0%   { transform: rotate(0); }
  30%  { transform: rotate(720deg); }
  64%  { transform: rotate(720deg); }
  100% { transform: rotate(1560deg); }
}

@keyframes pl-dashes {
  0%   { background-position: 0 0; }
  30%  { background-position: -460px 0; }
  64%  { background-position: -460px 0; }
  100% { background-position: -1100px 0; }
}

/* Presses down into the road rather than lifting off it, so the wheels
   never visibly float. The road paints over the bottom pixel. */
@keyframes pl-bob {
  from { transform: translateY(0); }
  to   { transform: translateY(1px); }
}

@keyframes pl-drop {
  from { opacity: 0; transform: translateY(-46px); }
  to   { opacity: 1; transform: none; }
}

@keyframes pl-wind {
  0%   { opacity: 0; transform: translateX(0); }
  6%   { opacity: 1; }
  28%  { opacity: 1; transform: translateX(-64px); }
  32%  { opacity: 0; }
  64%  { opacity: 0; transform: translateX(0); }
  70%  { opacity: 1; }
  96%  { opacity: 1; transform: translateX(-64px); }
  100% { opacity: 0; }
}

@keyframes pl-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* Reduced motion: a still truck, loaded, with the wordmark. No travel, no spin. */
@media (prefers-reduced-motion: reduce) {
  .pl-truck, .pl-bob, .pl-wheel, .pl-dashes, .pl-wind i, .pl-bale { animation: none; }
  .pl-wind { display: none; }
}

@media (max-width: 560px) {
  .pl-brand { font-size: 34px; margin-top: 28px; }
}
