jiteshkprasad commited on
Commit
6134f15
·
verified ·
1 Parent(s): e4c0886

BioCell simulator (private preview)

Browse files
Files changed (1) hide show
  1. static/index.html +113 -59
static/index.html CHANGED
@@ -128,14 +128,24 @@ body.mixing .card .cname{padding-right:30px}
128
  .org:focus{outline:none}
129
  .org:focus-visible .shp{stroke-width:3.5}
130
  .shp{transition:fill .4s ease-out,stroke .4s ease-out}
131
- .clbl{font:600 12px var(--sans);fill:var(--ink)}
132
- .cst{font:500 11.5px var(--sans);fill:var(--ink)}
133
  .cst .arr{font-weight:700}
 
 
 
134
  #breath{transform-box:fill-box;transform-origin:center;animation:breathe 7s ease-in-out infinite alternate}
135
  @keyframes breathe{from{transform:scale(1)}to{transform:scale(1.015)}}
136
- body.calm #breath{animation:none}
 
 
 
 
 
 
 
137
  body.calm .shp{transition:none}
138
- @media (prefers-reduced-motion: reduce){#breath{animation:none}.shp{transition:none}.card{transition:none}}
139
 
140
  /* System card */
141
  .syscard{position:absolute;left:18px;right:18px;bottom:18px;background:var(--white);border-radius:28px;box-shadow:var(--lift);padding:16px 18px;z-index:5;border:1px solid var(--line)}
@@ -249,7 +259,7 @@ dialog .close{position:absolute;top:18px;right:18px}
249
  .controls{border-radius:28px;padding:12px}
250
  .group.lines{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none;max-width:100%}
251
  .clbl,.cst .stt{display:none}
252
- .cst{font-size:22px}
253
  .story{min-height:420px;padding:18px}
254
  .genes{grid-template-columns:1fr}
255
  .twocol{grid-template-columns:1fr}
@@ -452,14 +462,13 @@ const rmq = window.matchMedia("(prefers-reduced-motion: reduce)");
452
  const motionOff = () => rmq.matches || state.paused;
453
 
454
  /* ---------- The cell drawing ---------- */
455
- function blobPath(cx, cy, rx, ry, k){
456
- // A soft, organic closed outline: an ellipse with a few gentle bumps, smoothed with Catmull-Rom curves.
457
- const n = 36, pts = [];
458
- for (let i = 0; i < n; i++){
459
- const t = i / n * Math.PI * 2;
460
- const r = 1 + k * (0.030 * Math.sin(3*t + 0.6) + 0.018 * Math.sin(5*t + 2.1) + 0.010 * Math.sin(7*t + 0.3));
461
- pts.push([cx + rx * r * Math.cos(t), cy + ry * r * Math.sin(t)]);
462
- }
463
  const f = v => v.toFixed(1);
464
  let d = `M${f(pts[0][0])} ${f(pts[0][1])}`;
465
  for (let i = 0; i < n; i++){
@@ -468,58 +477,103 @@ function blobPath(cx, cy, rx, ry, k){
468
  }
469
  return d + "Z";
470
  }
471
- function erPath(cx, cy, rx, ry){
472
- // A wavy ring (the protein-factory network round the nucleus).
473
- const n = 120; let d = "";
 
 
474
  for (let i = 0; i <= n; i++){
475
- const t = i / n * Math.PI * 2, w = 1 + 0.045 * Math.sin(9*t);
476
- d += (i ? " L" : "M") + (cx + rx*w*Math.cos(t)).toFixed(1) + " " + (cy + ry*w*Math.sin(t)).toFixed(1);
477
  }
478
- return d + "Z";
 
 
 
 
 
 
 
 
 
 
 
 
479
  }
480
- const CELL_PATHS = {body: blobPath(270, 175, 226, 144, 1), halo: blobPath(270, 175, 250, 162, 0.8), er: erPath(205, 168, 92, 80)};
481
- const RIBOSOMES = [[120,120],[138,232],[300,120],[316,200],[290,236],[110,200],[160,80],[330,92],[262,262],[420,128],[440,206],[396,262],[96,150],[318,154]];
482
- function cellSVG(p, mini){
483
- const o = (id, inner) => `<g class="org" id="${p}org-${id}" data-sys="${id}" ${mini ? "" : `tabindex="0" role="button" aria-label="${SYS[id]}: steady"`}>${inner}</g>`;
484
- const st = (id, x, y, anchor) => `<text class="cst" id="${p}z-${id}" x="${x}" y="${y}" text-anchor="${anchor||"middle"}"><tspan class="arr"></tspan><tspan class="stt"></tspan></text>`;
485
- const lb = (t, x, y, anchor) => mini ? "" : `<text class="clbl" x="${x}" y="${y}" text-anchor="${anchor||"middle"}">${t}</text>`;
 
 
 
 
 
 
486
  const S = 'stroke="#1C1B18" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"';
487
- const T = 'stroke="#1C1B18" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"';
488
- const dots = RIBOSOMES.map(([x,y]) => `<circle cx="${x}" cy="${y}" r="2.2" fill="#1C1B18" fill-opacity=".55"/>`).join("");
489
- return `<svg viewBox="0 0 540 350" ${mini ? 'aria-hidden="true"' : 'role="group" aria-label="The cell"'} xmlns="http://www.w3.org/2000/svg">
490
- <g id="${p}breath">
491
- ${o("stress_alarm", `<path class="shp" data-kind="stroke" id="${p}shape-stress_alarm" d="${CELL_PATHS.halo}" fill="none" ${S} stroke-dasharray="1 9" stroke-width="3"/>${lb("Stress alarm",516,334,"end")}${st("stress_alarm",516,348,"end")}`)}
492
- ${o("cell_skeleton", `<path class="shp" data-kind="fill" id="${p}shape-cell_skeleton" d="${CELL_PATHS.body}" fill="#FFFCF6" ${S}/>
493
- <path d="M96 120 Q180 146 262 104 M120 250 Q236 222 330 262 M352 66 Q400 120 450 150 M300 300 Q360 286 420 272" fill="none" stroke="#3F6B4C" stroke-opacity=".22" stroke-width="1.5" stroke-linecap="round"/>
494
- <g fill="#F6EFE2" ${T}><path d="M436 222 q18 -8 36 0"/><path d="M432 232 q22 -9 44 0"/><path d="M436 242 q18 -8 36 0"/></g>
495
- ${lb("Skeleton and shape",22,14,"start")}${st("cell_skeleton",22,28,"start")}`)}
496
- ${o("protein_factory", `<path d="${CELL_PATHS.er}" fill="none" stroke="#E4EEE0" stroke-width="16" stroke-linejoin="round"/>
497
- <path class="shp" data-kind="stroke" id="${p}shape-protein_factory" d="${CELL_PATHS.er}" fill="none" stroke="#1C1B18" stroke-width="5" stroke-linecap="round" stroke-dasharray="0 11"/>
498
- ${dots}${lb("Protein factories",172,72,"middle")}${st("protein_factory",172,86,"middle")}`)}
499
- ${o("cell_division", `<circle class="shp" data-kind="fill" id="${p}shape-cell_division" cx="205" cy="168" r="60" fill="#F3ECDF" ${S}/>
500
- <path d="M174 146 C186 134, 214 136, 224 146 M176 196 C186 204, 206 206, 216 198" fill="none" stroke="#1C1B18" stroke-opacity=".3" stroke-width="1.6" stroke-linecap="round"/>
501
- <circle cx="238" cy="198" r="10" fill="#E6D9C2" ${T}/>
502
- ${lb("Cell division",205,166)}${st("cell_division",205,182)}`)}
503
- ${o("message_editing", `<rect class="shp" data-kind="fill" id="${p}shape-message_editing" x="146" y="256" width="118" height="34" rx="17" fill="#FAF6EE" ${S}/>
504
- <path d="M268 262 q6 -6 12 0 t12 0" fill="none" stroke="#1C1B18" stroke-opacity=".5" stroke-width="1.6" stroke-linecap="round"/>${lb("Message editing",205,270)}${st("message_editing",205,284)}`)}
505
- ${o("power_plants", `<g transform="translate(362,214) rotate(-14)"><rect class="shp" data-kind="fill" id="${p}shape-power_plants" x="-50" y="-22" width="100" height="44" rx="22" fill="#FCEFE4" ${S}/>
506
- <rect x="-42" y="-14" width="84" height="28" rx="14" fill="none" stroke="#1C1B18" stroke-opacity=".35" stroke-width="1.4"/>
507
- <path d="M-30 -14 v14 M-18 14 v-16 M-6 -14 v16 M6 14 v-16 M18 -14 v16 M30 14 v-14" fill="none" stroke="#1C1B18" stroke-opacity=".45" stroke-width="1.6" stroke-linecap="round"/></g>
508
- <g transform="translate(118,250) rotate(18)"><rect x="-17" y="-8" width="34" height="16" rx="8" fill="#FCEFE4" ${T}/><path d="M-8 -8 v9 M0 8 v-9 M8 -8 v9" fill="none" stroke="#1C1B18" stroke-opacity=".45" stroke-width="1.3" stroke-linecap="round"/></g>
509
- ${lb("Power plants",362,258)}${st("power_plants",362,272)}`)}
510
- ${o("trash_recycling", `<circle class="shp" data-kind="fill" id="${p}shape-trash_recycling" cx="378" cy="108" r="36" fill="#EAF2E7" ${S}/>
511
- <circle cx="356" cy="90" r="3.5" fill="#FFFCF6" ${T}/><circle cx="398" cy="133" r="3" fill="#FFFCF6" ${T}/>
512
- <circle cx="404" cy="72" r="6" fill="#EAF2E7" ${T}/><circle cx="420" cy="92" r="4.5" fill="#EAF2E7" ${T}/><circle cx="344" cy="78" r="5" fill="#EAF2E7" ${T}/>
513
- ${lb("Recycling",378,106)}${st("trash_recycling",378,121)}`)}
514
- ${o("fuel_metabolism", `<rect class="shp" data-kind="fill" id="${p}shape-fuel_metabolism" x="410" y="152" width="80" height="34" rx="17" fill="#F7F0E0" ${S}/>${lb("Fuel",450,166)}${st("fuel_metabolism",450,180)}`)}
515
- ${o("self_destruct", `<rect class="shp" data-kind="fill" id="${p}shape-self_destruct" x="244" y="44" width="136" height="34" rx="17" fill="#FAF6EE" ${S}/>${lb("Self-destruct switch",312,58)}${st("self_destruct",312,72)}`)}
516
- ${o("immune_signals", `<rect class="shp" data-kind="fill" id="${p}shape-immune_signals" x="34" y="152" width="80" height="34" rx="17" fill="#F2F6EE" ${S}/>${lb("Signals",74,166)}${st("immune_signals",74,180)}`)}
517
- </g></svg>`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
518
  }
519
- const IDLE_FILL = {cell_skeleton:"#FFFCF6", cell_division:"#F3ECDF", power_plants:"#FCEFE4", trash_recycling:"#EAF2E7", fuel_metabolism:"#F7F0E0", immune_signals:"#F2F6EE"};
520
  function colorsFor(dir, strong, kind){
521
  if (kind === "stroke") return dir === "up" ? "#3F6B4C" : "#8A4F2A";
522
- if (kind === "body") return dir === "up" ? (strong ? "#C5DDC7" : "#DFEDDD") : (strong ? "#F8D6C1" : "#FBE4D6");
523
  if (dir === "up") return strong ? "#9CC2A1" : "#C5DDC7";
524
  return strong ? "#F5C3A5" : "#F8D6C1";
525
  }
@@ -560,7 +614,7 @@ function paintCell(p, res, animate){
560
  const finalScale = dir === "up" ? 1.03 : 0.97;
561
  const apply = () => {
562
  if (sh.dataset.kind === "stroke") sh.setAttribute("stroke", colorsFor(dir, strong, "stroke"));
563
- else sh.setAttribute("fill", colorsFor(dir, strong, s.id === "cell_skeleton" ? "body" : "fill"));
564
  g.style.transform = s.id === "cell_skeleton" || s.id === "stress_alarm" ? "" : `scale(${finalScale})`;
565
  };
566
  if (calm){ apply(); setStatus(p, s.id, dir, val); return; }
 
128
  .org:focus{outline:none}
129
  .org:focus-visible .shp{stroke-width:3.5}
130
  .shp{transition:fill .4s ease-out,stroke .4s ease-out}
131
+ .clbl{font:600 13px var(--sans);fill:var(--ink)}
132
+ .cst{font:500 12.5px var(--sans);fill:var(--ink)}
133
  .cst .arr{font-weight:700}
134
+ .lblg{cursor:pointer}
135
+ .lead{stroke:#1C1B18;stroke-opacity:.45;stroke-width:1}
136
+ .lead-dot{fill:#1C1B18}
137
  #breath{transform-box:fill-box;transform-origin:center;animation:breathe 7s ease-in-out infinite alternate}
138
  @keyframes breathe{from{transform:scale(1)}to{transform:scale(1.015)}}
139
+ .drift{animation:drift 11s ease-in-out infinite}
140
+ .drift.d1{animation-name:drift1;animation-duration:9s}
141
+ .drift.d2{animation-name:drift2;animation-duration:12s}
142
+ .drift.d3{animation-name:drift3;animation-duration:14s}
143
+ @keyframes drift1{0%,100%{transform:translate(0,0)}50%{transform:translate(3px,-2px)}}
144
+ @keyframes drift2{0%,100%{transform:translate(0,0)}50%{transform:translate(-2px,3px)}}
145
+ @keyframes drift3{0%,100%{transform:translate(0,0)}33%{transform:translate(2px,2px)}66%{transform:translate(-2px,1px)}}
146
+ body.calm #breath,body.calm .drift{animation:none}
147
  body.calm .shp{transition:none}
148
+ @media (prefers-reduced-motion: reduce){#breath,.drift{animation:none}.shp{transition:none}.card{transition:none}}
149
 
150
  /* System card */
151
  .syscard{position:absolute;left:18px;right:18px;bottom:18px;background:var(--white);border-radius:28px;box-shadow:var(--lift);padding:16px 18px;z-index:5;border:1px solid var(--line)}
 
259
  .controls{border-radius:28px;padding:12px}
260
  .group.lines{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none;max-width:100%}
261
  .clbl,.cst .stt{display:none}
262
+ .cst{font-size:30px}
263
  .story{min-height:420px;padding:18px}
264
  .genes{grid-template-columns:1fr}
265
  .twocol{grid-template-columns:1fr}
 
462
  const motionOff = () => rmq.matches || state.paused;
463
 
464
  /* ---------- The cell drawing ---------- */
465
+ /* ---- Cell drawing (round 3): organelles on an organic body; labels outside on leader lines ---- */
466
+ const CX = 300, CY = 190;
467
+ function wob(t, k){ return 1 + k * (0.030 * Math.sin(3*t + 0.6) + 0.018 * Math.sin(5*t + 2.1) + 0.010 * Math.sin(7*t + 0.3)); }
468
+ function blobPt(t, rx, ry, k, cx, cy){ const r = wob(t, k); return [(cx ?? CX) + rx * r * Math.cos(t), (cy ?? CY) + ry * r * Math.sin(t)]; }
469
+ function blobPath(rx, ry, k){
470
+ const n = 40, pts = [];
471
+ for (let i = 0; i < n; i++) pts.push(blobPt(i / n * Math.PI * 2, rx, ry, k));
 
472
  const f = v => v.toFixed(1);
473
  let d = `M${f(pts[0][0])} ${f(pts[0][1])}`;
474
  for (let i = 0; i < n; i++){
 
477
  }
478
  return d + "Z";
479
  }
480
+ const deg = a => a * Math.PI / 180;
481
+ const NUC = {x:262, y:192, r:66};
482
+ function arcPath(cx, cy, r, a0, a1, wave, n){
483
+ // an open wavy arc (used for the folded ribbons of the protein factories)
484
+ let d = "";
485
  for (let i = 0; i <= n; i++){
486
+ const t = deg(a0 + (a1 - a0) * i / n), rr = r + wave * Math.sin(i / n * Math.PI * 7);
487
+ d += (i ? " L" : "M") + (cx + rr*Math.cos(t)).toFixed(1) + " " + (cy + rr*Math.sin(t)).toFixed(1);
488
  }
489
+ return d;
490
+ }
491
+ function bandPath(cx, cy, r0, r1, a0, a1){
492
+ // a closed crescent band on the nucleus edge (message editing)
493
+ const p = (r, a) => `${(cx + r*Math.cos(deg(a))).toFixed(1)} ${(cy + r*Math.sin(deg(a))).toFixed(1)}`;
494
+ return `M${p(r1,a0)} A${r1} ${r1} 0 0 1 ${p(r1,a1)} A${(r1-r0)/2} ${(r1-r0)/2} 0 0 1 ${p(r0,a1)} A${r0} ${r0} 0 0 0 ${p(r0,a0)} A${(r1-r0)/2} ${(r1-r0)/2} 0 0 1 ${p(r1,a0)}Z`;
495
+ }
496
+ function bean(cx, cy, w, h, rot){
497
+ // one mitochondrion outline (a capsule with a slight waist), in page coordinates
498
+ const a = w/2, b = h/2, c = Math.cos(deg(rot)), sn = Math.sin(deg(rot));
499
+ const P = (x, y) => `${(cx + x*c - y*sn).toFixed(1)} ${(cy + x*sn + y*c).toFixed(1)}`;
500
+ const d = `M${P(-a,0)} C${P(-a,-b*1.15)} ${P(-a*0.2,-b*1.05)} ${P(0,-b*0.8)} C${P(a*0.2,-b*1.05)} ${P(a,-b*1.15)} ${P(a,0)} C${P(a,b*1.15)} ${P(a*0.2,b*1.05)} ${P(0,b*0.8)} C${P(-a*0.2,b*1.05)} ${P(-a,b*1.15)} ${P(-a,0)}Z`;
501
+ return {d, t:`translate(${cx} ${cy}) rotate(${rot})`, w};
502
  }
503
+ function drop(x, y, r){ return `M${x} ${y-r*1.35} C${x+r*0.9} ${y-r*0.4} ${x+r} ${y+r*0.2} ${x+r} ${y+r*0.35} A${r} ${r} 0 0 1 ${x-r} ${y+r*0.35} C${x-r} ${y+r*0.2} ${x-r*0.9} ${y-r*0.4} ${x} ${y-r*1.35}Z`; }
504
+ function circ(x, y, r){ return `M${x-r} ${y} a${r} ${r} 0 1 0 ${2*r} 0 a${r} ${r} 0 1 0 ${-2*r} 0Z`; }
505
+ function hexa(x, y, r){ let d = ""; for (let i = 0; i < 6; i++){ const a = deg(60*i - 90); d += (i ? " L" : "M") + (x + r*Math.cos(a)).toFixed(1) + " " + (y + r*Math.sin(a)).toFixed(1); } return d + "Z"; }
506
+
507
+ const BODY = {rx:190, ry:135, k:1};
508
+ const MITO = [bean(388, 266, 60, 26, -20), bean(438, 228, 48, 22, 32), bean(340, 300, 46, 20, -6)];
509
+ const VESICLES = [[398,122,16],[424,110,10],[416,146,9],[376,102,8],[440,134,6]];
510
+ const DROPS = [[456,168,8],[470,190,6],[450,192,5.5]];
511
+ const RECEPTOR_ANGLES = [150, 168, 186, 204];
512
+ const RIBO_FREE = [[160,140],[176,252],[340,150],[356,206],[330,240],[150,200],[200,96],[372,82],[300,282],[452,120],[408,192],[262,300],[138,170],[236,300],[392,236]];
513
+
514
+ function cellSVG(p){
515
  const S = 'stroke="#1C1B18" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"';
516
+ const T = 'stroke="#1C1B18" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"';
517
+ const o = (id, inner, drift) => `<g class="org" id="${p}org-${id}" data-sys="${id}" tabindex="0" role="button" aria-label="${SYS[id]}: steady"><g class="${drift || ""}">${inner}</g></g>`;
518
+ // Body: interior (rest colour) + membrane band (the reacting shape, two outline lines)
519
+ const outer = blobPath(BODY.rx, BODY.ry, 1), inner = blobPath(BODY.rx - 9, BODY.ry - 9, 1);
520
+ const halo = blobPath(BODY.rx + 22, BODY.ry + 20, 0.9);
521
+ // Protein factories: ribbons round the nucleus; the beads (ribosomes) are the reacting shape
522
+ const er = [arcPath(NUC.x, NUC.y, NUC.r + 20, 196, 338, 3.5, 70), arcPath(NUC.x, NUC.y, NUC.r + 34, 204, 330, 4, 70), arcPath(NUC.x, NUC.y, NUC.r + 48, 214, 318, 4, 60)];
523
+ // Signals: receptors on the membrane
524
+ const rec = RECEPTOR_ANGLES.map(a => {
525
+ const t = deg(a), [x, y] = blobPt(t, BODY.rx, BODY.ry, 1), ux = Math.cos(t), uy = Math.sin(t);
526
+ const sx = x + ux*12, sy = y + uy*12, px = -uy, py = ux;
527
+ return {stem:`M${(x-ux*2).toFixed(1)} ${(y-uy*2).toFixed(1)} L${sx.toFixed(1)} ${sy.toFixed(1)}`,
528
+ head:`M${(sx+px*7).toFixed(1)} ${(sy+py*7).toFixed(1)} Q${(sx+ux*12).toFixed(1)} ${(sy+uy*12).toFixed(1)} ${(sx-px*7).toFixed(1)} ${(sy-py*7).toFixed(1)} Q${(sx+ux*4).toFixed(1)} ${(sy+uy*4).toFixed(1)} ${(sx+px*7).toFixed(1)} ${(sy+py*7).toFixed(1)}Z`};
529
+ });
530
+ const ribo = RIBO_FREE.map(([x,y]) => `<circle cx="${x}" cy="${y}" r="1.9" fill="#1C1B18" fill-opacity=".5"/>`).join("");
531
+ const parts = [
532
+ o("stress_alarm", `<path class="shp" data-kind="stroke" id="${p}shape-stress_alarm" d="${halo}" fill="none" ${S} stroke-dasharray="1 9" stroke-width="3"/>`),
533
+ o("cell_skeleton", `<path d="${outer}" fill="#FFFFFF"/>
534
+ <path d="M150 150 Q220 120 300 140 M170 270 Q250 248 330 276 M360 76 Q410 110 470 150 M120 210 Q150 250 200 286" fill="none" stroke="#1C1B18" stroke-opacity=".12" stroke-width="1.3" stroke-linecap="round"/>
535
+ <g class="drift d3">${ribo}</g>
536
+ <path class="shp" data-kind="fill" id="${p}shape-cell_skeleton" d="${outer} ${inner}" fill-rule="evenodd" fill="#F3EFE6" stroke="#1C1B18" stroke-width="1.6" stroke-linejoin="round"/>`),
537
+ o("protein_factory", `${er.map(d => `<path d="${d}" fill="none" stroke="#1C1B18" stroke-width="11" stroke-linecap="round" stroke-linejoin="round"/><path d="${d}" fill="none" stroke="#F3EFE6" stroke-width="7.4" stroke-linecap="round" stroke-linejoin="round"/>`).join("")}
538
+ <path class="shp" data-kind="stroke" id="${p}shape-protein_factory" d="${er.join(" ")}" fill="none" stroke="#1C1B18" stroke-width="3.6" stroke-linecap="round" stroke-dasharray="0 9"/>`),
539
+ o("cell_division", `<circle class="shp" data-kind="fill" id="${p}shape-cell_division" cx="${NUC.x}" cy="${NUC.y}" r="${NUC.r}" fill="#FAF6EE" ${S}/>
540
+ <circle cx="${NUC.x}" cy="${NUC.y}" r="${NUC.r - 6}" fill="none" stroke="#1C1B18" stroke-opacity=".25" stroke-width="1.2" stroke-dasharray="3 5"/>
541
+ <path d="M228 170 C238 154, 258 160, 252 176 S270 190, 284 180 M236 212 C248 224, 266 220, 272 230 M286 156 C296 162, 300 172, 296 182" fill="none" stroke="#1C1B18" stroke-opacity=".4" stroke-width="1.6" stroke-linecap="round"/>
542
+ <circle cx="${NUC.x + 22}" cy="${NUC.y + 14}" r="14" fill="#EFE6D4" ${T}/><circle cx="${NUC.x + 18}" cy="${NUC.y + 10}" r="4" fill="#E2D5BC"/>`),
543
+ o("message_editing", `<path class="shp" data-kind="fill" id="${p}shape-message_editing" d="${bandPath(NUC.x, NUC.y, NUC.r + 1, NUC.r + 10, 112, 168)}" fill="#F3EFE6" ${S}/>
544
+ <path d="M188 262 q5 -6 10 0 t10 0 t10 0" fill="none" stroke="#1C1B18" stroke-opacity=".55" stroke-width="1.5" stroke-linecap="round"/>`, "drift d2"),
545
+ o("power_plants", `<path class="shp" data-kind="fill" id="${p}shape-power_plants" d="${MITO.map(m => m.d).join(" ")}" fill="#F3EFE6" ${S}/>` + MITO.map(m => `<g transform="${m.t}"><path d="M${(-0.36*m.w).toFixed(1)} -4 l${(0.12*m.w).toFixed(1)} 8 l${(0.12*m.w).toFixed(1)} -8 l${(0.12*m.w).toFixed(1)} 8 l${(0.12*m.w).toFixed(1)} -8 l${(0.12*m.w).toFixed(1)} 8 l${(0.12*m.w).toFixed(1)} -8" fill="none" stroke="#1C1B18" stroke-opacity=".55" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></g>`).join(""), "drift d1"),
546
+ o("trash_recycling", `<path class="shp" data-kind="fill" id="${p}shape-trash_recycling" d="${VESICLES.map(([x,y,r]) => circ(x,y,r)).join(" ")}" fill="#FFFFFF" ${S}/>
547
+ <circle cx="394" cy="118" r="3" fill="#1C1B18" fill-opacity=".35"/><circle cx="404" cy="128" r="2" fill="#1C1B18" fill-opacity=".35"/>`, "drift d2"),
548
+ o("fuel_metabolism", `<path class="shp" data-kind="fill" id="${p}shape-fuel_metabolism" d="${DROPS.map(([x,y,r]) => drop(x,y,r)).join(" ")}" fill="#FAF6EE" ${S}/>`, "drift d3"),
549
+ o("self_destruct", `<path class="shp" data-kind="fill" id="${p}shape-self_destruct" d="${hexa(344, 82, 11)}" fill="#F3EFE6" ${S}/><circle cx="344" cy="82" r="3" fill="#1C1B18"/>`, "drift d1"),
550
+ o("immune_signals", `${rec.map(r => `<path d="${r.stem}" fill="none" ${S}/>`).join("")}<path class="shp" data-kind="fill" id="${p}shape-immune_signals" d="${rec.map(r => r.head).join(" ")}" fill="#FFFFFF" ${S}/>`),
551
+ ];
552
+ // Labels outside the cell, joined by leader lines. Clicking a label opens its system too.
553
+ const L = [
554
+ ["cell_skeleton", 18, 24, "start", blobPt(deg(222), BODY.rx, BODY.ry, 1), [96, 40]],
555
+ ["protein_factory", 200, 24, "middle", [214, 118], [206, 48]],
556
+ ["self_destruct", 360, 24, "middle", [346, 70], [346, 48]],
557
+ ["trash_recycling", 512, 54, "start", [432, 104], [508, 58]],
558
+ ["fuel_metabolism", 512, 150, "start", [476, 178], [508, 154]],
559
+ ["power_plants", 512, 262, "start", [458, 234], [508, 266]],
560
+ ["stress_alarm", 582, 350, "end", blobPt(deg(42), BODY.rx + 22, BODY.ry + 20, 0.9), [520, 340]],
561
+ ["immune_signals", 18, 214, "start", blobPt(deg(186), BODY.rx + 14, BODY.ry + 14, 1), [80, 210]],
562
+ ["cell_division", 18, 128, "start", [NUC.x - 50, NUC.y - 40], [86, 132]],
563
+ ["message_editing", 18, 314, "start", [204, 252], [112, 312]],
564
+ ];
565
+ const labels = L.map(([id, x, y, anc, tip, from]) => `<g class="lblg" data-sys="${id}">
566
+ <path class="lead" d="M${from[0].toFixed(1)} ${from[1].toFixed(1)} L${tip[0].toFixed(1)} ${tip[1].toFixed(1)}" fill="none"/>
567
+ <circle class="lead-dot" cx="${tip[0].toFixed(1)}" cy="${tip[1].toFixed(1)}" r="2.6"/>
568
+ <text class="clbl" x="${x}" y="${y}" text-anchor="${anc}">${SYS[id]}</text>
569
+ <text class="cst" id="${p}z-${id}" x="${x}" y="${y + 15}" text-anchor="${anc}"><tspan class="arr"></tspan><tspan class="stt"></tspan></text></g>`).join("");
570
+ return `<svg viewBox="0 0 600 370" role="group" aria-label="The cell" xmlns="http://www.w3.org/2000/svg">
571
+ <g id="${p}breath">${parts.join("")}</g>
572
+ <g class="labels" aria-hidden="true">${labels}</g></svg>`;
573
  }
574
+ const IDLE_FILL = {cell_skeleton:"#F3EFE6", cell_division:"#FAF6EE", power_plants:"#F3EFE6", trash_recycling:"#FFFFFF", fuel_metabolism:"#FAF6EE", self_destruct:"#F3EFE6", immune_signals:"#FFFFFF", message_editing:"#F3EFE6"};
575
  function colorsFor(dir, strong, kind){
576
  if (kind === "stroke") return dir === "up" ? "#3F6B4C" : "#8A4F2A";
 
577
  if (dir === "up") return strong ? "#9CC2A1" : "#C5DDC7";
578
  return strong ? "#F5C3A5" : "#F8D6C1";
579
  }
 
614
  const finalScale = dir === "up" ? 1.03 : 0.97;
615
  const apply = () => {
616
  if (sh.dataset.kind === "stroke") sh.setAttribute("stroke", colorsFor(dir, strong, "stroke"));
617
+ else sh.setAttribute("fill", colorsFor(dir, strong, "fill"));
618
  g.style.transform = s.id === "cell_skeleton" || s.id === "stress_alarm" ? "" : `scale(${finalScale})`;
619
  };
620
  if (calm){ apply(); setStatus(p, s.id, dir, val); return; }