/* ============================================================
   LUXURY PAINT LOADER — شركة أبو يوسف للنقاشة والديكور
   Full-Screen Cinematic Paint & Brush Animation
   Architecture: Canvas reveal via clip-path paint sweeps
   Duration: ~3.8s total → fade → reveal main content
   ============================================================ */

/* ── 0. FONT IMPORT ──────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@300;400;600&family=Almarai:wght@300;400;700&display=swap');

/* ── 1. CUSTOM PROPERTIES ────────────────────────────────── */
:root {
  --loader-bg:        #f8f6f2;
  --loader-paint-1:   #1a1a1a;
  --loader-paint-2:   #2d2d2d;
  --loader-paint-3:   #444444;
  --loader-accent:    #c8b89a;
  --loader-silver:    #d4d0c8;
  --loader-text:      #1a1a1a;
  --loader-muted:     #888880;
  --roller-speed:     1.6s;
  --brush-speed:      1.2s;
  --reveal-delay:     2.4s;
  --total-duration:   3.8s;
}

/* ── 2. ROOT CONTAINER ───────────────────────────────────── */
.loader-container {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #f8f6f2 0%, #fff5e6 50%, #e8f4f8 100%);
  overflow: hidden;
  font-family: 'Almarai', sans-serif;
  pointer-events: all;
  /* Animated paint-like texture */
  background-image:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(255,107,107,.08) 0%, transparent 70%),
    radial-gradient(ellipse 60% 80% at 100% 100%, rgba(78,205,196,.06) 0%, transparent 60%);
}

.loader-container.hidden {
  animation: loaderFadeOut 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  pointer-events: none;
}

@keyframes loaderFadeOut {
  0%   { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.015); visibility: hidden; }
}

/* ── 3. CANVAS WRAPPER ───────────────────────────────────── */
.loader-canvas-wrapper {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* ── 4. PAINT SWEEP PANELS (clip-path wipe reveal) ───────── */
/*
  Three horizontal bands sweep across, simulating a roller
  painting the screen in thick, sequential strokes.
  Each band uses clip-path polygon animation for a smooth wipe.
*/

.paint-sweep {
  position: absolute;
  left: 0;
  right: 0;
  transform-origin: left center;
  will-change: clip-path, opacity;
}

/* Stroke band 1 — top third (Red-Teal-Yellow gradient) */
.sweep-1 {
  top: 0;
  height: 38%;
  background: linear-gradient(
    90deg,
    #FF6B6B 0%,
    #FFD3B6 25%,
    #4ECDC4 50%,
    #95E1D3 75%,
    #FFE66D 100%
  );
  clip-path: polygon(0 0, 0% 0, 0% 100%, 0 100%);
  animation: sweepRight var(--roller-speed) cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.1s forwards;
}

/* Stroke band 2 — middle third (Teal-Pink-Orange gradient) */
.sweep-2 {
  top: 34%;
  height: 36%;
  background: linear-gradient(
    90deg,
    #A8E6CF 0%,
    #FF8B94 33%,
    #FFE66D 66%,
    #FFAAA5 100%
  );
  clip-path: polygon(100% 0, 100% 0, 100% 100%, 100% 100%);
  animation: sweepLeft var(--roller-speed) cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.35s forwards;
}

/* Stroke band 3 — bottom third (Yellow-Teal-Red gradient) */
.sweep-3 {
  bottom: 0;
  height: 38%;
  background: linear-gradient(
    90deg,
    #FFE66D 0%,
    #F4D03F 25%,
    #95E1D3 50%,
    #FF6B6B 75%,
    #FFAAA5 100%
  );
  clip-path: polygon(0 0, 0% 0, 0% 100%, 0 100%);
  animation: sweepRight var(--roller-speed) cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.6s forwards;
}

@keyframes sweepRight {
  0%   { clip-path: polygon(0 0, 0%   0, 0%   100%, 0 100%); }
  100% { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); }
}

@keyframes sweepLeft {
  0%   { clip-path: polygon(100% 0, 100% 0, 100% 100%, 100% 100%); }
  100% { clip-path: polygon(100% 0, 0%   0, 0%   100%, 100% 100%); }
}

/* ── 5. PAINT ROLLER — LEFT → RIGHT ──────────────────────── */
.paint-roller-left {
  position: absolute;
  top: calc(19% - 30px);
  left: -160px;
  width: 130px;
  height: 90px;
  z-index: 20;
  will-change: transform, opacity, filter;
  animation:
    rollerLeftMove var(--roller-speed) cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.1s forwards,
    rollerMotionBlur var(--roller-speed) ease-in-out 0.1s forwards;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.35));
}

@keyframes rollerLeftMove {
  0%   { left: -160px; opacity: 0; }
  5%   { opacity: 1; }
  88%  { left: calc(100% + 60px); opacity: 1; }
  100% { left: calc(100% + 60px); opacity: 0; }
}

/* ── 6. PAINT ROLLER — RIGHT → LEFT ──────────────────────── */
.paint-roller-right {
  position: absolute;
  bottom: calc(19% - 30px);
  right: -160px;
  width: 130px;
  height: 90px;
  z-index: 20;
  will-change: transform, opacity, filter;
  animation:
    rollerRightMove var(--roller-speed) cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.35s forwards,
    rollerMotionBlur var(--roller-speed) ease-in-out 0.35s forwards;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.35));
  transform: scaleX(-1);
}

@keyframes rollerRightMove {
  0%   { right: -160px; opacity: 0; }
  5%   { opacity: 1; }
  88%  { right: calc(100% + 60px); opacity: 1; }
  100% { right: calc(100% + 60px); opacity: 0; }
}

@keyframes rollerMotionBlur {
  0%   { filter: drop-shadow(0 8px 16px rgba(0,0,0,.35)) blur(0px); }
  15%  { filter: drop-shadow(0 4px 8px rgba(0,0,0,.25)) blur(2.5px); }
  80%  { filter: drop-shadow(0 4px 8px rgba(0,0,0,.25)) blur(2px); }
  100% { filter: drop-shadow(0 8px 16px rgba(0,0,0,.35)) blur(0px); }
}

/* ── 7. WET PAINT EDGE GLOSS (behind each roller) ─────────── */
/*
  A thin bright streak follows just behind the roller head,
  simulating the wet sheen of freshly-applied paint.
*/
.paint-gloss-1,
.paint-gloss-2 {
  position: absolute;
  width: 3px;
  opacity: 0;
  z-index: 18;
  will-change: left, right, opacity;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(255,255,255,0.18) 30%,
    rgba(255,255,255,0.28) 50%,
    rgba(255,255,255,0.18) 70%,
    transparent 100%
  );
}

.paint-gloss-1 {
  top: 0;
  height: 38%;
  left: 0;
  animation: glossRight var(--roller-speed) cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.1s forwards;
}

.paint-gloss-2 {
  bottom: 0;
  height: 38%;
  left: 0;
  animation: glossRight var(--roller-speed) cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.6s forwards;
}

@keyframes glossRight {
  0%   { left: 0%;   opacity: 0; }
  5%   { opacity: 1; }
  88%  { left: 99%;  opacity: 0.9; }
  100% { left: 100%; opacity: 0; }
}

/* ── 8. PAINT BRUSH ──────────────────────────────────────── */
.paint-brush {
  position: absolute;
  top: 44%;
  right: -90px;
  width: 70px;
  height: 85px;
  z-index: 22;
  opacity: 0;
  will-change: right, transform, opacity;
  animation: brushArc var(--brush-speed) cubic-bezier(0.34, 1.56, 0.64, 1) 1.55s forwards;
  filter: drop-shadow(2px 6px 12px rgba(0,0,0,0.4));
  transform-origin: 50% 20%;
}

@keyframes brushArc {
  0%   { right: -90px;  opacity: 0; transform: rotate(12deg)  translateY(10px);  }
  18%  {                opacity: 1;                                               }
  45%  { right: 38%;               transform: rotate(-6deg)  translateY(-4px);  }
  72%  { right: 12%;               transform: rotate(4deg)   translateY(2px);   }
  88%  { right: -40px;  opacity: 1; transform: rotate(10deg)  translateY(8px);   }
  100% { right: -90px;  opacity: 0; transform: rotate(14deg)  translateY(12px);  }
}

/* ── 9. PAINT SPLASHES ───────────────────────────────────── */
.paint-splashes {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 25;
}

.splash {
  position: absolute;
  opacity: 0;
}

.splash-1 {
  width: 48px;
  height: 48px;
  top: 27%;
  left: 22%;
  animation: splashBurst 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) 0.75s forwards;
}

.splash-2 {
  width: 32px;
  height: 32px;
  top: 58%;
  right: 18%;
  animation: splashBurst 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) 1.05s forwards;
}

.splash-3 {
  width: 40px;
  height: 40px;
  bottom: 28%;
  left: 13%;
  animation: splashBurst 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.95s forwards;
}

.splash-4 {
  width: 22px;
  height: 22px;
  top: 15%;
  right: 35%;
  animation: splashBurst 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) 1.2s forwards;
}

@keyframes splashBurst {
  0%   { opacity: 0;   transform: scale(0)    rotate(0deg);   }
  40%  { opacity: 0.8; transform: scale(1.3)  rotate(20deg);  }
  70%  { opacity: 0.5; transform: scale(0.95) rotate(-5deg);  }
  100% { opacity: 0;   transform: scale(0.6)  rotate(10deg);  }
}

/* ── 10. PAINT DRIPS (vertical gravity streaks) ──────────── */
.drip {
  position: absolute;
  width: 2px;
  border-radius: 1px;
  top: 0;
  opacity: 0;
  will-change: height, opacity;
  background: linear-gradient(180deg, rgba(26,26,26,0.6) 0%, transparent 100%);
}

.drip-1 {
  left: 32%;
  top: 38%;
  height: 0;
  animation: dripFall 1.1s ease-in 0.8s forwards;
}

.drip-2 {
  left: 68%;
  top: 70%;
  height: 0;
  animation: dripFall 0.9s ease-in 1.1s forwards;
}

.drip-3 {
  left: 50%;
  top: 34%;
  height: 0;
  width: 1.5px;
  animation: dripFall 1.3s ease-in 0.65s forwards;
}

@keyframes dripFall {
  0%   { height: 0;   opacity: 0.9; }
  60%  { height: 60px; opacity: 0.7; }
  100% { height: 80px; opacity: 0;   }
}

/* ── 11. TEXTURE GRAIN OVERLAY ───────────────────────────── */
.texture-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  /* SVG turbulence grain — very subtle paper tooth feel */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.72' numOctaves='4' seed='8' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23g)' opacity='0.04'/%3E%3C/svg%3E");
  background-repeat: repeat;
  animation: grainDrift 12s linear infinite alternate;
  mix-blend-mode: multiply;
}

@keyframes grainDrift {
  0%   { background-position: 0 0; }
  100% { background-position: 80px 60px; }
}

/* ── 12. LOADER BRANDING / CONTENT ───────────────────────── */
.loader-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 40;
  opacity: 0;
  animation: brandReveal 0.8s cubic-bezier(0.16, 1, 0.3, 1) 1.8s forwards;
  pointer-events: none;
}

@keyframes brandReveal {
  0%   { opacity: 0; transform: translateY(16px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* Decorative rule above logo */
.loader-content::before {
  content: '';
  display: block;
  width: 1px;
  height: 0;
  background: rgba(255,255,255,0.5);
  margin-bottom: 2rem;
  animation: lineGrow 0.6s ease-out 2.2s forwards;
}

@keyframes lineGrow {
  0%   { height: 0;    opacity: 0; }
  100% { height: 52px; opacity: 0.45; }
}

.loader-logo {
  font-family: 'Cormorant Garamond', 'Playfair Display', serif;
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  font-weight: 300;
  color: #ffffff;
  letter-spacing: 0.18em;
  text-align: center;
  margin-bottom: 0.4rem;
  line-height: 1.2;
  /* Crisp text on dark painted background */
  text-shadow: 0 1px 12px rgba(0,0,0,0.4);
}

.loader-tagline {
  font-family: 'Almarai', sans-serif;
  font-size: clamp(0.65rem, 1.2vw, 0.78rem);
  font-weight: 300;
  color: rgba(255,255,255,0.62);
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
  margin-bottom: 0;
}

/* ── 13. PROGRESS FILAMENT ───────────────────────────────── */
.loader-progress-track {
  position: absolute;
  bottom: 11%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  opacity: 0;
  animation: brandReveal 0.7s ease-out 2.0s forwards;
}

.loader-progress {
  width: 100px;
  height: 1px;
  background: rgba(255,255,255,0.12);
  position: relative;
  overflow: hidden;
  border-radius: 1px;
}

.loader-progress::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.85), transparent);
  animation: progressShimmer 1.6s ease-in-out 2.1s infinite;
}

@keyframes progressShimmer {
  0%   { left: -100%; opacity: 0.6; }
  50%  { opacity: 1; }
  100% { left: 100%;  opacity: 0.6; }
}

.loader-progress-label {
  font-family: 'Almarai', sans-serif;
  font-size: 0.6rem;
  letter-spacing: 0.35em;
  color: rgba(255,255,255,0.35);
  text-transform: uppercase;
}

/* ── 14. PAINT EFFECTS SVG (injected by JS) ──────────────── */
.paint-effects-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 15;
  opacity: 0.25;
  mix-blend-mode: multiply;
}

/* SVG stroke draw-on animation */
.paint-stroke {
  stroke-dasharray: 1200;
  stroke-dashoffset: 1200;
  animation: strokeDraw 2.8s ease-in-out forwards;
}
.stroke-1 { animation-delay: 0.15s; }
.stroke-2 { animation-delay: 0.4s;  }
.stroke-3 { animation-delay: 0.65s; }
.stroke-4 { animation-delay: 0.9s;  }
.stroke-5 { animation-delay: 1.1s;  }

@keyframes strokeDraw {
  0%   { stroke-dashoffset: 1200; }
  100% { stroke-dashoffset: 0;    }
}

/* SVG splash circles */
.fill-1 { animation: fillPop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) 0.75s forwards; opacity: 0; }
.fill-2 { animation: fillPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 1.0s  forwards; opacity: 0; }
.fill-3 { animation: fillPop 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) 0.9s forwards; opacity: 0; }
.fill-4 { animation: fillPop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) 1.15s forwards; opacity: 0; }

@keyframes fillPop {
  0%   { opacity: 0; transform: scale(0.4);  }
  55%  { opacity: 0.6; transform: scale(1.2); }
  100% { opacity: 0; transform: scale(0.85); }
}

/* ── 15. DARK PAINTED BG REVEAL ──────────────────────────── */
/*
  After the rollers sweep across, the loader-bg transitions
  from light to deep-charcoal so the brand text is legible
  on the "painted" surface.
*/
.loader-container {
  animation: bgDeepen 0.7s ease-out 0.9s forwards;
}

/* Note: we keep the fadeOut animation on .hidden — it overrides */
@keyframes bgDeepen {
  0%   { background: linear-gradient(135deg, #f8f6f2 0%, #fff5e6 50%, #e8f4f8 100%); }
  50%  { background: linear-gradient(135deg, #FF6B6B 0%, #4ECDC4 50%, #FFE66D 100%); }
  100% { background: #141414; }
}

/* ── 16. RESPONSIVE ──────────────────────────────────────── */
@media (max-width: 768px) {
  .paint-roller-left,
  .paint-roller-right {
    width: 90px;
    height: 65px;
  }

  .paint-brush {
    width: 52px;
    height: 64px;
  }

  .loader-logo {
    font-size: 1.35rem;
    letter-spacing: 0.12em;
  }

  .loader-tagline {
    font-size: 0.62rem;
    letter-spacing: 0.22em;
  }

  .loader-content::before {
    margin-bottom: 1.25rem;
  }

  :root {
    --roller-speed: 1.4s;
    --brush-speed: 1.0s;
  }
}

@media (max-width: 480px) {
  .drip-1, .drip-2, .drip-3 { display: none; }

  .splash-3, .splash-4 { display: none; }

  .loader-logo {
    font-size: 1.2rem;
    letter-spacing: 0.08em;
  }
}

/* ── 17. REDUCED MOTION ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay:    0ms  !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .loader-container.hidden {
    display: none;
  }
}

/* ── 18. PRINT ───────────────────────────────────────────── */
@media print {
  .loader-container { display: none !important; }
}
