/* =====================================================================
   3D SCROLL EXPERIENCE
   Pinned "magic edit" stage + scroll-driven 3D reveals site-wide.
   ===================================================================== */

/* The old carousel is replaced by the stage (kept in DOM for main.js) */
.carousel { display: none !important; }

.magic {
  position: relative;
  height: 460vh;
  background: #07120b;
  color: #fff;
}

.magic-sticky {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  perspective: 1400px;
  perspective-origin: 50% 40%;
}

/* Ambient glowing orbs, parallaxed by JS via --p */
.magic-bg { position: absolute; inset: 0; pointer-events: none; }
.magic-bg span {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .55;
  will-change: transform;
}
.magic-bg span:nth-child(1) { width: 46vmax; height: 46vmax; left: -12vmax; top: -10vmax; background: #148a2c; }
.magic-bg span:nth-child(2) { width: 38vmax; height: 38vmax; right: -10vmax; top: 20vh; background: #0d5a7a; }
.magic-bg span:nth-child(3) { width: 30vmax; height: 30vmax; left: 30vw; bottom: -14vmax; background: #6c3bb5; opacity: .35; }

/* Fine grid floor for depth */
.magic-grid {
  position: absolute;
  left: -50%; right: -50%;
  bottom: -30vh;
  height: 80vh;
  background-image:
    linear-gradient(rgba(255,255,255,.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.07) 1px, transparent 1px);
  background-size: 60px 60px;
  transform: rotateX(72deg);
  transform-origin: top center;
  mask-image: linear-gradient(to top, #000 10%, transparent 85%);
  -webkit-mask-image: linear-gradient(to top, #000 10%, transparent 85%);
  pointer-events: none;
}

/* Intro title that dissolves as editing begins */
.magic-intro {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 20px;
  z-index: 5;
  pointer-events: none;
  will-change: transform, opacity, filter;
}
.magic-eyebrow {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: #8fe3a2;
  margin-bottom: 18px;
}
.magic-intro h2 {
  color: #fff;
  font-size: clamp(2.4rem, 7vw, 6rem);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.03em;
}
.magic-intro h2 em {
  font-style: normal;
  background: linear-gradient(90deg, #8fe3a2, #5cc8ff, #c6a3ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.magic-scroll-hint {
  margin-top: 36px;
  font-size: .85rem;
  color: rgba(255,255,255,.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.magic-scroll-hint i {
  width: 22px; height: 36px;
  border: 2px solid rgba(255,255,255,.5);
  border-radius: 12px;
  position: relative;
}
.magic-scroll-hint i::after {
  content: '';
  position: absolute;
  left: 50%; top: 6px;
  width: 4px; height: 8px;
  margin-left: -2px;
  border-radius: 2px;
  background: #fff;
  animation: magicWheel 1.6s ease-in-out infinite;
}
@keyframes magicWheel { 0% { opacity: 0; transform: translateY(0); } 40% { opacity: 1; } 100% { opacity: 0; transform: translateY(12px); } }

/* 3D scene */
.magic-scene {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6vw;
  transform-style: preserve-3d;
}

.magic-rig {
  position: absolute;
  right: 6vw;
  top: 50%;
  width: min(58vw, 820px);
  aspect-ratio: 16 / 10;
  margin-top: calc(min(58vw, 820px) * -0.3125);
  transform-style: preserve-3d;
  opacity: 0;
  will-change: transform, opacity;
}
.magic-frame {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  overflow: hidden;
  background: #111;
  box-shadow: 0 50px 120px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.08);
}
.magic-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}
/* "Raw" look: flat, dull, soft, noisy */
.m-raw { filter: grayscale(.75) sepia(.25) contrast(.75) brightness(.8) blur(2.5px); transform: scale(1.04); }
.m-noise {
  position: absolute;
  inset: 0;
  opacity: .35;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}
/* "Edited" layer revealed by a clip wipe */
.m-clean { clip-path: inset(0 100% 0 0); filter: saturate(1.12) contrast(1.05); }

/* The magic scan beam */
.m-scan {
  position: absolute;
  top: -5%;
  bottom: -5%;
  left: 0;
  width: 3px;
  background: #fff;
  box-shadow: 0 0 12px #fff, 0 0 30px #8fe3a2, 0 0 60px #5cc8ff;
  opacity: 0;
  z-index: 3;
}
.m-scan::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  right: 3px;
  width: 120px;
  background: linear-gradient(90deg, transparent, rgba(143,227,162,.22));
}
.m-scan::after {
  content: '\2726';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 42px; height: 42px;
  border-radius: 50%;
  background: #fff;
  color: #0b6b1a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  box-shadow: 0 0 30px rgba(143,227,162,.9);
}

.m-badge {
  position: absolute;
  top: 16px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  z-index: 4;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.m-badge.before { left: 16px; background: rgba(0,0,0,.55); color: #fff; }
.m-badge.after { right: 16px; background: rgba(255,255,255,.9); color: #0b6b1a; opacity: 0; }

/* Floating 3D "edit applied" chips */
.m-chips { position: absolute; inset: 0; transform-style: preserve-3d; pointer-events: none; z-index: 6; }
.m-chip {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(255,255,255,.96);
  color: #16211a;
  font-size: .85rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 18px 40px rgba(0,0,0,.35);
  opacity: 0;
  will-change: transform, opacity;
}
.m-chip.c1 { top: 10%; left: -7%; }
.m-chip.c2 { top: 44%; right: -8%; }
.m-chip.c3 { bottom: 9%; left: 10%; }
@media (max-width: 900px) {
  .m-chip.c1 { left: 4%; top: 16%; }
  .m-chip.c2 { right: 4%; }
  .m-chip.c3 { left: 6%; bottom: 6%; }
}
.m-chip b {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #0b6b1a;
  color: #fff;
  font-size: .7rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Left-hand copy for each scene */
.magic-copy {
  position: absolute;
  left: 6vw;
  top: 50%;
  width: min(30vw, 420px);
  transform: translateY(-50%);
  z-index: 7;
}
.magic-step {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  opacity: 0;
  will-change: transform, opacity;
}
.magic-step .num {
  display: inline-block;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .2em;
  color: #8fe3a2;
  margin-bottom: 12px;
}
.magic-step h3 {
  color: #fff;
  font-size: clamp(1.8rem, 3.4vw, 3rem);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin-bottom: 14px;
}
.magic-step p { color: rgba(255,255,255,.72); font-size: 1.02rem; }
.magic-step .magic-cta {
  margin-top: 24px;
  display: inline-flex;
  gap: 10px;
  flex-wrap: wrap;
  pointer-events: auto;
}
.magic-step .magic-cta button { padding: 13px 26px; border-radius: 999px; font-weight: 600; font-size: .95rem; cursor: pointer; }
.magic-step .magic-cta .btn-quote { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); }
.magic-step .magic-cta .btn-quote:hover { background: #fff; color: #0b6b1a; }

/* Progress rail */
.magic-progress {
  position: absolute;
  left: 50%;
  bottom: 28px;
  width: min(280px, 60vw);
  height: 3px;
  margin-left: calc(min(280px, 60vw) / -2);
  background: rgba(255,255,255,.15);
  border-radius: 3px;
  overflow: hidden;
  z-index: 8;
}
.magic-progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #8fe3a2, #5cc8ff); }

/* ---------- Scroll reveals for the rest of the site ---------- */
.r3d {
  opacity: 0;
  transform: perspective(1000px) translate3d(0, 60px, -80px) rotateX(14deg);
  transform-origin: 50% 100%;
  transition: opacity .9s cubic-bezier(.2,.7,.2,1), transform .9s cubic-bezier(.2,.7,.2,1);
  transition-delay: var(--d, 0s);
}
.r3d.in { opacity: 1; transform: none; }

/* Services detail images float in 3D with scroll (driven by --t from JS) */
.image-column { perspective: 1200px; }
.image-column img {
  transform: rotateY(calc(var(--t, 0) * 14deg)) rotateX(calc(var(--t, 0) * -6deg)) translateZ(calc((1 - var(--a, 0)) * -60px));
  transition: transform .1s linear, box-shadow .3s ease;
  will-change: transform;
}
.photo-editing-container:nth-of-type(even) .image-column img {
  transform: rotateY(calc(var(--t, 0) * -14deg)) rotateX(calc(var(--t, 0) * -6deg)) translateZ(calc((1 - var(--a, 0)) * -60px));
}

/* Sample posters (tall 8:15) in the stage */
.magic-rig.poster {
  height: 86vh;
  width: calc(86vh * 8 / 15);
  aspect-ratio: auto;
  top: 7vh;
  margin-top: 0;
  right: 14vw;
}
.magic-rig.poster .magic-frame { border-radius: 16px; }
.magic-rig.poster .m-chip.c1 { left: -30%; }
.magic-rig.poster .m-chip.c2 { right: -34%; }
.magic-rig.poster .m-chip.c3 { left: -24%; }
@media (max-width: 900px) {
  .magic-rig.poster {
    height: 62vh;
    width: calc(62vh * 8 / 15);
    top: 6vh;
    left: 50%;
    right: auto;
    margin-left: calc(62vh * -4 / 15);
  }
  .magic-rig.poster .m-chip.c1 { left: -18%; }
  .magic-rig.poster .m-chip.c2 { right: -18%; }
  .magic-rig.poster .m-chip.c3 { left: -10%; }
  .magic-copy { bottom: 28px; }
}

/* Before → after → review scenes */
.magic-rig.pair {
  width: min(52vw, 760px);
  aspect-ratio: 4 / 3;
  margin-top: calc(min(52vw, 760px) * -0.375 - 6vh);
  right: 8vw;
}
.magic-rig.pair .m-raw {
  object-fit: contain;
  filter: none;
  transform: none;
  background: #0b0f0c;
}
/* Show the whole result — never crop heads */
.magic-rig.pair .m-clean { object-fit: contain; background: #0b0f0c; }
/* Labels sit along the bottom edge (bodies/floor), never over faces */
.magic-rig.pair .m-chip.c1,
.magic-rig.pair .m-chip.c2 { top: auto; bottom: 26%; }
.magic-rig.pair .m-chip.c1 { left: 3%; right: auto; }
.magic-rig.pair .m-chip.c2 { right: 3%; left: auto; }
.m-review {
  position: absolute;
  left: 50%;
  bottom: -22%;
  width: 78%;
  margin-left: -39%;
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 255, 255, .1);
  opacity: 0;
  z-index: 7;
  will-change: transform, opacity;
}
.m-review img { display: block; width: 100%; height: auto; }
@media (max-width: 900px) {
  .magic-rig.pair {
    width: 92vw;
    left: 4vw;
    right: auto;
    margin-left: 0;
    top: 34%;
    margin-top: -34.5vw;
  }
  .magic-rig.pair .m-chip { font-size: .68rem; padding: 6px 10px; gap: 6px; }
  .magic-rig.pair .m-chip b { width: 16px; height: 16px; font-size: .6rem; }
  .magic-rig.pair .m-chip.c1,
  .magic-rig.pair .m-chip.c2 { top: auto; bottom: 28%; }
  .magic-rig.pair .m-chip.c1 { left: 2%; }
  .magic-rig.pair .m-chip.c2 { right: 2%; }
  .m-review { width: 92%; margin-left: -46%; bottom: -24%; }
}

/* Examples gallery: tall before/after posters, shown whole */
.gallery-panel {
  height: auto !important;
  min-height: 0;
  overflow: visible !important;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)) !important;
  align-items: start;
}
.gallery-panel img {
  height: auto !important;
  max-width: 100% !important;
  margin: 0 !important;
  object-fit: contain !important;
}
@media (max-width: 600px) {
  .gallery-panel { grid-template-columns: repeat(2, 1fr) !important; }
}

/* Hover tilt cards */
.tilt { transform-style: preserve-3d; transition: transform .25s ease, box-shadow .25s ease; }
.tilt:hover { box-shadow: 0 24px 50px rgba(16, 33, 22, .16); }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .magic { height: 400vh; }
  .magic-sticky { perspective: 900px; }
  .magic-rig {
    left: 50%;
    right: auto;
    top: 44%;
    width: 88vw;
    aspect-ratio: 4 / 5;
    margin-left: -44vw;
    margin-top: -55vw;
  }
  .magic-frame { border-radius: 18px; }
  .magic-copy {
    left: 6vw;
    right: 6vw;
    width: auto;
    top: auto;
    bottom: 64px;
    transform: none;
    text-align: center;
  }
  .magic-step { top: auto; bottom: 0; transform: none; }
  .magic-step h3 { font-size: 1.6rem; margin-bottom: 6px; }
  .magic-step p { font-size: .9rem; }
  .magic-step .num { margin-bottom: 6px; }
  .magic-step .magic-cta { justify-content: center; margin-top: 14px; }
  .magic-step .magic-cta button { padding: 11px 20px; font-size: .88rem; }
  .m-chip { font-size: .75rem; padding: 8px 12px; }
  .m-scan::after { width: 34px; height: 34px; font-size: .9rem; }
}

@media (prefers-reduced-motion: reduce) {
  .magic { height: auto; }
  .magic-sticky { position: relative; height: auto; min-height: 100vh; }
  .r3d { opacity: 1; transform: none; }
  .image-column img { transform: none !important; }
}
