/* The host box is --butterfly-size wide; the rig's origin (the thorax, where the wings hinge)
   sits at 50% / 47.2% of it. */
:host {
  --s: var(--butterfly-size, 40px);
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  display: block;
  width: var(--s);
  aspect-ratio: 208 / 178;
  pointer-events: none;
  perspective: calc(var(--s) * 7);
  perspective-origin: 50% 47.2%;
  will-change: translate;
}
:host([hidden]) { display: none; }

/* the 3D rig: lean in the screen plane, then tilt toward a side view, then turn the head */
.rig {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform-origin: 50% 47.2%;
  transform:
    rotateZ(calc(var(--lean, 0) * 1deg))
    rotateX(calc(var(--tilt, 0) * 1deg))
    rotateZ(calc(var(--yaw, 0) * 1deg));
}

.plane {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform-origin: 50% 47.2%;
  backface-visibility: visible;
}

/* wings hinge on the body axis and fold up toward the back (toward the viewer from above) */
.fore-r { transform: rotateY(calc(var(--fore-r, 0) * -1deg)); }
.hind-r { transform: rotateY(calc(var(--hind-r, 0) * -1deg)); }
.fore-l { transform: rotateY(calc(var(--fore-l, 0) * 1deg)); }
.hind-l { transform: rotateY(calc(var(--hind-l, 0) * 1deg)); }

/* the two body layers: from above (a hair above the wing roots) and in profile. Each is faded
   by how squarely it faces the viewer (--top-vis / --side-vis, set from script). */
.body-top  { transform: translateZ(0.6px); opacity: var(--top-vis, 1); }
.body-side { transform: rotateY(90deg); opacity: var(--side-vis, 0); }

/* soft shadow under its feet when it rests on something (screen-aligned, outside the rig) */
.perch-shadow {
  position: absolute;
  left: 50%;
  top: calc(47.2% + var(--s) * 0.08);
  width: calc(var(--s) * 0.42);
  height: calc(var(--s) * 0.05);
  translate: -50% -50%;
  border-radius: 50%;
  background: var(--color-ink);
  filter: blur(calc(var(--s) * 0.02));
  opacity: calc(var(--shadow, 0) * 0.22);
}

/* invisible, generous tap target */
.hit {
  position: absolute;
  inset: -10%;
  border-radius: 50%;
  pointer-events: all;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- palette ---------- */
.stop-wing-light { stop-color: var(--color-wing-light); }
.stop-wing       { stop-color: var(--color-wing); }
.stop-wing-shade { stop-color: var(--color-wing-shade); }

.wing-edge { fill: var(--color-ink); stroke: var(--color-ink); stroke-width: 3; stroke-linejoin: round; }
.wing-blue { fill: url(#wing-grad); }
.wing-glow { fill: var(--color-wing-glow); opacity: 0.85; filter: url(#soften); }
.vein { fill: none; stroke: var(--color-ink); stroke-width: 2.4; stroke-linecap: round; }
.dot-white { fill: #fff; }
.dot-blue { fill: var(--color-wing-glow); }

.abdomen, .thorax, .head, .club { fill: var(--color-ink); }
.stripe { stroke: var(--color-wing-light); stroke-width: 1.6; stroke-linecap: round; }
.speck { fill: #fff; }
.antenna, .leg { fill: none; stroke: var(--color-ink); stroke-width: 2.2; stroke-linecap: round; }
