// pf-valves.jsx — Dibujos técnicos de válvulas de control para la Clase 2.9 de Profundización.
// Ilustraciones propias del curso en estilo de manual técnico: piezas en corte con rayado,
// fluido en azul, aire en verde y piezas móviles en naranja. Solo necesita React: no depende de
// pf-lib.jsx. También lo usa el curso «Válvulas de control» (vc-art.jsx cambia la paleta).
// Todos los componentes son puros (solo props) y devuelven un <g> en coordenadas locales.

const VA = {
  steel: '#d3dae2', steelD: '#9aa6b4', trim: '#eef2f6', trimD: '#a9b5c2',
  paint: '#4a6a90', paintD: '#2f4a6b', paintL: '#6d8db3',
  move: '#f48a3c', moveD: '#c9631c', air: '#7fd6a0', airD: '#2fae6a',
  spring: '#c9631c', gasket: '#2b2f36', ink: '#0f2b4a', liq: '#7fb3ea', liqD: '#3f86d4',
  vapor: '#ffffff', hot: '#d7263d',
};
const clampV = (v, a, b) => Math.max(a, Math.min(b, v));

// Patrones de rayado (corte) y degradados: se ponen una vez dentro de cada <svg>
function ValveDefs() {
  return (
    <defs>
      <pattern id="vaHatch" width="14" height="14" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
        <rect width="14" height="14" fill={VA.steel} /><line x1="0" y1="0" x2="0" y2="14" stroke={VA.steelD} strokeWidth="2.2" />
      </pattern>
      <pattern id="vaHatchT" width="10" height="10" patternUnits="userSpaceOnUse" patternTransform="rotate(-45)">
        <rect width="10" height="10" fill={VA.trim} /><line x1="0" y1="0" x2="0" y2="10" stroke={VA.trimD} strokeWidth="1.8" />
      </pattern>
      <pattern id="vaHatchP" width="12" height="12" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
        <rect width="12" height="12" fill={VA.paint} /><line x1="0" y1="0" x2="0" y2="12" stroke={VA.paintD} strokeWidth="2" />
      </pattern>
      <pattern id="vaHatchM" width="10" height="10" patternUnits="userSpaceOnUse" patternTransform="rotate(-45)">
        <rect width="10" height="10" fill={VA.move} /><line x1="0" y1="0" x2="0" y2="10" stroke={VA.moveD} strokeWidth="2" />
      </pattern>
      <linearGradient id="vaShaft" x1="0" x2="1" y1="0" y2="0">
        <stop offset="0" stopColor="#c5ccd5" /><stop offset="0.45" stopColor="#f6f8fa" /><stop offset="1" stopColor="#9aa6b4" />
      </linearGradient>
      <linearGradient id="vaLiq" x1="0" x2="0" y1="0" y2="1">
        <stop offset="0" stopColor="#9cc6f0" /><stop offset="1" stopColor="#6aa5e4" />
      </linearGradient>
      <radialGradient id="vaBall" cx="0.38" cy="0.35" r="0.75">
        <stop offset="0" stopColor="#ffffff" /><stop offset="0.55" stopColor="#d5dce4" /><stop offset="1" stopColor="#8b97a6" />
      </radialGradient>
    </defs>
  );
}

// Resorte helicoidal entre y1 (arriba) y y2 (abajo), centrado en x, con n espiras
function Coil({ x, y1, y2, w = 34, n = 7, color = VA.spring, sw = 5 }) {
  const h = y2 - y1, step = h / n;
  let d = `M ${x} ${y1}`;
  for (let i = 0; i < n; i++) {
    const ya = y1 + i * step;
    d += ` L ${x + w / 2} ${ya + step * 0.25} L ${x - w / 2} ${ya + step * 0.75}`;
  }
  d += ` L ${x} ${y2}`;
  return <path d={d} fill="none" stroke={color} strokeWidth={sw} strokeLinejoin="round" strokeLinecap="round" />;
}

// Tornillo prisionero visto de lado
function Stud({ x, y1, y2 }) {
  return (
    <g>
      <rect x={x - 6} y={y1} width="12" height={y2 - y1} fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="1.5" />
      <rect x={x - 12} y={y1 - 10} width="24" height="10" rx="2" fill="#7b8794" stroke={VA.ink} strokeWidth="1.5" />
      <rect x={x - 12} y={y2} width="24" height="10" rx="2" fill="#7b8794" stroke={VA.ink} strokeWidth="1.5" />
    </g>
  );
}

// Puntos que viajan por una polilínea; ph de 0 a 1 por partícula
function Particles({ pts, t, speed = 0.25, n = 14, r = 6, color = '#ffffff', op = 0.9, seed = 0 }) {
  if (op <= 0.01 || speed <= 0) return null;
  const seg = [];
  let L = 0;
  for (let i = 0; i < pts.length - 1; i++) {
    const [x1, y1] = pts[i], [x2, y2] = pts[i + 1];
    const l = Math.hypot(x2 - x1, y2 - y1); seg.push([x1, y1, x2, y2, L, l]); L += l;
  }
  const out = [];
  for (let k = 0; k < n; k++) {
    const ph = ((t * speed + k / n + seed) % 1 + 1) % 1, d = ph * L;
    const s = seg.find((q) => d >= q[4] && d <= q[4] + q[5]) || seg[seg.length - 1];
    const f = (d - s[4]) / s[5];
    const fade = Math.min(1, ph * 8, (1 - ph) * 8);
    out.push(<circle key={k} cx={s[0] + (s[2] - s[0]) * f} cy={s[1] + (s[3] - s[1]) * f} r={r} fill={color} opacity={op * fade} />);
  }
  return <g>{out}</g>;
}

// ── Válvula de globo guiada por jaula, con actuador de resorte y diafragma ────────
// open: 0 a 1 (carrera); air: 0 a 1 (presión en el actuador); act: 'ATO' (aire abre, resortes
// arriba, falla cierra) o 'ATC' (aire cierra, resortes abajo, falla abre). show: qué partes dibujar
// (para armar el ensamble paso a paso). Origen: eje del vástago, y = 0 en el asiento.
const LIFT = 110; // carrera completa en unidades locales
// trim: 'cage' (guiado por jaula, tapón balanceado) o 'simple' (asiento simple, tapón contorneado guiado por arriba)
function GlobeAssembly({ open = 0.5, air = 0.5, act = 'ATO', t = 0, flow = true, show = {}, positioner = false, posSignal = 0.5, trim = 'cage' }) {
  const L = LIFT * clampV(open, 0, 1);
  const on = (k) => show[k] !== false;
  // Fluido de entrada (bajo el tabique) y de salida (sobre el tabique)
  const inlet = 'M -400 -80 L -262 -80 L -150 15 L 150 15 L 232 92 L 232 140 Q 230 186 180 190 L -180 190 Q -232 186 -236 140 L -258 80 L -400 80 Z';
  const outlet = 'M -232 -118 L -150 -15 L 120 -15 L 262 80 L 400 80 L 400 -80 L 262 -80 L 236 -130 Q 222 -232 170 -240 L -170 -240 Q -222 -232 -232 -170 Z';
  // Ventanas de la jaula: de y = -15 hacia arriba, 120 de alto; el tapón las descubre al subir
  const winTop = -15 - 120, winOpen = L;
  const plugBot = -15 - L, plugTop = plugBot - 150;
  const dia = -860 - L; // plato del diafragma: se mueve igual que el tapón
  // Partículas del flujo: entra por la izquierda, sube por el asiento y sale por las ventanas
  const fl = flow && open > 0.02;
  const simple = trim === 'simple';
  const pathR = simple ? [[-420, 0], [-300, 0], [-200, 60], [-60, 120], [20, 60], [40, 0], [80, -30 - L * 0.3], [190, -40], [300, 0], [430, 0]]
    : [[-420, 0], [-300, 0], [-200, 60], [-60, 120], [0, 60], [0, 0], [10, -20 - L * 0.4], [100, -20 - L * 0.45], [190, -40], [300, 0], [430, 0]];
  const pathL = simple ? [[-420, 40], [-320, 40], [-160, 120], [-20, 150], [-30, 60], [-40, 0], [-80, -30 - L * 0.3], [-170, -90], [-150, -200], [0, -225], [150, -200], [230, -110], [320, -30], [430, -30]] : [[-420, 40], [-320, 40], [-160, 120], [0, 150], [10, 60], [-10, 0], [-10, -20 - L * 0.4], [-100, -20 - L * 0.45], [-180, -90], [-150, -200], [0, -225], [150, -200], [230, -110], [320, -30], [430, -30]];
  return (
    <g>
      {/* ── Cuerpo (corte) ── */}
      {on('body') && <g>
        <g stroke={VA.ink} strokeWidth="10" strokeLinejoin="round">
          <rect x="-430" y="-165" width="44" height="330" rx="6" fill="none" />
          <rect x="386" y="-165" width="44" height="330" rx="6" fill="none" />
          <rect x="-400" y="-112" width="800" height="224" fill="none" />
          <ellipse cx="0" cy="0" rx="290" ry="262" fill="none" />
          <rect x="-205" y="-290" width="410" height="40" fill="none" />
        </g>
        <g fill="url(#vaHatch)">
          <rect x="-430" y="-165" width="44" height="330" rx="6" />
          <rect x="386" y="-165" width="44" height="330" rx="6" />
          <rect x="-400" y="-112" width="800" height="224" />
          <ellipse cx="0" cy="0" rx="290" ry="262" />
          <rect x="-205" y="-290" width="410" height="40" />
        </g>
        <path d={inlet} fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="4" strokeLinejoin="round" />
        <path d={outlet} fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="4" strokeLinejoin="round" />
        {/* Garganta del asiento */}
        <rect x="-64" y="-17" width="128" height="34" fill="url(#vaLiq)" />
        {[-408, 408].map((x) => [-130, 130].map((y) => <circle key={`${x}${y}`} cx={x} cy={y} r="9" fill="#7b8794" stroke={VA.ink} strokeWidth="2" />))}
      </g>}

      {/* ── Asiento (anillo) ── */}
      {on('seat') && <g>
        <rect x="-112" y="-17" width="48" height="34" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="3" />
        <rect x="64" y="-17" width="48" height="34" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="3" />
        <rect x="-118" y="-21" width="60" height="5" fill={VA.gasket} /><rect x="58" y="-21" width="60" height="5" fill={VA.gasket} />
      </g>}

      {/* ── Jaula: paredes con ventanas ── */}
      {on('cage') && !simple && <g>
        {[-1, 1].map((sgn) => (
          <g key={sgn}>
            <rect x={sgn < 0 ? -112 : 92} y="-250" width="20" height={250 - 135} fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="3" />
            <rect x={sgn < 0 ? -112 : 92} y={winTop} width="20" height="120" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="2" strokeDasharray="6 5" />
          </g>
        ))}
        <rect x="-122" y="-262" width="244" height="14" fill={VA.gasket} />
      </g>}

      {/* ── Tapón y vástago (se mueven) ── */}
      {on('plug') && simple && <g transform={`translate(0 ${-L})`}>
        <path d="M -64 -110 L 64 -110 L 64 -40 Q 64 -18 52 -12 Q 38 12 0 20 Q -38 12 -52 -12 Q -64 -18 -64 -40 Z" fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="4" />
        <rect x="-22" y="-230" width="44" height="122" fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="3" />
      </g>}
      {on('plug') && !simple && <g>
        <rect x="-90" y={plugTop} width="180" height="150" rx="6" fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="4" />
        <rect x="-90" y={plugTop + 18} width="180" height="10" fill={VA.gasket} opacity="0.75" />
        <path d={`M -90 ${plugBot - 4} L -74 ${plugBot} L 74 ${plugBot} L 90 ${plugBot - 4}`} fill="none" stroke={VA.ink} strokeWidth="3" />
        {/* Puertos de balanceo */}
        <rect x="-40" y={plugTop + 40} width="14" height="100" fill="url(#vaLiq)" opacity="0.8" />
        <rect x="26" y={plugTop + 40} width="14" height="100" fill="url(#vaLiq)" opacity="0.8" />
      </g>}
      {on('stem') && <rect x="-13" y={-650 - L} width="26" height={485} fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />}

      {/* ── Bonete con empaquetadura ── */}
      {on('bonnet') && <g>
        <path d="M -210 -300 L 210 -300 L 210 -262 L 122 -262 L 122 -250 L -122 -250 L -122 -262 L -210 -262 Z" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" strokeLinejoin="round" />
        <path d="M -72 -300 L -72 -470 L -27 -470 L -27 -300 Z M 27 -300 L 27 -470 L 72 -470 L 72 -300 Z" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" strokeLinejoin="round" />
        <path d="M -120 -470 L 120 -470 L 120 -500 L -120 -500 Z" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
        {[-170, 170].map((x) => <Stud key={x} x={x} y1={-318} y2={-246} />)}
        {simple && <g><rect x="-48" y="-262" width="24" height="56" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="2.5" /><rect x="24" y="-262" width="24" height="56" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="2.5" /></g>}
        {/* Anillos en V de la empaquetadura */}
        {[0, 1, 2, 3, 4].map((i) => (
          <path key={i} d={`M -27 ${-382 - i * 16} L -13 ${-372 - i * 16} M 13 ${-372 - i * 16} L 27 ${-382 - i * 16}`} stroke="#2b2f36" strokeWidth="6" />
        ))}
        <rect x="-27" y="-350" width="14" height="18" fill="#7b8794" /><rect x="13" y="-350" width="14" height="18" fill="#7b8794" />
        {/* Seguidor y brida de la empaquetadura */}
        <rect x="-50" y="-540" width="100" height="40" fill="#b9c3ce" stroke={VA.ink} strokeWidth="4" />
        {[-90, 90].map((x) => <Stud key={x} x={x} y1={-552} y2={-500} />)}
        <rect x="-110" y="-552" width="220" height="14" fill="#9aa6b4" stroke={VA.ink} strokeWidth="3" />
      </g>}

      {/* ── Yugo e indicador de carrera ── */}
      {on('yoke') && <g>
        <path d="M -150 -552 L -120 -552 L -110 -760 L -150 -760 Z M 150 -552 L 120 -552 L 110 -760 L 150 -760 Z" fill={VA.paint} stroke={VA.ink} strokeWidth="5" strokeLinejoin="round" />
        <rect x="-170" y="-790" width="340" height="32" fill={VA.paint} stroke={VA.ink} strokeWidth="5" />
        {/* Conector del vástago */}
        <rect x="-38" y={-650 - L} width="76" height="44" rx="5" fill="#b9c3ce" stroke={VA.ink} strokeWidth="4" />
        <rect x="38" y={-634 - L} width="70" height="10" fill={VA.ink} />
        <polygon points={`108,${-639 - L} 128,${-629 - L} 108,${-619 - L}`} fill={VA.hot} />
        {/* Escala de carrera */}
        <rect x="132" y={-629 - LIFT - 10} width="42" height={LIFT + 20} fill="#fff" stroke={VA.ink} strokeWidth="3" />
        {[0, 25, 50, 75, 100].map((p) => <g key={p}>
          <line x1="132" y1={-629 - LIFT * p / 100} x2="148" y2={-629 - LIFT * p / 100} stroke={VA.ink} strokeWidth="2" />
          <text x="152" y={-625 - LIFT * p / 100} fontSize="13" fontFamily="'IBM Plex Mono', monospace" fill={VA.ink}>{p}</text>
        </g>)}
      </g>}

      {/* ── Actuador de resorte y diafragma (corte) ── */}
      {on('actuator') && <g>
        {/* Vástago del actuador: del plato al conector */}
        <rect x="-15" y={dia} width="30" height={210} fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />
        {/* Cámara de aire */}
        <path d={act === 'ATO'
          ? `M -296 -905 Q -270 ${dia} -230 ${dia} L 230 ${dia} Q 270 ${dia} 296 -905 L 278 -842 Q 0 -776 -278 -842 Z`
          : `M -296 -905 Q -270 ${dia} -230 ${dia} L 230 ${dia} Q 270 ${dia} 296 -905 L 278 -982 Q 0 -1072 -278 -982 Z`}
          fill={VA.air} opacity={0.12 + 0.78 * air} />
        {/* Carcasas (corte) */}
        <path d="M -310 -905 L -290 -830 Q 0 -760 290 -830 L 310 -905 L 296 -905 L 278 -842 Q 0 -776 -278 -842 L -296 -905 Z" fill="url(#vaHatchP)" stroke={VA.ink} strokeWidth="4" strokeLinejoin="round" />
        <path d="M -310 -905 L -292 -990 Q 0 -1094 292 -990 L 310 -905 L 296 -905 L 278 -982 Q 0 -1072 -278 -982 L -296 -905 Z" fill="url(#vaHatchP)" stroke={VA.ink} strokeWidth="4" strokeLinejoin="round" />
        <rect x="-334" y="-913" width="668" height="16" rx="3" fill={VA.paintD} />
        {[-318, 318].map((x) => <rect key={x} x={x - 6} y="-925" width="12" height="40" fill="#7b8794" stroke={VA.ink} strokeWidth="1.5" />)}
        {/* Diafragma y plato */}
        <path d={`M -298 -905 Q -270 ${dia} -230 ${dia} L 230 ${dia} Q 270 ${dia} 298 -905`} fill="none" stroke={VA.gasket} strokeWidth="6" />
        <rect x="-235" y={dia - 9} width="470" height="18" rx="4" fill="#b9c3ce" stroke={VA.ink} strokeWidth="3" />
        {/* Resortes */}
        {act === 'ATO'
          ? [-160, -60, 60, 160].map((x) => <Coil key={x} x={x} y1={-1058 + Math.abs(x) * 0.28} y2={dia - 9} n={7} />)
          : [-160, -60, 60, 160].map((x) => <Coil key={x} x={x} y1={dia + 9} y2={-792 - Math.abs(x) * 0.2} n={5} />)}
        {/* Toma de aire */}
        <rect x="262" y={act === 'ATO' ? -862 : -972} width="70" height="18" fill="#7b8794" stroke={VA.ink} strokeWidth="2" />
      </g>}

      {/* ── Posicionador montado en el yugo ── */}
      {positioner && <g>
        <path d={act === 'ATO' ? 'M 332 -853 L 425 -853 L 425 -690' : 'M 332 -963 L 425 -963 L 425 -690'} fill="none" stroke={VA.airD} strokeWidth="9" strokeLinecap="round" />
        <rect x="350" y="-690" width="150" height="190" rx="14" fill="#e9edf2" stroke={VA.ink} strokeWidth="5" />
        <rect x="372" y="-668" width="106" height="44" rx="6" fill={VA.paintD} />
        <text x="425" y="-639" textAnchor="middle" fontSize="20" fontWeight="700" fill="#fff" fontFamily="'IBM Plex Mono', monospace">{Math.round(4 + 16 * posSignal * 10) / 10} mA</text>
        <circle cx="425" cy="-570" r="30" fill="#fff" stroke={VA.ink} strokeWidth="3" />
        {(() => { const a = (-130 + 260 * air) * Math.PI / 180; return <line x1="425" y1="-570" x2={425 + 24 * Math.sin(a)} y2={-570 - 24 * Math.cos(a)} stroke={VA.hot} strokeWidth="4" strokeLinecap="round" />; })()}
        {/* Brazo de realimentación al conector del vástago */}
        {(() => { const px = 350, py = -560, ex = 108, ey = -629 - L; return <g><line x1={px} y1={py} x2={ex + 30} y2={ey} stroke={VA.ink} strokeWidth="7" strokeLinecap="round" /><circle cx={px} cy={py} r="9" fill={VA.ink} /><circle cx={ex + 30} cy={ey} r="7" fill={VA.hot} /></g>; })()}
        <path d="M 500 -560 L 560 -560" stroke="#2b2f36" strokeWidth="6" />
      </g>}

      {/* ── Flujo ── */}
      {on('body') && fl && <g>
        <Particles pts={pathR} t={t} speed={0.18 + 0.25 * open} n={16} r={6} op={0.9} />
        <Particles pts={pathL} t={t} speed={0.12 + 0.18 * open} n={14} r={6} op={0.75} seed={0.37} />
      </g>}
    </g>
  );
}

// Punto de una pieza del ensamble, para etiquetas (coordenadas locales)
const GLOBE_PARTS = {
  body: [-250, 150], seat: [-90, 0], cage: [-102, -200], plug: [0, -90], stem: [0, -420],
  packing: [-20, -400], bonnet: [-160, -280], yoke: [-135, -680], indicator: [150, -680],
  actuator: [-270, -950], spring: [-150, -1000], diaphragm: [230, -905], positioner: [425, -600],
};

// ── Jaula desenrollada: forma de la ventana según la característica ──────────
// Ancho de ventana w(h) con h de 0 (asiento) a 1 (carrera completa)
const CAGE_SHAPES = {
  qo: (h) => 1 - 0.75 * h,                       // apertura rápida: ancha abajo
  lin: () => 0.62,                               // lineal: rectangular
  eq: (h) => 0.06 + 0.94 * Math.pow(h, 2.4),     // igual porcentaje: angosta abajo
};
function cageArea(kind, h) { // área descubierta normalizada (0 a 1)
  const f = CAGE_SHAPES[kind]; let a = 0, A = 0; const n = 200;
  for (let i = 0; i < n; i++) { const y = (i + 0.5) / n; const w = f(y) / n; A += w; if (y <= h) a += w; }
  return a / A;
}
function CageWindow({ x, y, w = 220, h = 300, kind = 'lin', lift = 0.5, color = VA.move }) {
  const f = CAGE_SHAPES[kind];
  let left = '', right = '';
  for (let i = 0; i <= 60; i++) { const k = i / 60, yy = y + h - k * h, ww = f(k) * w / 2; left += `${i ? 'L' : 'M'} ${x - ww} ${yy} `; right = `L ${x + ww} ${yy} ` + right; }
  const shape = left + right + 'Z';
  const yl = y + h - lift * h;
  return (
    <g>
      <rect x={x - w / 2 - 30} y={y - 20} width={w + 60} height={h + 40} rx="10" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="4" />
      <clipPath id={`cw${kind}`}><rect x={x - w} y={yl} width={w * 2} height={y + h - yl} /></clipPath>
      <path d={shape} fill="#fff" stroke={VA.ink} strokeWidth="3" />
      <path d={shape} fill="url(#vaLiq)" clipPath={`url(#cw${kind})`} />
      <rect x={x - w / 2 - 30} y={y - 20} width={w + 60} height={Math.max(0, yl - y + 20)} fill={color} opacity="0.55" />
      <line x1={x - w / 2 - 30} y1={yl} x2={x + w / 2 + 30} y2={yl} stroke={VA.moveD} strokeWidth="6" />
    </g>
  );
}

// ── Mariposa de alto desempeño (vista a lo largo del eje) ───────────────────
// angle: 0 cerrada, 90 abierta
function ButterflyArt({ angle = 45, t = 0, flow = true }) {
  const a = clampV(angle, 0, 90), open = Math.sin(a * Math.PI / 180);
  return (
    <g>
      <rect x="-300" y="-150" width="600" height="300" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="6" />
      <rect x="-300" y="-120" width="600" height="240" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" />
      <rect x="-40" y="-150" width="80" height="300" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <rect x="-40" y="-120" width="80" height="240" fill="url(#vaLiq)" />
      {/* Anillo de asiento */}
      <rect x="-14" y="-124" width="28" height="12" fill={VA.gasket} /><rect x="-14" y="112" width="28" height="12" fill={VA.gasket} />
      <g transform={`rotate(${-a} 0 0) translate(14 0)`}>
        <path d="M -12 -116 Q 22 -60 22 0 Q 22 60 -12 116 Q -2 0 -12 -116 Z" fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="4" />
      </g>
      <circle cx="0" cy="0" r="16" fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />
      {flow && <Particles pts={[[-320, -60], [-60, -60 * (1 - open) - 40], [60, -40], [320, -60]]} t={t} speed={0.1 + 0.45 * open} n={10} op={open} />}
      {flow && <Particles pts={[[-320, 60], [-60, 60 * (1 - open) + 40], [60, 40], [320, 60]]} t={t} speed={0.1 + 0.45 * open} n={10} op={open} seed={0.5} />}
    </g>
  );
}

// ── Bola segmentada en V: corte y lo que «ve» el flujo ───────────────────────
function VBallArt({ angle = 45, t = 0, flow = true }) {
  const a = clampV(angle, 0, 90), k = a / 90;
  return (
    <g>
      <rect x="-300" y="-150" width="600" height="300" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="6" />
      <rect x="-300" y="-110" width="600" height="220" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" />
      <circle cx="0" cy="0" r="150" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <circle cx="0" cy="0" r="128" fill="url(#vaLiq)" />
      {/* Segmento de bola que gira hacia arriba al abrir */}
      {/* Casquete esférico: cerrado tapa el paso; al girar 90° sale del flujo */}
      <g transform={`rotate(${-90 * k} 0 0)`}>
        <path d={`M ${128 * Math.cos(-1.05)} ${128 * Math.sin(-1.05)} A 128 128 0 0 1 ${128 * Math.cos(1.05)} ${128 * Math.sin(1.05)} L ${104 * Math.cos(1.05)} ${104 * Math.sin(1.05)} A 104 104 0 0 0 ${104 * Math.cos(-1.05)} ${104 * Math.sin(-1.05)} Z`} fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="4" />
        <line x1="0" y1="0" x2={104 * Math.cos(-1.05)} y2={104 * Math.sin(-1.05)} stroke={VA.ink} strokeWidth="4" opacity="0.5" />
        <line x1="0" y1="0" x2={104 * Math.cos(1.05)} y2={104 * Math.sin(1.05)} stroke={VA.ink} strokeWidth="4" opacity="0.5" />
      </g>
      <circle cx="0" cy="0" r="14" fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />
      {flow && <Particles pts={[[-320, 0], [-80, 0], [80, -10 * k], [320, 0]]} t={t} speed={0.1 + 0.4 * k} n={12} op={Math.min(1, k * 3)} />}
    </g>
  );
}
// Abertura en V vista desde la tubería
function VNotchView({ k = 0.5, r = 110 }) {
  const h = 2 * r * clampV(k, 0, 1);
  return (
    <g>
      <circle cx="0" cy="0" r={r + 14} fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="4" />
      <circle cx="0" cy="0" r={r} fill="url(#vaBall)" stroke={VA.ink} strokeWidth="3" />
      <clipPath id="vnotch"><circle cx="0" cy="0" r={r} /></clipPath>
      <path d={`M 0 ${r} L ${-0.55 * h} ${r - h} L ${0.55 * h} ${r - h} Z`} fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" clipPath="url(#vnotch)" />
    </g>
  );
}

// ── Tapón rotativo excéntrico ───────────────────────────────────────────────
function EccPlugArt({ angle = 30, t = 0, flow = true }) {
  const a = clampV(angle, 0, 60), k = a / 60;
  return (
    <g>
      <rect x="-300" y="-150" width="600" height="300" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="6" />
      <rect x="-300" y="-110" width="600" height="220" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" />
      <rect x="-20" y="-150" width="40" height="70" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="3" />
      <rect x="-20" y="80" width="40" height="70" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="3" />
      <g transform={`rotate(${-a} 70 -150)`}>
        <line x1="70" y1="-150" x2="30" y2="-40" stroke={VA.ink} strokeWidth="10" />
        <path d="M 20 -80 Q 0 0 20 80 L 46 80 Q 30 0 46 -80 Z" fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="4" />
      </g>
      <circle cx="70" cy="-150" r="14" fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />
      {flow && <Particles pts={[[-320, 20], [-40, 20], [40, 40], [320, 20]]} t={t} speed={0.1 + 0.35 * k} n={10} op={Math.min(1, k * 3)} />}
    </g>
  );
}

// ── Válvula de diafragma tipo vertedero (corte) ─────────────────────────────
// open: 0 (diafragma apretado contra el vertedero) a 1 (levantado)
function DiaphragmArt({ open = 0.6, t = 0, flow = true }) {
  const k = clampV(open, 0, 1), yd = -10 - 90 * k;
  return (
    <g>
      <path d="M -300 -150 L 300 -150 L 300 150 L -300 150 Z" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="6" />
      <path d={`M -300 -90 L -110 -90 Q -60 ${yd} 0 ${yd} Q 60 ${yd} 110 -90 L 300 -90 L 300 90 L -300 90 Z`} fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" />
      {/* Vertedero */}
      <path d="M -120 90 Q -60 -10 0 -10 Q 60 -10 120 90 Z" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="4" />
      {/* Diafragma elastomérico y compresor */}
      <path d={`M -150 -150 L -110 -90 Q -60 ${yd} 0 ${yd} Q 60 ${yd} 110 -90 L 150 -150`} fill="none" stroke="#3a3f47" strokeWidth="10" strokeLinejoin="round" />
      <path d={`M -70 ${yd - 50} L 70 ${yd - 50} L 50 ${yd - 8} L -50 ${yd - 8} Z`} fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="3" />
      <rect x="-12" y="-300" width="24" height={250 + yd} fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />
      <path d="M -170 -150 L 170 -150 L 130 -260 L -130 -260 Z" fill="url(#vaHatchP)" stroke={VA.ink} strokeWidth="5" />
      {flow && <Particles pts={[[-320, 40], [-120, 40], [0, yd + 30], [120, 40], [320, 40]]} t={t} speed={0.1 + 0.3 * k} n={10} op={Math.min(1, k * 3)} />}
    </g>
  );
}

// ── Válvula de ángulo (corte): entra por un lado y sale hacia abajo ───────────
function AngleBodyArt({ open = 0.5, t = 0, flow = true }) {
  const L = 80 * clampV(open, 0, 1);
  return (
    <g>
      <g stroke={VA.ink} strokeWidth="10"><rect x="-380" y="-112" width="300" height="224" fill="none" /><rect x="-112" y="80" width="224" height="300" fill="none" /><circle cx="0" cy="0" r="200" fill="none" /><rect x="-160" y="-250" width="320" height="40" fill="none" /></g>
      <g fill="url(#vaHatch)"><rect x="-380" y="-112" width="300" height="224" /><rect x="-112" y="80" width="224" height="300" /><circle cx="0" cy="0" r="200" /><rect x="-160" y="-250" width="320" height="40" /></g>
      <rect x="-410" y="-160" width="34" height="320" rx="5" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <rect x="-160" y="376" width="320" height="34" rx="5" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <path d="M -380 -80 L -150 -80 Q -130 -170 0 -170 Q 130 -170 140 -60 L 140 40 L 64 40 L 64 60 L -64 60 L -64 40 L -140 40 L -150 80 L -380 80 Z" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="4" />
      <path d="M -64 60 L 64 60 L 80 380 L -80 380 Z" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="4" />
      <rect x="-104" y="40" width="40" height="30" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="3" /><rect x="64" y="40" width="40" height="30" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="3" />
      <g transform={`translate(0 ${-L})`}>
        <path d="M -62 -90 L 62 -90 L 62 0 Q 60 30 30 50 Q 0 64 -30 50 Q -60 30 -62 0 Z" fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="4" />
        <rect x="-14" y="-330" width="28" height="242" fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />
      </g>
      <rect x="-60" y="-330" width="34" height="80" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="4" /><rect x="26" y="-330" width="34" height="80" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="4" />
      {flow && open > 0.02 && <Particles pts={[[-420, 0], [-160, 0], [-90, -60], [-40, 30], [0, 120], [0, 420]]} t={t} speed={0.15 + 0.3 * open} n={14} op={0.9} />}
    </g>
  );
}

// ── Válvula de tres vías mezcladora (corte): dos entradas, una salida ───────────
// pos: 0 = todo por la entrada A (arriba), 1 = todo por la entrada B (abajo)
function ThreeWayArt({ pos = 0.5, t = 0, flow = true }) {
  const y = -50 + 100 * clampV(pos, 0, 1); // el tapón doble sube y baja entre los dos asientos
  return (
    <g>
      <g stroke={VA.ink} strokeWidth="10"><rect x="-380" y="-200" width="300" height="160" fill="none" /><rect x="-380" y="40" width="300" height="160" fill="none" /><rect x="80" y="-80" width="300" height="160" fill="none" /><rect x="-160" y="-260" width="320" height="520" rx="40" fill="none" /></g>
      <g fill="url(#vaHatch)"><rect x="-380" y="-200" width="300" height="160" /><rect x="-380" y="40" width="300" height="160" /><rect x="80" y="-80" width="300" height="160" /><rect x="-160" y="-260" width="320" height="520" rx="40" /></g>
      <path d="M -380 -175 L -130 -175 L -130 -110 L 130 -110 L 130 -60 L 380 -60 L 380 60 L 130 60 L 130 110 L -130 110 L -130 175 L -380 175 L -380 65 L -130 65 L -130 -65 L -380 -65 Z" fill="none" />
      <path d="M -380 -175 L -110 -175 L -110 -210 L 110 -210 L 110 -64 L 60 -64 L 60 -80 L -60 -80 L -60 -64 L -110 -64 L -110 -65 L -380 -65 Z" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" />
      <path d="M -380 65 L -110 65 L -110 64 L -60 64 L -60 80 L 60 80 L 60 64 L 110 64 L 110 210 L -110 210 L -110 175 L -380 175 Z" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" />
      <path d="M -60 -64 L 60 -64 L 60 -40 L 130 -40 L 130 -60 L 380 -60 L 380 60 L 130 60 L 130 40 L 60 40 L 60 64 L -60 64 Z" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" />
      {[-80, 64].map((yy) => <g key={yy}><rect x="-110" y={yy} width="50" height="16" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="2.5" /><rect x="60" y={yy} width="50" height="16" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="2.5" /></g>)}
      <g transform={`translate(0 ${y})`}>
        <rect x="-74" y="-30" width="148" height="20" rx="4" fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="3" />
        <rect x="-74" y="10" width="148" height="20" rx="4" fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="3" />
        <rect x="-12" y="-300" width="24" height="330" fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="2.5" />
      </g>
      <text x="-370" y="-210" fontSize="28" fontWeight="700" fill={VA.ink} fontFamily="'IBM Plex Mono', monospace">A</text>
      <text x="-370" y="232" fontSize="28" fontWeight="700" fill={VA.ink} fontFamily="'IBM Plex Mono', monospace">B</text>
      <text x="330" y="-80" fontSize="28" fontWeight="700" fill={VA.ink} fontFamily="'IBM Plex Mono', monospace">AB</text>
      {flow && <Particles pts={[[-400, -120], [-150, -120], [-30, -90], [0, -50], [140, 0], [400, 0]]} t={t} speed={0.3} n={10} op={clampV(1 - pos, 0, 1)} />}
      {flow && <Particles pts={[[-400, 120], [-150, 120], [-30, 90], [0, 50], [140, 10], [400, 10]]} t={t} speed={0.3} n={10} op={clampV(pos, 0, 1)} seed={0.5} />}
    </g>
  );
}

// ── Bonetes: estándar, extendido con aletas y de sello de fuelle ───────────────
// Origen: unión con el cuerpo (y = 0); el bonete crece hacia arriba. travel 0..1 mueve el vástago.
function BonnetArt({ type = 'std', travel = 0.5 }) {
  const neck = type === 'std' ? 170 : 420;
  const top = -40 - neck;
  const dy = -40 * clampV(travel, 0, 1);
  return (
    <g>
      {/* parte alta del cuerpo */}
      <path d="M -200 80 L -200 0 L 200 0 L 200 80 Q 0 140 -200 80 Z" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <rect x="-210" y="-40" width="420" height="40" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      {/* cuello del bonete */}
      <rect x="-72" y={top} width="45" height={neck} fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="4" />
      <rect x="27" y={top} width="45" height={neck} fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="4" />
      {type === 'ext' && Array.from({ length: 9 }, (_, i) => (
        <g key={i}><rect x="-150" y={-80 - i * 30} width="78" height="10" fill="#b9c3ce" stroke={VA.ink} strokeWidth="2" /><rect x="72" y={-80 - i * 30} width="78" height="10" fill="#b9c3ce" stroke={VA.ink} strokeWidth="2" /></g>
      ))}
      {/* fuelle metálico soldado al vástago */}
      {type === 'bellows' && (() => {
        const y1 = -60, y2 = top + 150 + dy; let d = '';
        const n = 12, h = (y2 - y1) / n;
        for (let i = 0; i <= n; i++) d += `${i ? 'L' : 'M'} ${i % 2 ? -26 : -14} ${y1 + i * h} `;
        let e = ''; for (let i = 0; i <= n; i++) e += `${i ? 'L' : 'M'} ${i % 2 ? 26 : 14} ${y1 + i * h} `;
        return <g><rect x="-26" y={y2} width="52" height={y1 - y2} fill="#eef2f6" /><path d={d} fill="none" stroke={VA.airD} strokeWidth="6" strokeLinejoin="round" /><path d={e} fill="none" stroke={VA.airD} strokeWidth="6" strokeLinejoin="round" /></g>;
      })()}
      {/* empaquetadura arriba */}
      {[0, 1, 2, 3].map((i) => <path key={i} d={`M -27 ${top + 70 - i * 14} L -13 ${top + 80 - i * 14} M 13 ${top + 80 - i * 14} L 27 ${top + 70 - i * 14}`} stroke="#2b2f36" strokeWidth="5" />)}
      <rect x="-90" y={top - 30} width="180" height="30" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="4" />
      <rect x="-13" y={top - 70 + dy} width="26" height={-top + 150} fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />
    </g>
  );
}

// ── Empaquetadura en corte ampliado: anillos en V de PTFE, grafito o carga viva ─────
// wear 0..1 hunde un poco el seguidor; en carga viva los resortes lo compensan.
function PackingArt({ type = 'ptfe', t = 0, wear = 0, stem = null }) {
  const stemY = stem == null ? 14 * Math.sin(t * 1.4) : stem;
  const comp = type === 'live' ? 0 : 14 * clampV(wear, 0, 1);
  const rings = [];
  for (let i = 0; i < 5; i++) {
    const y = 140 - i * 44 + comp * (i / 5);
    if (type === 'graphite') rings.push(<g key={i}><rect x="-120" y={y - 36} width="80" height="38" fill="#4b525b" stroke={VA.ink} strokeWidth="2" /><rect x="40" y={y - 36} width="80" height="38" fill="#4b525b" stroke={VA.ink} strokeWidth="2" />{[0, 1, 2].map((k) => <g key={k}><line x1="-118" y1={y - 26 + k * 10} x2="-42" y2={y - 26 + k * 10} stroke="#7a828c" strokeWidth="1.5" /><line x1="42" y1={y - 26 + k * 10} x2="118" y2={y - 26 + k * 10} stroke="#7a828c" strokeWidth="1.5" /></g>)}</g>);
    else rings.push(<g key={i}><path d={`M -120 ${y - 30} L -80 ${y - 4} L -40 ${y - 30} L -40 ${y - 14} L -80 ${y + 10} L -120 ${y - 14} Z`} fill="#f4f6f8" stroke={VA.ink} strokeWidth="2.5" /><path d={`M 40 ${y - 30} L 80 ${y - 4} L 120 ${y - 30} L 120 ${y - 14} L 80 ${y + 10} L 40 ${y - 14} Z`} fill="#f4f6f8" stroke={VA.ink} strokeWidth="2.5" /></g>);
  }
  const fy = -110 + comp; // seguidor
  return (
    <g>
      <rect x="-220" y="-140" width="100" height="340" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <rect x="120" y="-140" width="100" height="340" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <rect x="-220" y="200" width="440" height="40" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <rect x="-120" y="160" width="80" height="40" fill="#9aa6b4" stroke={VA.ink} strokeWidth="2" /><rect x="40" y="160" width="80" height="40" fill="#9aa6b4" stroke={VA.ink} strokeWidth="2" />
      {rings}
      <rect x="-120" y={fy} width="80" height="40" fill="#b9c3ce" stroke={VA.ink} strokeWidth="3" /><rect x="40" y={fy} width="80" height="40" fill="#b9c3ce" stroke={VA.ink} strokeWidth="3" />
      <rect x="-260" y={fy - 30} width="520" height="30" fill="#9aa6b4" stroke={VA.ink} strokeWidth="3" />
      {[-200, 200].map((x) => <g key={x}>
        <rect x={x - 8} y={fy - 140} width="16" height="200" fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="2" />
        {type === 'live'
          ? [0, 1, 2, 3, 4, 5].map((k) => <path key={k} d={`M ${x - 32} ${fy - 36 - k * 14 + (k % 2 ? 4 : 0)} L ${x} ${fy - 44 - k * 14 + (k % 2 ? -4 : 4)} L ${x + 32} ${fy - 36 - k * 14 + (k % 2 ? 4 : 0)}`} fill="none" stroke={VA.spring} strokeWidth="5" strokeLinejoin="round" />)
          : null}
        <rect x={x - 22} y={type === 'live' ? fy - 140 : fy - 52} width="44" height="22" fill="#7b8794" stroke={VA.ink} strokeWidth="2" />
      </g>)}
      <rect x="-40" y={-260 + stemY} width="80" height="520" fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="4" />
    </g>
  );
}

// ── Mariposa según su excentricidad (corte a lo largo de la tubería) ──────────
// offset: 'conc' (eje centrado), 'double' (eje detrás del sello y desplazado), 'triple' (además, sello cónico)
function ButterflyOffsetArt({ offset = 'conc', angle = 30, t = 0 }) {
  const a = clampV(angle, 0, 90);
  const px = offset === 'conc' ? 0 : 34, py = offset === 'conc' ? 0 : 26;
  const cone = offset === 'triple';
  const disc = cone
    ? 'M -14 -116 L 14 -106 L 18 106 L -18 116 Z'
    : 'M -14 -116 Q 14 -60 14 0 Q 14 60 -14 116 Q -4 0 -14 -116 Z';
  return (
    <g>
      <rect x="-280" y="-150" width="560" height="300" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="6" />
      <rect x="-280" y="-120" width="560" height="240" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" />
      {/* sello o anillo de asiento (rojo si el disco lo roza) */}
      {(() => { const rub = offset === 'conc' || a < 6; const c = rub && a > 1 ? VA.hot : VA.gasket; return <g><rect x="-16" y="-128" width="32" height="14" fill={c} /><rect x="-16" y="114" width="32" height="14" fill={c} /></g>; })()}
      <g transform={`rotate(${-a} ${px} ${py})`}><path d={disc} fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="4" /></g>
      {offset !== 'conc' && <line x1={px} y1={py} x2="0" y2={py} stroke={VA.ink} strokeWidth="3" strokeDasharray="6 5" />}
      <circle cx={px} cy={py} r="14" fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />
      <Particles pts={[[-300, -70], [-60, -70], [80, -60], [300, -70]]} t={t} speed={0.1 + 0.4 * a / 90} n={8} op={a / 90} />
      <Particles pts={[[-300, 70], [-60, 70], [80, 60], [300, 70]]} t={t} speed={0.1 + 0.4 * a / 90} n={8} op={a / 90} seed={0.5} />
    </g>
  );
}

// ── Mariposa con actuador de diafragma y palanca (vista a lo largo del eje) ─────
// La palanca va en el extremo del eje del disco (al frente del dibujo); el actuador la empuja.
function RotaryLinkArt({ angle = 45, t = 0, air = 0.5 }) {
  const a = clampV(angle, 0, 90);
  const th = (-160 + a) * Math.PI / 180, R = 190;
  const Px = R * Math.cos(th), Py = R * Math.sin(th);     // pasador de la palanca
  const Ax = -330, Ay = -470;                              // pivote del actuador
  const ang = Math.atan2(Py - Ay, Px - Ax) * 180 / Math.PI;
  const len = Math.hypot(Px - Ax, Py - Ay);
  return (
    <g>
      <ButterflyArt angle={a} t={t} />
      {/* caja de la palanca, al frente */}
      <circle cx="0" cy="0" r="70" fill="#e9edf2" fillOpacity="0.85" stroke={VA.ink} strokeWidth="4" />
      <line x1="0" y1="0" x2={Px} y2={Py} stroke={VA.moveD} strokeWidth="24" strokeLinecap="round" />
      <circle cx="0" cy="0" r="20" fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />
      <circle cx={Px} cy={Py} r="12" fill={VA.ink} />
      {/* actuador de diafragma que gira sobre su pivote */}
      <g transform={`translate(${Ax} ${Ay}) rotate(${ang - 90})`}>
        <rect x="-11" y="60" width="22" height={len - 60} fill="url(#vaShaft)" stroke={VA.ink} strokeWidth="3" />
        <path d="M -120 60 L 120 60 L 110 -10 Q 0 -60 -110 -10 Z" fill="url(#vaHatchP)" stroke={VA.ink} strokeWidth="4" />
        <path d="M -104 52 L 104 52 L 96 0 Q 0 -40 -96 0 Z" fill={VA.air} opacity={0.15 + 0.75 * air} />
      </g>
      <circle cx={Ax} cy={Ay} r="12" fill={VA.ink} />
      <path d={`M ${Ax - 70} ${Ay - 26} L ${Ax + 70} ${Ay - 26}`} stroke={VA.ink} strokeWidth="8" />
    </g>
  );
}

// ── Detalle ampliado del asiento: para cavitación y flashing ───────────────────
// Corte del paso entre tapón contorneado y asiento; x de -500 a 500, y de -220 a 220.
// p2: presión de salida relativa (Pv = 0,3). stage: 'single' o 'multi'
function SeatZoom({ t = 0, mode = 'cav', damage = 0 }) {
  const bubbles = [];
  const N = 22;
  for (let i = 0; i < N; i++) {
    const ph = ((t * 0.45 + i / N) % 1 + 1) % 1;
    const yy = -40 + ((i * 37) % 80);
    const x = -60 + ph * 520;
    let r;
    if (mode === 'none') r = 0;
    else if (mode === 'cav') r = ph < 0.35 ? 3 + 30 * ph : ph < 0.55 ? Math.max(0, 13.5 * (1 - (ph - 0.35) / 0.2)) : 0;
    else r = 3 + 18 * Math.min(1, ph * 1.5);
    const cy = mode === 'cav' ? yy + (ph > 0.25 ? -(yy + 125) * Math.min(1, (ph - 0.25) / 0.3) : 0) : yy;
    if (r > 0.5) bubbles.push(<circle key={i} cx={x} cy={cy} r={r} fill={VA.vapor} fillOpacity="0.55" stroke={VA.liqD} strokeWidth="2.5" />);
    if (mode === 'cav' && ph > 0.53 && ph < 0.62) {
      const q = (ph - 0.53) / 0.09;
      bubbles.push(<g key={`b${i}`} opacity={1 - q}>
        {[0, 1, 2, 3, 4, 5, 6, 7].map((k) => { const a = k * Math.PI / 4; return <line key={k} x1={x + 6 * Math.cos(a)} y1={-130 + 6 * Math.sin(a)} x2={x + (8 + 22 * q) * Math.cos(a)} y2={-130 + (8 + 22 * q) * Math.sin(a)} stroke={VA.hot} strokeWidth="3" />; })}
      </g>);
    }
  }
  const pits = [];
  for (let i = 0; i < Math.round(26 * damage); i++) pits.push(<ellipse key={i} cx={150 + (i * 53) % 300} cy={-150 + (i % 3) * 3} rx={6 + (i % 3) * 3} ry="5" fill="#5b6470" />);
  return (
    <g>
      {/* Pared del cuerpo aguas abajo (arriba) y tapón contorneado (abajo-izquierda) */}
      <path d="M -500 -220 L 500 -220 L 500 -150 L 100 -150 Q 0 -150 -60 -110 L -500 -110 Z" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <path d="M -500 220 L 500 220 L 500 150 L -60 150 Q -100 150 -120 120 L -500 120 Z" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <path d="M -500 -110 L -60 -110 Q 0 -150 100 -150 L 500 -150 L 500 150 L -60 150 Q -100 150 -120 120 L -500 120 Z" fill="url(#vaLiq)" />
      {/* Asiento y tapón dejan una garganta estrecha */}
      <path d="M -160 -110 L -60 -110 L -40 -40 L -160 -40 Z" fill="url(#vaHatchT)" stroke={VA.ink} strokeWidth="4" />
      <path d="M -160 120 L -120 120 Q -70 60 -40 30 L -160 30 Z" fill="url(#vaHatchM)" stroke={VA.ink} strokeWidth="4" />
      {pits}
      {mode === 'flash' && <rect x="-40" y="-150" width="540" height="300" fill="#fff" opacity="0.25" />}
      <Particles pts={[[-500, -75], [-160, -75], [-40, -5], [100, -40], [500, -60]]} t={t} speed={0.35} n={10} r={5} op={0.85} />
      <Particles pts={[[-500, 80], [-160, 80], [-40, 5], [100, 40], [500, 60]]} t={t} speed={0.35} n={10} r={5} op={0.85} seed={0.5} />
      {bubbles}
    </g>
  );
}

// Jaula antcavitación de varias etapas (corte)
function MultiStageArt({ t = 0 }) {
  const rings = [0, 1, 2];
  return (
    <g>
      <circle cx="0" cy="0" r="300" fill="url(#vaHatch)" stroke={VA.ink} strokeWidth="5" />
      <circle cx="0" cy="0" r="275" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" />
      {rings.map((i) => {
        const r = 70 + i * 55;
        return <g key={i}>
          <circle cx="0" cy="0" r={r + 18} fill="none" stroke={VA.ink} strokeWidth="30" /><circle cx="0" cy="0" r={r + 18} fill="none" stroke="#c4ced8" strokeWidth="25" />
          {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((k) => { const a = (k / 12) * Math.PI * 2 + i * 0.26; return <circle key={k} cx={(r + 18) * Math.cos(a)} cy={(r + 18) * Math.sin(a)} r="7" fill={VA.liq} stroke={VA.ink} strokeWidth="1.5" />; })}
        </g>;
      })}
      <circle cx="0" cy="0" r="60" fill="url(#vaLiq)" stroke={VA.ink} strokeWidth="3" />
      {[0, 1, 2, 3, 4, 5].map((k) => {
        const a0 = (k / 6) * Math.PI * 2;
        const pts = [[0, 0], [100 * Math.cos(a0), 100 * Math.sin(a0)], [150 * Math.cos(a0 + 0.26), 150 * Math.sin(a0 + 0.26)], [205 * Math.cos(a0 + 0.52), 205 * Math.sin(a0 + 0.52)], [260 * Math.cos(a0 + 0.6), 260 * Math.sin(a0 + 0.6)]];
        return <Particles key={k} pts={pts} t={t} speed={0.3} n={4} r={5} op={0.9} seed={k / 6} />;
      })}
    </g>
  );
}

Object.assign(window, {
  VA, ValveDefs, Coil, Stud, Particles, GlobeAssembly, GLOBE_PARTS, LIFT,
  CAGE_SHAPES, cageArea, CageWindow, ButterflyArt, VBallArt, VNotchView, EccPlugArt, DiaphragmArt, SeatZoom, MultiStageArt,
  AngleBodyArt, ThreeWayArt, BonnetArt, PackingArt, ButterflyOffsetArt, RotaryLinkArt,
});
