/* ============================================
   THE DRILL — scroll-driven animation  (v2, enhanced realism)
   ============================================
   The rig lives inside a 320 x H container.
   All horizontal coordinates anchor the bit centre at x = 160.

   JS-driven custom properties:
     --drill-y        descent of head+barrel in px (0..MAX)
     --shaft-h        spindle length, grows with descent
     --hole-h         bored cavity depth
     --hole-rim-op    rim/lip opacity (0/1)
     --effects-op     master effects opacity (0/1)
     --cut-intensity  0..1, how hard it's cutting (from scroll velocity)
   ============================================ */

.rig {
  position: relative;
  width: 320px;
  height: 100%;
  --cut-intensity: 0.35;          /* idle simmer by default */
}

/* --- BASE PLATE (top, anchored) --- */
.rig-base {
  position: absolute;
  top: 0; left: 0;
  width: 320px;
  height: 96px;
  z-index: 6;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.5));
}
.rig-base svg { width: 100%; height: 100%; }

/* --- COLUMN: vertical rail with rack teeth --- */
.rig-column {
  position: absolute;
  top: 60px;
  left: 154px;            /* width 12, centre at 160 */
  width: 12px;
  height: calc(100% - 60px);
  background:
    linear-gradient(90deg,
      var(--silver-700) 0%,
      var(--silver-300) 30%,
      var(--silver-100) 50%,
      var(--silver-300) 70%,
      var(--silver-700) 100%);
  border-left: 1px solid var(--bg-deep);
  border-right: 1px solid var(--bg-deep);
  box-shadow: 0 0 8px rgba(0,0,0,0.4);
  z-index: 4;
}
.rig-column::before {
  content: '';
  position: absolute;
  left: 3px; top: 0; bottom: 0; width: 6px;
  background-image: repeating-linear-gradient(
    180deg,
    var(--bg-deep) 0,
    var(--bg-deep) 2px,
    var(--silver-500) 2px,
    var(--silver-500) 6px);
}

/* --- DRILL HEAD: motor + carriage. Rides DOWN the column. --- */
.rig-head {
  position: absolute;
  top: 60px;
  left: 0;
  width: 320px;
  height: 160px;
  z-index: 7;
  transform: translate3d(0, var(--drill-y, 0px), 0);
  will-change: transform;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.45));
}
.rig-head svg { width: 100%; height: 100%; }

/* motor vibration — amplitude scales with cut intensity */
.rig-head-vibrate {
  animation: motorVibrate 0.05s linear infinite;
}
@keyframes motorVibrate {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(calc(-0.6px * var(--cut-intensity, 0.35)), calc(0.6px * var(--cut-intensity, 0.35))); }
  50% { transform: translate(calc(0.4px * var(--cut-intensity, 0.35)), calc(-0.3px * var(--cut-intensity, 0.35))); }
  75% { transform: translate(calc(0.6px * var(--cut-intensity, 0.35)), calc(-0.6px * var(--cut-intensity, 0.35))); }
}

/* --- SHAFT: spindle connecting head to barrel --- */
.rig-shaft {
  position: absolute;
  top: 220px;
  left: 157px;            /* width 6, centre at 160 */
  width: 6px;
  background: linear-gradient(90deg,
    var(--silver-700),
    var(--silver-200) 40%,
    var(--silver-100) 50%,
    var(--silver-200) 60%,
    var(--silver-700));
  z-index: 5;
  transform: translate3d(0, var(--drill-y, 0px), 0);
  height: var(--shaft-h, 70px);
  will-change: transform;
}
.rig-shaft::before {
  content: '';
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(
    180deg,
    transparent 0,
    transparent 6px,
    rgba(0,0,0,0.18) 6px,
    rgba(0,0,0,0.18) 7px);
  animation: shaftSpin 0.14s linear infinite;
}
@keyframes shaftSpin {
  0% { background-position: 0 0; }
  100% { background-position: 0 7px; }
}

/* --- CORE BARREL: the cutting bit cylinder --- */
.rig-barrel {
  position: absolute;
  top: 220px;
  left: 142px;            /* width 36, centre at 160 */
  width: 36px;
  height: 160px;
  z-index: 8;
  transform: translate3d(0, var(--drill-y, 0px), 0);
  will-change: transform;
}
.rig-barrel-svg {
  width: 100%; height: 100%;
  animation: barrelSpin 0.1s linear infinite;
}
@keyframes barrelSpin {
  0%, 100% { transform: scaleX(1); filter: brightness(1) saturate(1); }
  50% { transform: scaleX(0.9); filter: brightness(1.22) saturate(1.1); }
}
/* sweeping specular glint that sells the rotation */
.rig-barrel::after {
  content: '';
  position: absolute;
  top: 8px; bottom: 18px;
  left: 6px; width: 8px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.55), transparent);
  filter: blur(1px);
  animation: barrelGlint 0.5s linear infinite;
  pointer-events: none;
}
@keyframes barrelGlint {
  0% { transform: translateX(-4px); opacity: 0; }
  40% { opacity: 0.9; }
  100% { transform: translateX(22px); opacity: 0; }
}

/* --- CUTTING GLOW: friction halo at the contact point --- */
.rig-glow {
  position: absolute;
  left: 130px;
  width: 60px;
  height: 40px;
  top: calc(360px + var(--drill-y, 0px));
  border-radius: 50%;
  background: radial-gradient(ellipse at center,
    rgba(120, 200, 255, 0.55) 0%,
    rgba(30, 159, 255, 0.28) 40%,
    transparent 72%);
  filter: blur(6px);
  z-index: 8;
  pointer-events: none;
  opacity: calc(var(--effects-op, 0) * (0.45 + 0.55 * var(--cut-intensity, 0.35)));
  animation: glowPulse 0.45s ease-in-out infinite;
}
@keyframes glowPulse {
  0%, 100% { transform: scale(0.92); }
  50% { transform: scale(1.12); }
}

/* --- HOLE: bored cavity, centred under bit, grows with descent --- */
.rig-hole-wrap {
  position: absolute;
  top: 380px;
  left: 142px;
  width: 36px;
  height: var(--hole-h, 0px);
  z-index: 3;
  pointer-events: none;
}
.rig-hole {
  position: relative;
  width: 100%; height: 100%;
  background:
    linear-gradient(90deg,
      rgba(0,0,0,0.97) 0%,
      rgba(0,0,0,0.6) 14%,
      rgba(10,16,32,0.32) 50%,
      rgba(0,0,0,0.6) 86%,
      rgba(0,0,0,0.97) 100%);
  box-shadow:
    inset 0 6px 14px rgba(0,0,0,0.95),
    inset 4px 0 8px rgba(0,0,0,0.75),
    inset -4px 0 8px rgba(0,0,0,0.75);
}
/* faint blue-tinted wet streaks running down the bore wall */
.rig-hole::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(90deg, transparent 24%, rgba(120,180,230,0.10) 25%, transparent 27%),
    linear-gradient(90deg, transparent 62%, rgba(120,180,230,0.08) 63%, transparent 65%);
}
/* elliptical lip of the bore — perspective rim with a wet highlight */
.rig-hole-rim {
  position: absolute;
  top: 374px;
  left: 130px;
  width: 60px;
  height: 16px;
  z-index: 9;
  pointer-events: none;
  opacity: var(--hole-rim-op, 0);
}
.rig-hole-rim::before {        /* dark inner mouth */
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, #000 34%, rgba(0,0,0,0.55) 58%, transparent 74%);
  filter: blur(1.5px);
}
.rig-hole-rim::after {         /* wet specular crescent on the lip */
  content: '';
  position: absolute;
  left: 8px; right: 8px; top: 1px; height: 5px;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(150,205,255,0.55), transparent);
  filter: blur(0.6px);
}

/* --- SLURRY POOL: wet grey-blue mix collecting at the lip --- */
.rig-slurry {
  position: absolute;
  left: 122px;
  width: 76px;
  height: 22px;
  top: calc(378px + var(--drill-y, 0px));
  z-index: 7;
  pointer-events: none;
  opacity: var(--effects-op, 0);
}
.rig-slurry::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%,
    rgba(150,170,190,0.55) 0%,
    rgba(90,120,150,0.4) 45%,
    transparent 72%);
  filter: blur(2px);
  animation: slurryShimmer 1.6s ease-in-out infinite;
}
@keyframes slurryShimmer {
  0%, 100% { transform: scale(1) translateY(0); opacity: 0.85; }
  50% { transform: scale(1.06) translateY(0.5px); opacity: 1; }
}

/* --- DUST: layered volumetric puffs at the cutting tip --- */
.rig-dust {
  position: absolute;
  left: 104px;
  width: 112px;
  height: 84px;
  top: calc(356px + var(--drill-y, 0px));
  z-index: 9;
  pointer-events: none;
  opacity: calc(var(--effects-op, 0) * (0.5 + 0.5 * var(--cut-intensity, 0.35)));
}
.rig-dust span {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(190, 205, 225, 0.55), transparent 66%);
  filter: blur(8px);
}
.rig-dust span:nth-child(1) { left: 18px; top: 28px; width: 64px; height: 48px; animation: dustPuff 1.7s ease-in-out infinite; }
.rig-dust span:nth-child(2) { left: 40px; top: 20px; width: 52px; height: 40px; animation: dustPuff 2.1s ease-in-out 0.4s infinite; }
.rig-dust span:nth-child(3) { left: 8px;  top: 36px; width: 44px; height: 34px; animation: dustDrift 2.6s ease-in-out 0.2s infinite; }
@keyframes dustPuff {
  0%, 100% { transform: scale(0.85) translateY(0); opacity: 0.4; }
  50% { transform: scale(1.25) translateY(-6px); opacity: 0.85; }
}
@keyframes dustDrift {
  0% { transform: translate(0,0) scale(0.8); opacity: 0; }
  40% { opacity: 0.6; }
  100% { transform: translate(-22px,-30px) scale(1.4); opacity: 0; }
}

/* --- WATER SPRAY: fine droplets fanning off the wet bit --- */
.rig-droplets {
  position: absolute;
  left: 158px;
  top: calc(378px + var(--drill-y, 0px));
  width: 4px; height: 4px;
  z-index: 10;
  pointer-events: none;
  opacity: var(--effects-op, 0);
}
.rig-droplet {
  position: absolute;
  inset: 0;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: rgba(160, 210, 255, 0.9);
  box-shadow: 0 0 5px rgba(30, 159, 255, 0.8);
  animation: dropletFly 0.7s ease-out infinite;
}
.rig-droplet:nth-child(1) { --dx: 52px;  --dy: 30px; animation-delay: 0s; }
.rig-droplet:nth-child(2) { --dx: -40px; --dy: 38px; animation-delay: 0.12s; }
.rig-droplet:nth-child(3) { --dx: 60px;  --dy: 14px; animation-delay: 0.24s; }
.rig-droplet:nth-child(4) { --dx: -52px; --dy: 24px; animation-delay: 0.36s; }
.rig-droplet:nth-child(5) { --dx: 30px;  --dy: 50px; animation-delay: 0.48s; }
.rig-droplet:nth-child(6) { --dx: -30px; --dy: 54px; animation-delay: 0.6s; }
.rig-droplet:nth-child(7) { --dx: 44px;  --dy: 44px; animation-delay: 0.18s; }
.rig-droplet:nth-child(8) { --dx: -20px; --dy: 46px; animation-delay: 0.54s; }
@keyframes dropletFly {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.5); opacity: 0; }
}

/* --- SPARKS: occasional bright flecks when biting rebar/aggregate --- */
.rig-sparks {
  position: absolute;
  left: 158px;
  top: calc(380px + var(--drill-y, 0px));
  width: 4px; height: 4px;
  z-index: 11;
  pointer-events: none;
  opacity: calc(var(--effects-op, 0) * var(--cut-intensity, 0.35));
}
.rig-spark {
  position: absolute;
  inset: 0;
  width: 2px; height: 2px;
  border-radius: 50%;
  background: #eaf4ff;
  box-shadow: 0 0 6px 1px rgba(140, 200, 255, 0.95);
  animation: sparkFly 0.5s ease-out infinite;
}
.rig-spark:nth-child(1) { --sx: 40px;  --sy: -14px; animation-delay: 0s; }
.rig-spark:nth-child(2) { --sx: -34px; --sy: -10px; animation-delay: 0.9s; }
.rig-spark:nth-child(3) { --sx: 26px;  --sy: -22px; animation-delay: 1.7s; }
.rig-spark:nth-child(4) { --sx: -22px; --sy: -18px; animation-delay: 2.4s; }
@keyframes sparkFly {
  0% { transform: translate(0,0) scale(1.2); opacity: 1; }
  100% { transform: translate(var(--sx), var(--sy)) scale(0); opacity: 0; }
}

/* --- CONCRETE CHUNKS: spoil thrown from the cut, gravity arcs --- */
.rig-chunks {
  position: absolute;
  left: 158px;
  top: calc(378px + var(--drill-y, 0px));
  width: 4px; height: 4px;
  z-index: 10;
  pointer-events: none;
  opacity: calc(var(--effects-op, 0) * (0.55 + 0.45 * var(--cut-intensity, 0.35)));
}
.rig-chunk {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--silver-300), var(--silver-700));
  border: 0.5px solid var(--bg-deep);
  animation: chunkFall 1.5s cubic-bezier(.3,.1,.7,1) infinite;
}
.rig-chunk:nth-child(1) { width: 7px; height: 5px; clip-path: polygon(0 30%, 50% 0, 100% 40%, 80% 100%, 20% 90%); --cx: 66px;  --cy: 120px; --rot: 540deg;  animation-delay: 0s; }
.rig-chunk:nth-child(2) { width: 5px; height: 4px; clip-path: polygon(20% 0, 100% 30%, 80% 100%, 0 80%);        --cx: -58px; --cy: 108px; --rot: -480deg; animation-delay: 0.4s; }
.rig-chunk:nth-child(3) { width: 8px; height: 6px; clip-path: polygon(10% 20%, 80% 0, 100% 60%, 60% 100%, 0 70%); --cx: 74px;  --cy: 138px; --rot: 720deg;  animation-delay: 0.7s; }
.rig-chunk:nth-child(4) { width: 6px; height: 5px; clip-path: polygon(0 50%, 50% 0, 100% 40%, 80% 100%);         --cx: -50px; --cy: 124px; --rot: -540deg; animation-delay: 1s; }
.rig-chunk:nth-child(5) { width: 5px; height: 4px; clip-path: polygon(30% 0, 100% 40%, 70% 100%, 0 80%);         --cx: 52px;  --cy: 100px; --rot: 420deg;  animation-delay: 0.2s; }
.rig-chunk:nth-child(6) { width: 6px; height: 4px; clip-path: polygon(0 30%, 70% 0, 100% 50%, 80% 100%, 30% 90%); --cx: -66px; --cy: 128px; --rot: -360deg; animation-delay: 0.55s; }
@keyframes chunkFall {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translate(var(--cx), var(--cy)) rotate(var(--rot)); opacity: 0; }
}

/* --- SPOIL PILE: a little debris settling under the hole --- */
.rig-spoil {
  position: absolute;
  left: 120px;
  width: 80px;
  height: 14px;
  top: calc(396px + var(--drill-y, 0px));
  z-index: 6;
  pointer-events: none;
  opacity: var(--effects-op, 0);
  background:
    radial-gradient(ellipse at 40% 60%, var(--silver-600) 0%, transparent 60%),
    radial-gradient(ellipse at 62% 70%, var(--silver-700) 0%, transparent 58%);
  filter: blur(1px);
}

/* respect reduced motion — freeze the spinning bits, keep it legible */
@media (prefers-reduced-motion: reduce) {
  .rig-head-vibrate,
  .rig-barrel-svg,
  .rig-barrel::after,
  .rig-shaft::before,
  .rig-glow,
  .rig-dust span,
  .rig-droplet,
  .rig-spark,
  .rig-chunk,
  .rig-slurry::before {
    animation: none !important;
  }
}
