/* Rig and drill, realistic pass. Loaded last; overrides drill.css and depth.css.
   The borehole is cut into the rock: jagged walls, a crushed rim, the layer showing through,
   cuttings carried up beside the pipe. The pipe is steel with tool joints; the bit is a tricone. */

/* ---------- the rig on the surface ---------- */
.rig {
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .5)); overflow: visible;
  /* the far air softens the top of the mast into the sky behind it */
  -webkit-mask: linear-gradient(to bottom, rgba(0, 0, 0, .5), rgba(0, 0, 0, .85) 35%, #000 60%);
          mask: linear-gradient(to bottom, rgba(0, 0, 0, .5), rgba(0, 0, 0, .85) 35%, #000 60%);
}
/* at the surface the rig holds the string; the bit shows once it is under ground */
.bit { transition: opacity .3s; }
.drill:not(.down) .bit { opacity: 0; }
.rig .beacon { animation: beacon 1.8s steps(1) infinite; }
@keyframes beacon { 50% { opacity: .15; } }

/* ---------- the borehole ---------- */
:root {
  --wall: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='96' viewBox='0 0 44 96' preserveAspectRatio='none'%3E%3Cpath d='M2 0L.5 9 2.6 17 1 26 3.2 34 .8 45 2.3 55 .5 66 2.9 76 1.2 87 2 96H42L43.2 87 41.4 77 43.5 66 41.8 56 43.4 45 40.9 35 43 25 41.6 16 43.5 8 42 0Z'/%3E%3C/svg%3E");
  --rimwall: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='130' viewBox='0 0 56 130' preserveAspectRatio='none'%3E%3Cpath d='M5 0L1 11 4.5 21 .5 33 3.5 44 0 57 4 69 1.5 82 5 93 .8 106 3.8 118 5 130H51L55.2 118 52 106 55.5 94 51.5 82 54.6 70 51 57 55.6 45 52.2 33 55 21 51.4 10 55 0Z'/%3E%3C/svg%3E");
}
.rim {
  position: absolute; top: 0; left: calc(50% - 28px); width: 56px; will-change: transform;
  background:
    radial-gradient(circle, rgba(255, 246, 228, .5) .7px, transparent 1.2px) 0 0 / 7px 9px,
    radial-gradient(circle, rgba(20, 12, 4, .45) .8px, transparent 1.3px) 3px 5px / 9px 11px,
    linear-gradient(to right, rgba(20, 12, 4, .22), rgba(255, 246, 228, .14) 22%, transparent 50%, rgba(255, 246, 228, .14) 78%, rgba(20, 12, 4, .22));
  -webkit-mask: var(--rimwall) 0 0 / 100% 130px repeat-y;
          mask: var(--rimwall) 0 0 / 100% 130px repeat-y;
  opacity: .8;
}
.hole {
  left: calc(50% - 22px); width: 44px;
  background:
    /* the steel casing that lines the top of every well */
    linear-gradient(to bottom, transparent 62px, rgba(0, 0, 0, .55) 62px 64px, transparent 64px) 0 0 / 100% 64px no-repeat,
    linear-gradient(to right, #1A2126, #5B6870 12%, #3A454C 22%, rgba(30, 38, 44, .55) 30% 70%, #3A454C 78%, #5B6870 88%, #1A2126) 0 0 / 100% 64px no-repeat,
    /* marks the bit's cutters left on the wall */
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, .2) 0 1px, transparent 1px 6px, rgba(255, 240, 215, .06) 6px 7px, transparent 7px 11px, rgba(0, 0, 0, .12) 11px 12px, transparent 12px 19px),
    /* round walls: darkest at the edges, the back wall dimly lit */
    linear-gradient(to right, rgba(8, 5, 2, .9), rgba(8, 5, 2, .66) 16%, rgba(8, 5, 2, .44) 50%, rgba(8, 5, 2, .66) 84%, rgba(8, 5, 2, .9));
  box-shadow: none;
  -webkit-mask: var(--wall) 0 0 / 100% 96px repeat-y;
          mask: var(--wall) 0 0 / 100% 96px repeat-y;
}
/* cuttings of the rock being drilled, carried up the gap between pipe and wall */
.hole::before {
  content: ""; position: absolute; inset: 64px 0 0; opacity: 0; transition: opacity .4s;
  background:
    radial-gradient(circle, color-mix(in srgb, var(--chip, #8a6a40) 55%, #fff) .9px, transparent 1.4px) 0 0 / 9px 13px,
    radial-gradient(circle, color-mix(in srgb, var(--chip, #8a6a40) 60%, #000) .8px, transparent 1.3px) 4px 6px / 11px 17px;
}
.drilling .hole::before { opacity: .85; animation: lift .7s linear infinite; }
@keyframes lift { to { background-position: 0 -26px, 4px -28px; } }

/* ---------- the drill pipe ---------- */
.pipe {
  left: calc(50% - 9px); width: 18px; padding: 0 3px; box-sizing: border-box;
  background:
    /* dust of the current layer on the lower pipe */
    linear-gradient(to bottom, transparent calc(100% - 180px), color-mix(in srgb, var(--chip, #8a6a40) 42%, transparent)),
    /* scuffs travel sideways as the pipe turns */
    repeating-linear-gradient(90deg, transparent 0 3px, rgba(255, 255, 255, .12) 3px 4px, transparent 4px 9px, rgba(0, 0, 0, .2) 9px 10px, transparent 10px 17px, rgba(255, 255, 255, .08) 17px 19px, transparent 19px 26px) var(--spin) 0 / 26px 100%,
    linear-gradient(to right, #1C2327, #52606A 16%, #AEB9BF 34%, #F1F5F6 41%, #97A3AA 54%, #4E5A62 80%, #1A2024);
  background-clip: content-box;
  background-origin: content-box;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, .6));
}
/* tool joints every length of pipe; they ride down with the bit */
.pipe::before, .pipe::after { content: ""; position: absolute; inset: 0; }
.pipe::before {
  background: linear-gradient(to right, #20282C, #5E6B73 18%, #C4CDD1 38%, #E9EEF0 44%, #808C93 60%, #3B464D 85%, #1B2226);
  -webkit-mask: linear-gradient(to bottom, transparent 104px, #000 104px 118px, transparent 118px) 0 100% / 100% 120px repeat-y;
          mask: linear-gradient(to bottom, transparent 104px, #000 104px 118px, transparent 118px) 0 100% / 100% 120px repeat-y;
}
.pipe::after {
  background: linear-gradient(to bottom, transparent 104px, rgba(255, 255, 255, .6) 104px 105px, rgba(0, 0, 0, .35) 105px 106px, transparent 106px 110px, rgba(0, 0, 0, .45) 110px 111px, transparent 111px 117px, rgba(0, 0, 0, .6) 117px 118px, transparent 118px) 0 100% / 100% 120px repeat-y;
}

/* ---------- the bit: a tricone, as used for water wells ---------- */
.bit-sub {
  bottom: 46px; left: -11px; width: 22px; height: 30px; border-radius: 1px;
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, .5) 0 1px, transparent 1px 3px, rgba(0, 0, 0, .45) 3px 4px, transparent 4px calc(100% - 4px), rgba(0, 0, 0, .5) calc(100% - 4px) calc(100% - 3px), transparent calc(100% - 3px)),
    linear-gradient(to bottom, transparent 40%, color-mix(in srgb, var(--chip, #8a6a40) 40%, transparent)),
    repeating-linear-gradient(90deg, transparent 0 3px, rgba(255, 255, 255, .12) 3px 4px, transparent 4px 9px, rgba(0, 0, 0, .2) 9px 10px, transparent 10px 17px) var(--spin) 0 / 17px 100%,
    linear-gradient(to right, #20282C, #5B6871 16%, #B9C4C9 36%, #EDF2F3 43%, #8A969D 58%, #3E4950 84%, #1B2226);
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, .55));
}
.bit-head {
  bottom: 0; left: -22px; width: 44px; height: 48px;
  clip-path: none; background: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .55));
}
.bit-head svg { display: block; width: 100%; height: 100%; }
.bit-head .dust { fill: var(--chip, #8a6a40); opacity: .3; mix-blend-mode: multiply; }
.bit-head .row path { stroke-dasharray: .1 2.6; }
.drilling .bit-head .row path { animation: teeth .3s linear infinite; }
.drilling .bit-head .rev path { animation-direction: reverse; }
@keyframes teeth { to { stroke-dashoffset: -2.7; } }
.drilling .bit-head svg { animation: chatter .1s steps(2) infinite; }
@keyframes chatter { 50% { transform: translateX(.4px); } }
.wet .bit-head .dust { opacity: .08; }

/* a cloud of rock dust where the cutters bite */
.chips::before {
  content: ""; position: absolute; left: -34px; top: -26px; width: 68px; height: 34px; border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--chip, #8a6a40) 70%, #fff), transparent);
  opacity: 0; transform: scale(.6); transition: opacity .35s, transform .35s;
}
.drilling .chips::before { opacity: .55; transform: scale(1); }
.chips i { border-radius: 30% 60% 40% 50%; }
.wet .chips::before { opacity: 0; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .rim { left: calc(50% - 15px); width: 30px; }
  .hole { left: calc(50% - 11px); width: 22px; }
  .pipe { left: calc(50% - 5px); width: 10px; padding: 0 2px; }
  .bit-sub { left: -5.5px; width: 11px; height: 16px; bottom: 23px; }
  .bit-head { left: -11px; width: 22px; height: 24px; }
  .chips::before { left: -18px; top: -14px; width: 36px; height: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .rig .beacon, .drilling .hole::before, .drilling .bit-head .row path, .drilling .bit-head svg { animation: none; }
}
