/* The N coupling and the cable outlet are measured from the tray by meter-journey.js.
   Size the tray with room for both fittings; keep the housing itself on centre. */
#scene {
  --bench-width: var(--bench-module-width, min(65vw, 1110px, 104svh));
  --bench-centre: var(--bench-module-center, 53%);
}

#scene .assembly,
#scene .assembly.has-cable-plug {
  --module-width: var(--bench-width);
  width: var(--module-width);
  left: 50%;
  margin-left: calc(var(--module-width) / -2);
  top: calc(var(--bench-centre) - var(--module-width) / 4);
}

/* A low softbox reflected in silver, with a thin contact shadow at its mating seam.
   Keep each light on its own physical surface so it follows the opening movement. */
#scene .assembly::before {
  left: 8%;
  right: 7%;
  top: 88%;
  height: 13%;
  background: radial-gradient(ellipse, #000c 8%, #01040a94 52%, transparent 74%);
  filter: blur(clamp(4px, .8vw, 14px));
}

#scene .lid-front {
  border-color: #e4ecf0;
  background: linear-gradient(114deg, #99a8af, #f8fbfc 16%, #a8b2ba 48%, #e3e9eb 74%, #7d8d9b);
  box-shadow:
    inset 0 1px 0 #ffffffd4,
    inset 1px 0 1px #f7fcff8c,
    inset -1px -1px 0 #7c8b97,
    0 1px 0 #d5dfe6,
    0 2px 0 #728698,
    0 3px 2px #1d2b3594;
}

#scene .cover-grain::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 22% 6%, #f5fcff45, transparent 57%),
    linear-gradient(112deg, #18324720, transparent 20%, #f7fbff12 39%,
      transparent 60%, #25456621 86%, #bcd6e71c);
}

#scene .lid-fastener {
  background: radial-gradient(circle, #354755 0 31%, #62707b 35%, #dde3e7 54%,
    #697883 64%, #dbe6ed 72%, transparent 77%);
  box-shadow: 0 .65px 1px #10253375;
}

#scene .bolt-head {
  border-color: #8f9ca7;
  background: conic-gradient(from -24deg, #e7eff2, #8c9aa4 20%, #d6dfe6 42%,
    #f7fafc 53%, #8f9ca4 79%, #e7eff2);
}

#scene .plate-text {
  color: #182f40;
  text-shadow: 0 1px #f9fdff69;
}

#scene .plate-text h1 {
  margin: 0;
  font-size: clamp(17px, calc(var(--bench-width) * .041), 45px);
  line-height: 1.34;
  letter-spacing: -.035em;
}

#scene .plate-text .serial {
  color: #405463;
  font-size: clamp(7px, calc(var(--bench-width) * .012), 13px);
}

/* Use the photographed front wall and its existing machined outside silhouette.
   Light only the wall, below the PCB, leaving the package colours intact. */
#scene .base-plane::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  clip-path: polygon(5.3% 84%, 94.7% 84%, 94.7% 90%, 94.2% 94.9%,
    92.4% 97.6%, 7.6% 97.6%, 5.7% 94.9%, 5.3% 90%);
  background: linear-gradient(100deg, #25415f36, #c2dcec23 19%,
    transparent 46%, #29496533 85%, #0a1c302e);
}

#scene .n-cable-plug img {
  filter: saturate(.78) contrast(1.035) brightness(.98);
}

#scene .mj-cable-body {
  stroke: #1a2028;
}

#scene .mj-cable-highlight {
  stroke: #9eaebe;
  stroke-opacity: .39;
}

/* The sheet metal has two faces and one continuous, rounded perimeter.
   Its normal stays perpendicular to the screen until the opening sequence. */
#scene {
  --lid-gauge: clamp(3px, calc(var(--bench-width) * .014), 15px);
  --lid-lift: clamp(0, calc(var(--p, 0) * 1.85), 1);
  --lid-turn: clamp(0, calc((var(--p, 0) - .08) * 1.72), 1);
  --lid-leave: clamp(0, calc((var(--p, 0) - .61) / .39), 1);
  --lid-pitch: calc(
    64deg * clamp(0, calc((var(--p, 0) - .06) / .31), 1) +
    8deg * clamp(0, calc((var(--p, 0) - .37) / .17), 1) +
    39deg * clamp(0, calc((var(--p, 0) - .54) / .18), 1)
  );
}

#scene .solid-lid {
  transform-style: preserve-3d;
  transform-origin: 50% 46%;
  transform:
    translate3d(calc(var(--lid-turn) * -4vw - var(--lid-leave) * 100vw),
      calc(var(--lid-turn) * -6svh - var(--lid-leave) * 46svh),
      calc(1px + var(--bench-width) * var(--lid-lift) * .24))
    rotateZ(calc(-8deg * var(--lid-turn)))
    rotateY(calc(-8deg * var(--lid-turn)))
    rotateX(var(--lid-pitch));
  opacity: 1;
  will-change: transform;
}

#scene .solid-lid .lid-front {
  transform: translateZ(var(--lid-gauge));
  transform-style: preserve-3d;
}

#scene .solid-lid .lid-fastener {
  --screw-rise: calc(var(--unscrew, 0) * var(--lid-gauge) * 1.13);
  transform-style: preserve-3d;
}

#scene .solid-lid .bolt-head {
  transform: translateZ(calc(.5px + var(--screw-rise))) rotate(calc(var(--unscrew, 0) * -540deg));
}

#scene .solid-lid .bolt-shank {
  inset: 0;
  width: auto;
  height: auto;
  background: none;
  transform-style: preserve-3d;
}

#scene .bolt-shaft-facet {
  position: absolute;
  width: 12%;
  height: var(--screw-rise);
  transform-origin: 0 0;
  backface-visibility: hidden;
  background: repeating-linear-gradient(170deg, hsl(210 11% var(--shaft-lit)) 0 1px, #bcc8d2 1px 2px);
}

#scene .solid-lid .lid-back {
  display: block;
  transform: rotateX(180deg);
  border-radius: 3.2% / 7%;
  border: 1px solid #c4cdd3;
  background:
    repeating-linear-gradient(0deg, transparent 0 1px, #60778816 1px 2px),
    linear-gradient(106deg, #7890a2, #d1dce1 19%, #9baebd 47%, #e1e8e9 73%, #778d9e);
  box-shadow: inset 0 0 0 2px #eff7fc88, inset 0 0 0 3px #465e6f94;
}

#scene .solid-lid .lid-back .lid-texture {
  display: none;
}

#scene .solid-lid .lid-back::before {
  content: "";
  position: absolute;
  inset: 8% 4%;
  border: 1px solid #566e7d;
  border-radius: 2.5% / 6%;
  box-shadow: 0 1px 0 #edf4f7, inset 0 1px 2px #3f576b7a;
  background: linear-gradient(118deg, #a7b7c326, #8b9daa47 53%, #cfdee380);
}

#scene .lid-underside-bore {
  position: absolute;
  width: 1.7%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, #14202c 0 41%, #536471 46%, #b4c2ce 61%, #e4e9ea 69%, #5a6b77 75%, transparent 78%);
}

#scene .lid-perimeter {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}

#scene .lid-edge-panel {
  position: absolute;
  left: 0;
  top: 0;
  height: var(--lid-gauge);
  transform-origin: 0 0;
  backface-visibility: hidden;
  background: linear-gradient(to bottom, #e2e9ee 0,
    hsl(207 13% var(--edge-tone)) 15%, hsl(209 12% calc(var(--edge-tone) - 11%)) 70%,
    #a9bac8 88%, #e7eef1 100%);
}

/* Project onto the stationary tray while the solid lid lifts away. An opacity on
   the lid itself would flatten its children, so only this shadow fades. */
#scene .lid-projected-shadow {
  position: absolute;
  inset: 2.3% 5.3% 16.2%;
  border-radius: 3.2% / 7%;
  pointer-events: none;
  background: #08131b;
  opacity: calc(.36 - var(--p, 0) * .48);
  transform: translate3d(calc(var(--lid-lift) * 7%), calc(var(--lid-lift) * 10%), .75px)
    skewX(calc(var(--lid-turn) * -7deg)) scaleY(calc(1 - .67 * var(--lid-turn)));
  filter: blur(calc(2px + var(--bench-width) * .016 * var(--lid-lift)));
}

#scene.ready .lid-projected-shadow {
  visibility: hidden;
}

@media (prefers-reduced-motion: reduce) {
  #scene .solid-lid {
    transform: translateZ(1px);
    visibility: visible;
    opacity: 1;
    will-change: auto;
  }

  #scene.ready .solid-lid {
    visibility: hidden;
  }

  #scene .lid-projected-shadow {
    display: none;
  }

  #scene .solid-lid .bolt-head {
    transform: translateZ(.5px);
  }
}

@media (max-width: 800px) {
  #scene {
    --bench-width: var(--bench-module-width, min(74vw, 122svh));
    --bench-centre: var(--bench-module-center, 52%);
  }

  #scene .plate-text h1 {
    font-size: clamp(12px, calc(var(--bench-width) * .043), 24px);
  }

  #scene .plate-text .serial {
    font-size: clamp(6px, calc(var(--bench-width) * .018), 10px);
  }

  #scene .lid-front {
    box-shadow: inset 0 1px 0 #ffffffbd, 0 1px 0 #c0ced9, 0 2px 1px #20324191;
  }
}
