  *{box-sizing:border-box} html,body{height:100%}
  body{margin:0;font:13.5px/1.45 "Segoe UI",Roboto,Arial,sans-serif;background:#dfe6ec;color:#1c2733;display:flex;flex-direction:column}
  #errBanner{display:none;position:fixed;top:0;left:0;right:0;z-index:999;background:#b71c1c;color:#fff;
    font:12px/1.4 Consolas,monospace;padding:6px 10px;white-space:pre-wrap;max-height:34vh;overflow:auto}
  #topbar{display:flex;align-items:center;gap:6px;padding:7px 10px;background:#263238;color:#fff;flex-wrap:wrap}
  .brand{display:flex;flex-direction:column;line-height:1.05;margin-right:8px;user-select:none}
  .brand b{font-size:16.5px;font-weight:800;letter-spacing:1.5px;color:#fff}
  .brand small{font-size:9.5px;color:#b0bec5;letter-spacing:.4px;margin-top:1px}
  #modeChip{display:none;font:700 11px Consolas,monospace;border-radius:6px;padding:4px 9px}
  #modeChip.fluid{display:inline-block;background:#0b62a4;color:#fff}
  #modeChip.gas{display:inline-block;background:#00695c;color:#fff}
  #statusline{margin-left:auto;font:600 12.5px Consolas,monospace;color:#ffe082;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:34vw}
  #lockChip{display:none;background:#b71c1c;color:#fff;font:700 11.5px Consolas,monospace;border-radius:6px;padding:4px 8px}
  #projNameChip{display:inline-block;font:600 12px "Segoe UI",Roboto,Arial,sans-serif;
    background:#37474f;color:#fff;border-radius:6px;padding:4px 10px;cursor:pointer;
    max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  #projNameChip.empty{background:#b71c1c;animation:bl 1.4s linear infinite}
  #projNameChip:hover{background:#0b62a4}
  button{font:inherit;border:1px solid #90a4ae;background:#eceff1;border-radius:6px;padding:4px 10px;cursor:pointer}
  button:hover{background:#cfd8dc}
  button.primary{background:#0b62a4;border-color:#0b62a4;color:#fff}
  button.stop{background:#c62828;border-color:#c62828;color:#fff}
  button.del{background:#fce4ec;border-color:#e57373;color:#b71c1c}
  /* ---------- unsaved-changes indicator on 💾 Save ---------- */
  #bSave{position:relative}
  #bSave.dirty::after{
    content:'';position:absolute;top:-3px;right:-3px;
    width:9px;height:9px;border-radius:50%;background:#ff9800;
    box-shadow:0 0 5px #ff9800;animation:bl 1.4s linear infinite;
  }
  #topbar .tgl.on{background:#0b62a4;border-color:#0b62a4;color:#fff}
  #bPanel{position:relative}
  #bPanel.atten::after{content:'';position:absolute;top:-4px;right:-4px;width:10px;height:10px;
    border-radius:50%;background:#ff9800;box-shadow:0 0 7px #ff9800;animation:bl 1s linear infinite}
  #zoomPct{font:600 12px Consolas,monospace;color:#fff;background:#37474f;border-radius:6px;padding:4px 8px;cursor:pointer;min-width:52px;text-align:center}
    #exportWrap{position:relative;display:inline-block}
  #exportMenu{display:none;position:absolute;top:100%;right:0;margin-top:4px;background:#fff;
    border:1px solid #b0bec5;border-radius:8px;box-shadow:0 6px 18px rgba(0,0,0,.15);
    padding:6px;z-index:220;flex-direction:column;gap:4px;min-width:190px}
  #exportMenu.open{display:flex}
  #exportMenu button{text-align:left;padding:5px 10px;background:#f5f7f9;border:1px solid #d7dee3;font-size:12.5px}
    #exportMenu button:hover{background:#e3f2fd;border-color:#0b62a4}
  #graphLayer{position:fixed;inset:0;pointer-events:none;z-index:209}
  .graphWin{position:fixed;z-index:210;display:flex;flex-direction:column;
    background:#fff;border:1px solid #b0bec5;border-radius:12px;
    box-shadow:0 10px 30px rgba(0,0,0,.28);
    overflow:hidden;min-width:300px;min-height:200px;pointer-events:auto}
  .graphWin header{flex:0 0 auto;display:flex;align-items:center;gap:8px;padding:7px 10px;
    background:#263238;color:#fff;font:700 12.5px "Segoe UI",Roboto,Arial,sans-serif;
    cursor:move;touch-action:none;user-select:none}
  .graphWin header .gttl{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .graphWin header button{background:#37474f;border-color:#546e7a;color:#fff;padding:2px 9px;font-size:12px;cursor:pointer}
  .graphWin header button:hover{background:#455a64}
  .graphWin header .grng{display:flex;gap:3px;margin-right:4px}
  .graphWin header .grng button{padding:1px 7px;font-size:11px;font-weight:600;opacity:.7}
  .graphWin header .grng button.on{background:#0b62a4;border-color:#0b62a4;opacity:1}
  .graphWin .gwrap{flex:1 1 auto;position:relative;overflow:hidden;background:#fbfcfd;min-height:0}
  .graphWin canvas{display:block;width:100%;height:100%;background:#fbfcfd}
  .graphWin .grsz{position:absolute;right:0;bottom:0;width:16px;height:16px;z-index:3;
    cursor:nwse-resize;touch-action:none;
    background:
      linear-gradient(135deg,transparent 0 45%,#90a4ae 45% 55%,transparent 55% 65%,#90a4ae 65% 75%);
    }
  .graphWin footer{flex:0 0 auto;padding:5px 10px;border-top:1px solid #eceff1;
    font:600 11.5px Consolas,monospace;color:#37474f;background:#fafbfc;
    overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  body.mobile .graphWin{min-width:260px;min-height:190px}
  #modeModal{display:none;position:fixed;inset:0;z-index:200;background:rgba(38,50,56,.72);
    align-items:center;justify-content:center;padding:16px}
  #modeModal.open{display:flex}
  .mCard{background:#fff;border-radius:14px;max-width:560px;width:100%;padding:18px;box-shadow:0 12px 40px rgba(0,0,0,.4)}
  .mCard h2{margin:0 0 4px;color:#0b62a4;font-size:17px}
  .mCard .hint{margin:0 0 12px}
  .mRow{display:flex;gap:10px;flex-wrap:wrap}
  .mOpt{flex:1 1 220px;display:flex;flex-direction:column;align-items:center;gap:4px;text-align:center;
    border:2px solid #cfd8dc;border-radius:12px;padding:14px 10px;background:#fbfcfd;cursor:pointer}
  .mOpt:hover{border-color:#0b62a4;background:#e8f2fb}
  .mOpt .ic{font-size:26px;line-height:1}
  .mOpt b{font-size:14px;color:#263238}
  .mOpt span{font-size:11px;color:#607d8b;line-height:1.3}
  .mEx{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:14px;padding-top:12px;border-top:1px solid #eceff1}
  .mEx span{font-size:11.5px;color:#607d8b}
  #mCancel{margin-top:12px;float:right}
  #main{flex:1;display:flex;min-height:0}
  #palette{width:178px;background:#fff;border-right:1px solid #cfd8dc;overflow-y:auto;padding:8px;display:flex;flex-direction:column;gap:6px}
  #palette h4{margin:6px 0 2px;font-size:10.5px;letter-spacing:.08em;text-transform:uppercase;color:#78909c;border-bottom:1px solid #eceff1;padding-bottom:2px}
  .pitem{display:flex;align-items:center;gap:8px;border:1px solid #d7dee3;border-radius:8px;padding:4px 7px;background:#fbfcfd;cursor:grab;user-select:none}
  .pitem:hover{border-color:#0b62a4;box-shadow:0 0 0 2px #e3f2fd}
  .pitem svg{flex:0 0 34px}
  .pitem span{font-size:10.8px;font-weight:600;line-height:1.15}
  .vgrid{display:grid;grid-template-columns:1fr 1fr;gap:4px}
  .vgrid .pitem{flex-direction:column;gap:2px;padding:4px 2px;text-align:center}
  .vgrid .pitem svg{flex:0 0 auto}
  .vgrid .pitem span{font-size:9px}
  body:not(.mobile).hidePalette #palette{display:none}
  body:not(.mobile).hideRight #right{display:none}
  #cwrap{flex:1;position:relative;background:#fff;min-width:0;overflow:hidden;touch-action:none}
  #cv{position:absolute;inset:0;width:100%;height:100%;touch-action:none;cursor:grab}
  #cv.panning{cursor:grabbing}
  #cv.picking{cursor:crosshair!important}
  text{user-select:none;pointer-events:none}
  /* ---- labels: white halo so tags / names / readings stay readable over any shape or pipe ---- */
  .lbl,.small,.pname,.lvtxt,.statTxt,.dmgTxt{
    paint-order:stroke;
    stroke:#ffffff;
    stroke-width:2.6px;
    stroke-linejoin:round;
    stroke-linecap:round;
  }
  .pipe{stroke:#2b2b2b;stroke-width:2;fill:none;vector-effect:non-scaling-stroke}
  .stub{stroke:#2b2b2b;stroke-width:2;vector-effect:non-scaling-stroke}
  .flowov{stroke-width:5;fill:none;stroke-linecap:round;stroke-linejoin:round;opacity:0;pointer-events:none;vector-effect:non-scaling-stroke}
  .farrow{opacity:0;pointer-events:none}
  .ehit{stroke:transparent;stroke-width:17;cursor:pointer;fill:none}
  .ehit:hover{stroke:rgba(11,98,164,.25)}
  g.edge.selected .pipe{stroke:#0b62a4;stroke-width:3.4}
  .shape{stroke:#2b2b2b;stroke-width:1.8}
  .node{cursor:grab}
  .node.dragging{cursor:grabbing}
  .node:hover .shape{stroke:#0b62a4}
  .node.selected{filter:drop-shadow(0 0 5px #0b62a4)}
  .node.act{filter:drop-shadow(0 0 6px rgba(21,101,192,.85))}
  .node.selected.act{filter:drop-shadow(0 0 6px rgba(21,101,192,.85)) drop-shadow(0 0 3px #0b62a4)}
  .node.violErr{filter:drop-shadow(0 0 7px #e53935)!important}
  .node.violWarn{filter:drop-shadow(0 0 6px #ff9800)!important}
  .node.damaged{filter:grayscale(1) drop-shadow(0 0 5px #e53935)!important}
  .node.damaged .shape{stroke:#b71c1c}
  .port{fill:#fff;stroke:#0b62a4;stroke-width:1.7;cursor:crosshair;pointer-events:all}
  .port:hover{fill:#0b62a4}
  body.running .port{display:none}
  body.running .node{cursor:pointer}
  body.running #cv{cursor:default}
  .lbl{font-size:11px;font-weight:600;text-anchor:middle;fill:#1c2733}
  .small{font-size:8.8px;fill:#555;text-anchor:middle}
  .pname{font-size:9px;font-style:italic;font-weight:700;fill:#00695c;text-anchor:middle}
  .lvtxt{font:600 9.5px Consolas,monospace;fill:#0b62a4;text-anchor:middle}
  .statTxt{font-size:9px;font-weight:700;text-anchor:middle}
  .dmgTxt{font:700 9px Consolas,monospace;fill:#c62828;text-anchor:middle}
  .dmgStamp{font:800 10px Consolas,monospace;fill:#fff;text-anchor:middle}
  .bl{animation:bl 1s linear infinite}
  @keyframes bl{50%{opacity:.15}}
  #linkPrev{stroke:#0b62a4;stroke-width:2;stroke-dasharray:6 5;opacity:0;pointer-events:none}
  #gBadge{cursor:pointer}
  #gBadge:hover circle{fill:#c62828}
  #right{width:302px;background:#fff;border-left:1px solid #cfd8dc;overflow-y:auto;padding:10px;display:flex;flex-direction:column;gap:10px}
  #right h3{margin:0 0 6px;font-size:12.5px;color:#0b62a4}
  .rClose{display:none}
  .card{border:1px solid #e0e6ea;border-radius:9px;padding:8px 9px;background:#fbfcfd}
  .card summary{cursor:pointer;font-size:12.5px;font-weight:700;color:#0b62a4;margin:-2px 0 6px;list-style:none;user-select:none}
  .card summary::-webkit-details-marker{display:none}
  .card summary::after{content:'▾';float:right;color:#90a4ae;font-size:11px}
  .card:not([open]) summary{margin-bottom:0}
  .row{display:flex;justify-content:space-between;align-items:center;gap:6px;margin:5px 0}
  .row label{font-size:11.5px;color:#546e7a}
  .row input[type=text],.row input[type=number],.row select{font:inherit;padding:2px 5px;border:1px solid #b0bec5;border-radius:5px;width:140px}
  .row select{max-width:170px}
  .lv{font:600 12px Consolas,monospace;color:#1b5e20}
  .hint{font-size:11.5px;color:#607d8b}
  .locknote{font-size:11.5px;font-weight:700;color:#b71c1c;background:#fdf2f2;border:1px solid #f2c4c4;border-radius:7px;padding:5px 7px;margin-bottom:6px}
  .crow{display:flex;align-items:center;gap:7px;margin:5px 0}
  .crow .cnm{flex:1;font:600 11.5px Consolas,monospace;color:#37474f;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:pointer}
  .crow input[type=range]{width:70px}
  .crow .pv{font:600 10px Consolas,monospace;color:#0b62a4;width:44px;text-align:right}
  .crow .sw{position:relative;width:36px;height:19px;flex:0 0 36px}
  .crow .sw input{position:absolute;inset:0;width:100%;height:100%;appearance:none;background:#b0bec5;border-radius:10px;cursor:pointer;transition:.2s;margin:0}
  .crow .sw input:checked{background:#43a047}
  .crow .sw input::after{content:'';position:absolute;top:2px;left:2px;width:15px;height:15px;background:#fff;border-radius:50%;transition:.2s}
  .crow .sw input:checked::after{left:19px}
  #metrics div{display:flex;justify-content:space-between;font-size:12px;margin:2px 0}
  #metrics span{font-family:Consolas,monospace;font-weight:600}
  #log{height:120px;overflow-y:auto;font-size:11px;display:flex;flex-direction:column;gap:3px}
  #log .ln{border-left:3px solid #bbb;padding:1px 6px;background:#fff}
  #log .ln span{color:#889;font-family:Consolas,monospace;margin-right:5px}
  #log .bad{border-color:#c62828;background:#fdf2f2}
  #log .warn{border-color:#e0a000;background:#fffaf0}
  #log .good{border-color:#2e9e44;background:#f2fbf4}
  #review{display:flex;flex-direction:column;gap:3px;max-height:240px;overflow-y:auto}
  #review .ln{cursor:pointer}
  #review .ln:hover{outline:1px solid #90a4ae}
  details{font-size:11.5px}.details li{margin:3px 0}
  .fab{display:none;position:fixed;left:12px;bottom:12px;z-index:60;padding:9px 14px;border-radius:24px;box-shadow:0 3px 10px rgba(0,0,0,.3)}
  .fab2{display:none;position:fixed;right:12px;bottom:12px;z-index:60;padding:9px 14px;border-radius:24px;box-shadow:0 3px 10px rgba(0,0,0,.3)}
  body.mobile .fab,body.mobile .fab2{display:block}
  body.mobile #palette{position:fixed;left:0;right:0;bottom:0;top:auto;width:auto;max-height:46vh;z-index:50;
    border-right:none;border-top:1px solid #cfd8dc;box-shadow:0 -6px 24px rgba(0,0,0,.22);
    display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));align-content:start;
    transform:translateY(105%);transition:transform .25s}
  body.mobile #palette.open{transform:none}
  body.mobile #palette h4{grid-column:1/-1;margin:4px 0 2px}
  body.mobile .vgrid{display:contents}
  /* ---------- palette filter ---------- */
  #palSearchWrap{display:flex;gap:4px;align-items:center;padding-bottom:6px;
    border-bottom:1px solid #eceff1}
  #palSearch{flex:1;font:inherit;font-size:12px;padding:4px 8px;
    border:1px solid #b0bec5;border-radius:6px;background:#f5f7f9;
    color:#1c2733;min-width:0}
  #palSearch::placeholder{color:#90a4ae}
  #palSearch:focus{outline:none;border-color:#0b62a4;background:#fff}
  #palSearchClear{background:#eceff1;border:1px solid #cfd8dc;color:#546e7a;
    border-radius:5px;padding:3px 7px;font-size:11px;cursor:pointer;display:none}
  #palSearchClear:hover{background:#cfd8dc;color:#263238}
  #palSearchWrap.hasText #palSearchClear{display:block}
  #palNone{display:none;text-align:center;color:#90a4ae;font-size:11.5px;
    padding:10px 6px}
  .pitem.palHide,#palette h4.palHide{display:none!important}
  body.mobile #palSearchWrap{grid-column:1/-1}
  body.mobile #palNone{grid-column:1/-1}
  body.mobile #right{position:fixed;top:0;right:0;bottom:0;width:min(88vw,330px);z-index:50;
    box-shadow:-6px 0 24px rgba(0,0,0,.25);transform:translateX(105%);transition:transform .25s}
  body.mobile #right.open{transform:none}
  body.mobile .rClose{display:block;position:absolute;top:8px;right:8px;z-index:5;
    background:#eceff1;border:1px solid #b0bec5;border-radius:16px;padding:3px 11px;font-weight:700;color:#546e7a}
  body.mobile #topbar button{padding:3px 7px;font-size:12px}
  body.mobile #statusline{max-width:100%;width:100%;order:9;margin-left:0}
  body.mobile .brand b{font-size:14px;letter-spacing:1px}
  body.mobile .brand small{font-size:8.5px}
  /* ---------- undo / redo + shortcuts dialog ---------- */
  #topbar button:disabled{opacity:.4;cursor:default;background:#eceff1;border-color:#90a4ae;color:#546e7a}
  #topbar button:disabled:hover{background:#eceff1}
  #keysModal{display:none;position:fixed;inset:0;z-index:220;background:rgba(38,50,56,.72);
    align-items:center;justify-content:center;padding:16px}
  #keysModal.open{display:flex}
  .keysTbl{width:100%;border-collapse:collapse;font-size:12px;margin-top:4px}
  .keysTbl td{padding:5px 8px;border-bottom:1px solid #eceff1;vertical-align:top}
  .keysTbl tr:last-child td{border-bottom:none}
  .keysTbl td:first-child{font-family:Consolas,monospace;font-weight:700;color:#0b62a4;
    white-space:nowrap;width:40%}
  /* ---------- component search ---------- */
  #searchWrap{position:relative;display:inline-block}
  #searchInp{font:inherit;padding:4px 9px;border:1px solid #90a4ae;border-radius:6px;
    background:#eceff1;color:#1c2733;width:180px}
  #searchInp::placeholder{color:#78909c}
  #searchInp:focus{outline:none;border-color:#0b62a4;background:#fff}
  #searchMenu{display:none;position:absolute;top:100%;right:0;margin-top:4px;background:#fff;
    border:1px solid #b0bec5;border-radius:8px;box-shadow:0 6px 18px rgba(0,0,0,.18);
    min-width:250px;max-height:320px;overflow-y:auto;z-index:230}
  #searchMenu.open{display:block}
  #searchMenu .sr{padding:5px 10px;cursor:pointer;font-size:12px;
    display:flex;justify-content:space-between;gap:10px;align-items:center}
  #searchMenu .sr:hover,#searchMenu .sr.active{background:#e3f2fd}
  #searchMenu .sr b{font-family:Consolas,monospace;color:#0b62a4;font-size:12.5px}
  #searchMenu .sr span{color:#607d8b;font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  #searchMenu .srNone{padding:8px 10px;color:#90a4ae;font-size:11.5px}
  .node.searchHit .shape{stroke:#ff9800!important;stroke-width:3!important}
  body.mobile #searchInp{width:130px}
  /* ---------- mobile toolbar collapse ---------- */
  /* The ☰ button is only shown on mobile. On desktop it stays hidden and
     the toolbar keeps every control visible, exactly as before. */
  #bTb{display:none;background:#37474f;border:1px solid #546e7a;color:#fff;
    font-weight:700;padding:4px 10px}
  #bTb:hover{background:#455a64}
  body.mobile #bTb{display:inline-block}
  body.mobile.tbOpen #bTb{background:#0b62a4;border-color:#0b62a4}
  /* On mobile, while the toolbar is collapsed, hide every direct child of
     #topbar except: the ALSIMU brand, the mode chip, the edit-lock chip,
     the RUN/PAUSE button, the toggle itself, and the status line. Parts,
     Panel, Check, New, Undo/Redo, Load Example, Save, Export, Load, Web,
     Elbow pipes, zoom, Fit, Reset, Speed, Mobile layout and Search are all
     hidden until the user taps ☰. */
  body.mobile:not(.tbOpen) #topbar > *:not(.brand):not(#modeChip):not(#lockChip):not(#alarmChip):not(#bRun):not(#bTb):not(#statusline){
  display:none!important;
}
  /* ---------- teaching example bank ---------- */
  .mCard.mCardWide{max-width:900px;max-height:92vh;overflow-y:auto}
  .bankTitle{margin:20px 0 4px;font-size:15px;color:#0b62a4;
    border-top:1px solid #eceff1;padding-top:14px;
    display:flex;align-items:baseline;gap:8px;flex-wrap:wrap}
  .bankTitle .bankCount{font-size:11.5px;font-weight:400;color:#607d8b}
  .exBank{display:grid;grid-template-columns:repeat(auto-fill,minmax(250px,1fr));
    gap:8px;margin-top:10px}
  .exCard{display:flex;gap:10px;align-items:flex-start;text-align:left;
    border:1px solid #d7dee3;border-radius:10px;padding:10px 12px;
    background:#fbfcfd;cursor:pointer;font:inherit;color:inherit;
    transition:border-color .12s,background .12s,box-shadow .12s}
  .exCard:hover{border-color:#0b62a4;background:#e8f2fb;box-shadow:0 0 0 2px #e3f2fd}
  .exCard:focus{outline:none;border-color:#0b62a4;box-shadow:0 0 0 2px #e3f2fd}
  .exCard .exIc{font-size:22px;line-height:1;flex:0 0 auto;margin-top:2px}
  .exCard .exBody{flex:1;min-width:0}
  .exCard b{display:block;font-size:12.5px;color:#263238;margin-bottom:2px}
  .exCard .exDesc{display:block;font-size:11px;color:#546e7a;line-height:1.35;
    margin-bottom:5px}
  .exCard .exTag{display:inline-block;font:700 9px Consolas,monospace;
    color:#0b62a4;background:#e3f2fd;border-radius:3px;
    padding:1px 5px;margin-right:3px;text-transform:uppercase;letter-spacing:.04em}
  @media (max-width:560px){
    .mCard.mCardWide{max-width:100%;padding:14px;max-height:96vh}
    .exBank{grid-template-columns:1fr}
  }

  #view3d{position:fixed;inset:0;z-index:300;background:#0b1218}
#view3d canvas{display:block;width:100%;height:100%;}
  #v3-loading{position:absolute;inset:0;z-index:4;
              display:flex;align-items:center;justify-content:center;
              flex-direction:column;gap:16px;
              color:#b0bec5;background:#0b1218;
              font:600 13px "Segoe UI",Roboto,Arial,sans-serif;
              transition:opacity .30s ease}
  #view3d.on #v3-loading{opacity:0;pointer-events:none}
  .v3-spin{width:40px;height:40px;border-radius:50%;
           border:3px solid #263238;border-top-color:#4fc3f7;
           animation:v3spin .9s linear infinite}
  .v3-spin-txt{letter-spacing:.05em;color:#90a4ae;font-size:12.5px}
  @keyframes v3spin{to{transform:rotate(360deg)}}
.v3-bar{position:absolute;top:10px;left:10px;z-index:2;display:flex;gap:6px;
        align-items:center;flex-wrap:wrap}
.v3-bar button{background:#1e2a35;border:1px solid #37474f;color:#e0e6ea;
        padding:5px 12px;border-radius:6px;cursor:pointer;font:inherit}
.v3-bar button:hover{background:#263238}
.v3-bar button.v3-primary{background:#0b62a4;border-color:#0b62a4;color:#fff}
.v3-bar button.v3-primary:hover{background:#0d7bd0}
.v3-bar button.v3-stop{background:#c62828;border-color:#c62828;color:#fff}
.v3-status{font:600 12px Consolas,monospace;color:#90a4ae;
           padding:4px 10px;border-radius:6px;background:#1e2a35;
           border:1px solid #37474f;min-width:70px;text-align:center}
.v3-status.on{color:#69f0ae;border-color:#2e7d32;background:#12261a}
.v3-hint{color:#90a4ae;font-size:12px;margin-left:10px}
#v3-panel{
  position:absolute;top:64px;right:14px;bottom:14px;width:260px;z-index:3;
  background:rgba(20,28,36,.94);border:1px solid #37474f;border-radius:10px;
  box-shadow:0 8px 26px rgba(0,0,0,.45);
  padding:10px;color:#e0e6ea;overflow-y:auto;
  font:12.5px "Segoe UI",Roboto,Arial,sans-serif;
  transition:height .2s;
}
#v3-panel.collapsed{height:38px;bottom:auto;overflow:hidden}
#v3-panel-head{
  display:flex;align-items:center;justify-content:space-between;
  font-weight:700;color:#0b62a4;margin:-2px 0 8px;
  border-bottom:1px solid #37474f;padding-bottom:6px;
}
#v3-panel-head button{
  background:transparent;border:1px solid #455a64;color:#b0bec5;
  border-radius:5px;padding:1px 8px;cursor:pointer;font-size:12px;
}
#v3-panel-head button:hover{background:#263238}
#v3-ctrl .v3-row{
  display:flex;align-items:center;gap:8px;padding:5px 0;
  border-bottom:1px solid #263238;
}
#v3-ctrl .v3-row:last-child{border-bottom:none}
#v3-ctrl .v3-nm{
  flex:1;font:600 11.5px Consolas,monospace;color:#b0bec5;
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:pointer;
}
#v3-ctrl .v3-nm:hover{color:#e0e6ea}
#v3-ctrl .v3-btn{
  font:600 11px Consolas,monospace;padding:3px 10px;border-radius:5px;
  cursor:pointer;border:1px solid transparent;color:#fff;min-width:62px;
  text-align:center;
}
#v3-ctrl .v3-btn.on  {background:#2e7d32;border-color:#2e7d32}
#v3-ctrl .v3-btn.off {background:#455a64;border-color:#455a64}
#v3-ctrl .v3-btn.auto{background:#37474f;border-color:#37474f;color:#90a4ae;cursor:default}
#v3-ctrl .v3-btn.bad {background:#b71c1c;border-color:#b71c1c;cursor:not-allowed}
#v3-ctrl .v3-empty{color:#90a4ae;padding:8px 0}

/* ---------- virtual joystick (walk mode, touch devices only) ------- */
#v3-joy{
  position:absolute;
  left:22px;
  bottom:22px;
  width:130px;
  height:130px;
  z-index:6;
  display:none;               /* shown by enableFly() on touch only */
  touch-action:none;
  user-select:none;
  -webkit-user-select:none;
  -webkit-tap-highlight-color:transparent;
}
#v3-joy .v3-joy-base{
  position:absolute;
  inset:0;
  border-radius:50%;
  background:radial-gradient(circle at 50% 45%,
              rgba(40,55,70,0.65), rgba(20,30,40,0.75));
  border:2px solid rgba(176,190,197,0.55);
  box-shadow:0 8px 20px rgba(0,0,0,0.45),
             inset 0 0 14px rgba(0,0,0,0.35);
  backdrop-filter:blur(4px);
  -webkit-backdrop-filter:blur(4px);
}
#v3-joy .v3-joy-knob{
  position:absolute;
  left:50%;
  top:50%;
  width:56px;
  height:56px;
  margin-left:-28px;
  margin-top:-28px;
  border-radius:50%;
  background:radial-gradient(circle at 40% 35%,
              #4fc3f7, #0b62a4 75%);
  border:2px solid #b3e5fc;
  box-shadow:0 4px 14px rgba(0,0,0,0.5),
             inset 0 0 6px rgba(255,255,255,0.4);
  pointer-events:none;
  transition:transform 0.04s linear;
  will-change:transform;
}
#v3-joy-actions{
  position:absolute;
  right:22px;
  bottom:22px;
  z-index:6;
  display:none;               /* shown by enableFly() on touch only */
  flex-direction:column;
  gap:10px;
  touch-action:none;
  user-select:none;
  -webkit-user-select:none;
}
#v3-joy-actions button{
  width:62px;
  height:62px;
  padding:0;
  border-radius:50%;
  font-size:22px;
  line-height:1;
  background:radial-gradient(circle at 50% 45%,
              rgba(40,55,70,0.75), rgba(20,30,40,0.85));
  border:2px solid rgba(176,190,197,0.55);
  color:#e0e6ea;
  box-shadow:0 6px 16px rgba(0,0,0,0.45);
  backdrop-filter:blur(4px);
  -webkit-backdrop-filter:blur(4px);
  touch-action:none;
  -webkit-tap-highlight-color:transparent;
}
#v3-joy-actions button.v3-hold,
#v3-joy-actions button:active{
  background:radial-gradient(circle at 50% 40%,
              #4fc3f7, #0b62a4 75%);
  border-color:#b3e5fc;
  color:#fff;
}

/* In landscape on a short phone the toolbar can wrap and the joystick
   can collide with the panel. Shrink both so the whole scene stays
   usable without the operator having to zoom. */
/* ============================================================
   Mobile / touch tuning for the 3D overlay
   ------------------------------------------------------------
   On touch devices the toolbar becomes a single floating pill
   with a translucent background, wrapping cleanly to at most
   two rows. The redundant "Iso" button is dropped (Fit already
   does iso) and the desktop-only hint text is hidden. The
   controls panel is repositioned below the pill and capped so
   it never touches the joystick area at the bottom of the
   screen.
   ============================================================ */
@media (pointer:coarse){

  /* ----- toolbar: a floating pill ----- */
  .v3-bar{
    top:10px; left:10px; right:auto;
    max-width:calc(100vw - 20px);
    box-sizing:border-box;
    padding:6px;
    gap:5px;
    background:rgba(20,28,36,.88);
    border:1px solid #37474f;
    border-radius:14px;
    box-shadow:0 8px 22px rgba(0,0,0,.45);
    backdrop-filter:blur(8px);
    -webkit-backdrop-filter:blur(8px);
  }
  .v3-bar button{
    padding:6px 10px;
    font-size:12.5px;
    border-radius:8px;
    min-height:34px;
    flex-shrink:0;
  }
  .v3-bar button.v3-primary,
  .v3-bar button.v3-stop{
    padding-left:14px;
    padding-right:14px;
    font-weight:700;
  }
  /* Fit already lands on iso — the separate Iso button is
     redundant on a phone and just adds clutter. */
  #v3-iso{display:none;}
  /* Desktop-only guidance text. */
  .v3-hint{display:none;}

  /* Status chip is right-aligned inside the pill. */
  .v3-status{
    margin-left:auto;
    min-width:auto;
    padding:5px 10px;
  }

  /* ----- controls panel: sits below the pill -----
     Top is set just past the tallest possible pill (two rows of
     34 px buttons + 6 px padding + 10 px top margin) so the panel
     never overlaps the toolbar. Bottom is deliberately unset
     rather than pinned, so a long list scrolls inside the panel
     rather than pushing itself under the joystick. */
  #v3-panel{
    top:100px;
    right:10px;
    bottom:auto;
    max-height:calc(100vh - 220px);
    width:min(78vw, 240px);
    border-radius:12px;
  }
  #v3-panel.collapsed{
    height:auto;
    bottom:auto;
    max-height:44px;
  }
}

/* Landscape on a short phone: shrink everything one notch. */
@media (max-height:480px) and (pointer:coarse){
  .v3-bar{top:6px;left:6px;padding:4px;gap:4px;border-radius:10px;}
  .v3-bar button{padding:5px 8px;font-size:11.5px;min-height:30px;}
  #v3-panel{top:80px;width:min(70vw,200px);max-height:calc(100vh - 160px);}

  #v3-joy{width:104px;height:104px;left:14px;bottom:14px;}
  #v3-joy .v3-joy-knob{width:44px;height:44px;margin-left:-22px;margin-top:-22px;}
  #v3-joy-actions{right:14px;bottom:14px;gap:8px;}
  #v3-joy-actions button{width:52px;height:52px;font-size:18px;}
}

/* Narrow non-touch windows get the same pill, without the touch
   joystick rules. */
@media (max-width:640px) and (pointer:fine){
  .v3-bar{
    top:8px; left:8px; right:8px;
    box-sizing:border-box;
    max-width:calc(100vw - 16px);
    padding:6px;
    gap:6px;
    background:rgba(20,28,36,.88);
    border:1px solid #37474f;
    border-radius:12px;
  }
  .v3-hint{display:none;}
  #v3-panel{top:100px;}
}

/* ---------- multi-drive list inside the controller inspector ------ */
.ctrlDriveList{display:flex;flex-direction:column;gap:2px;max-width:170px}
.ctrlDriveRow{display:flex;align-items:center;gap:4px;justify-content:flex-end}
.ctrlDriveRow .lv{flex:1;text-align:right;
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
  font-size:10.5px}
.ctrlDriveRm{
  flex:0 0 auto;
  font:700 10px Consolas,monospace;
  width:16px;height:16px;padding:0;line-height:1;
  border-radius:50%;
  background:#fce4ec;border:1px solid #e57373;color:#b71c1c;
  cursor:pointer;
}
.ctrlDriveRm:hover{background:#e57373;color:#fff}


/* ---------- About-the-project link inside the About card ---------- */
.aboutLink{
  display:flex;align-items:flex-start;gap:10px;
  margin:4px 0 10px;
  padding:10px 12px;
  border-radius:9px;
  background:linear-gradient(135deg,#e8f2fb,#f5f9fc);
  border:1px solid #cfe4f5;
  color:inherit;text-decoration:none;
  transition:border-color .15s, background .15s, transform .12s;
}
.aboutLink:hover{
  border-color:#0b62a4;
  background:linear-gradient(135deg,#dbeeff,#eef7ff);
  text-decoration:none;
  transform:translateY(-1px);
}
.aboutLinkIc{
  flex:0 0 auto;
  width:30px;height:30px;border-radius:8px;
  background:#0b62a4;color:#fff;
  display:inline-flex;align-items:center;justify-content:center;
  font-size:15px;
}
.aboutLinkBody{flex:1;min-width:0;line-height:1.35}
.aboutLinkBody b{display:block;font-size:12.5px;color:#0b62a4;margin-bottom:2px}
.aboutLinkBody small{display:block;font-size:11.5px;color:#455a64;line-height:1.45}

/* ====================================================================
   ALARM UI — ISA-5.1 / ISA-18.2
   --------------------------------------------------------------------
   Every element here is driven by state that the alarm engine writes
   onto the DOM: the topbar chip, the floating banner, the alarm card
   in the sidebar, and two classes on the node group that own the
   pulse and the colour override.
   ==================================================================== */

/* ---- topbar chip ---- */
#alarmChip{
  display:none;
  align-items:center;gap:6px;
  background:#c62828;color:#fff;
  font:700 11.5px Consolas,monospace;
  border-radius:6px;padding:4px 10px;
  cursor:pointer;user-select:none;
  border:1px solid #b71c1c;
  pointer-events:auto;         /* explicit — never let an ancestor rule disable it */
  animation:alarmChipPulse 0.9s ease-in-out infinite;
}
#alarmChip.show{display:inline-flex}
#alarmChip.acked{background:#e65100;border-color:#bf360c;animation:none}
#alarmChip .dot{
  width:7px;height:7px;border-radius:50%;background:#fff;
  animation:bl 0.8s linear infinite;
}
#alarmChip.acked .dot{animation:none;background:#ffe0b2}
@keyframes alarmChipPulse{
  0%,100%{ box-shadow:0 0 0 rgba(229,57,53,0); }
  50%    { box-shadow:0 0 10px rgba(229,57,53,.9); }
}

/* ---- floating banner over the canvas ---- */
#alarmBanner{
  display:none;
  position:absolute;top:0;left:50%;transform:translateX(-50%);
  background:linear-gradient(180deg,#c62828,#8e0000);
  color:#fff;font:700 12.5px Consolas,monospace;
  padding:7px 20px;border-radius:0 0 10px 10px;
  box-shadow:0 4px 14px rgba(0,0,0,.35);
  z-index:300;                 /* was 100 — above the SVG canvas and any open graph */
  cursor:pointer;
  pointer-events:auto;         /* explicit — never let an ancestor rule disable it */
  white-space:nowrap;max-width:92vw;overflow:hidden;
  text-overflow:ellipsis;
  animation:alarmBannerPulse 0.9s ease-in-out infinite;
}
#alarmBanner.show{display:block}
#alarmBanner.acked{
  animation:none;
  background:linear-gradient(180deg,#e65100,#bf360c);
}
@keyframes alarmBannerPulse{
  0%,100%{ box-shadow:0 4px 14px rgba(0,0,0,.35), 0 0 0 rgba(229,57,53,0); }
  50%    { box-shadow:0 4px 14px rgba(0,0,0,.35), 0 0 26px rgba(229,57,53,.9); }
}

/* ---- node-level alarm state (SVG) ---- */
.node.alarmActive{
  animation:alarmNodePulse 0.9s ease-in-out infinite;
}
.node.alarmActive .shape{ stroke:#e53935 !important; stroke-width:2.4 !important; }
.node.alarmAck{
  filter:drop-shadow(0 0 7px #c62828);
}
.node.alarmAck .shape{ stroke:#c62828 !important; stroke-width:2.2 !important; }
@keyframes alarmNodePulse{
  0%,100%{ filter:drop-shadow(0 0 4px #e53935); }
  50%    { filter:drop-shadow(0 0 14px #ff5252); }
}

/* ---- sidebar alarm card ---- */
#alarmList{display:flex;flex-direction:column;gap:3px;max-height:280px;overflow-y:auto}
#alarmList .noAlarms{
  color:#78909c;font-size:11.5px;padding:10px 6px;text-align:center;
}
#alarmList .alm{
  display:flex;align-items:center;gap:6px;
  padding:5px 7px;
  border-left:4px solid #c62828;
  background:#fdf2f2;
  border-radius:0 6px 6px 0;
  font-size:11.5px;
}
#alarmList .alm.p1{ border-color:#b71c1c; background:#fbe9e7; }
#alarmList .alm.p2{ border-color:#e65100; background:#fff3e0; }
#alarmList .alm.p3{ border-color:#f9a825; background:#fffde7; }
#alarmList .alm.p4{ border-color:#66bb6a; background:#f1f8e9; }
#alarmList .alm.ack{ opacity:0.65; border-left-style:dashed; }
#alarmList .alm .n{
  flex:1;font-family:Consolas,monospace;font-weight:700;
  color:#1c2733;
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
  cursor:pointer;
}
#alarmList .alm .n:hover{ color:#0b62a4; text-decoration:underline; }
#alarmList .alm .v{
  font-family:Consolas,monospace;font-size:10.5px;color:#455a64;
  white-space:nowrap;
}
#alarmList .alm button.ackbtn{
  background:#c62828;border:none;color:#fff;border-radius:4px;
  font:700 10px Consolas,monospace;padding:2px 7px;cursor:pointer;
}
#alarmList .alm button.ackbtn:hover{ background:#b71c1c; }
#alarmList .alm.ack button.ackbtn{
  background:#546e7a;cursor:default;
}

/* ====================================================================
   In-3D alarm rows (mirrors the 2D sidebar alarm card)
   --------------------------------------------------------------------
   One row per active alarm, drawn inside #v3-ctrl. Priorities 1–4 use
   the same colour ramp as the 2D card. Unacknowledged rows pulse;
   acknowledged rows are dimmed and dashed on the left edge — exactly
   the ISA-18.2 visual convention the 2D panel already uses.
   ==================================================================== */
#v3-ctrl .v3-alarm-head{
  display:flex;align-items:center;justify-content:space-between;
  gap:8px;
  padding:4px 0 6px;
  margin:-2px 0 4px;
  border-bottom:1px solid #37474f;
  font-weight:700;color:#ff8a80;
  font-size:12px;letter-spacing:.02em;
}
#v3-ctrl .v3-alarm-ackall{
  background:#b71c1c;border:1px solid #e53935;color:#fff;
  border-radius:5px;padding:3px 10px;
  font:700 10.5px Consolas,monospace;
  cursor:pointer;flex-shrink:0;
}
#v3-ctrl .v3-alarm-ackall:hover{ background:#e53935; border-color:#ff5252; }
#v3-ctrl .v3-alarm-ackall:active{ transform:translateY(1px); }

#v3-ctrl .v3-alarm-row{
  display:flex;align-items:center;gap:6px;
  padding:5px 7px;margin:2px 0;
  border-left:3px solid #c62828;
  background:rgba(198,40,40,0.10);
  border-radius:0 6px 6px 0;
  font-size:11.5px;
  animation:v3AlarmPulse 1.2s ease-in-out infinite;
}
#v3-ctrl .v3-alarm-row.p1{ border-color:#b71c1c; background:rgba(183,28,28,0.18); }
#v3-ctrl .v3-alarm-row.p2{ border-color:#e65100; background:rgba(230,81,0,0.14); }
#v3-ctrl .v3-alarm-row.p3{ border-color:#f9a825; background:rgba(249,168,37,0.10); }
#v3-ctrl .v3-alarm-row.p4{ border-color:#66bb6a; background:rgba(102,187,106,0.10); }
#v3-ctrl .v3-alarm-row.ack{
  opacity:0.72;
  border-left-style:dashed;
  animation:none;
}
@keyframes v3AlarmPulse{
  0%,100%{ box-shadow:inset 0 0 0 rgba(229,57,53,0); }
  50%    { box-shadow:inset 0 0 12px rgba(229,57,53,0.38); }
}

#v3-ctrl .v3-alarm-tag{
  flex:0 0 auto;
  font-family:Consolas,monospace;font-weight:700;
  color:#ffe082;
  cursor:pointer;white-space:nowrap;
  overflow:hidden;text-overflow:ellipsis;max-width:90px;
}
#v3-ctrl .v3-alarm-tag:hover{ color:#fff; text-decoration:underline; }

#v3-ctrl .v3-alarm-val{
  flex:1;
  font-family:Consolas,monospace;font-size:10.5px;
  color:#cfd8dc;text-align:right;white-space:nowrap;
}

#v3-ctrl .v3-alarm-ack{
  flex:0 0 auto;
  font:700 10px Consolas,monospace;
  background:#c62828;color:#fff;border:none;border-radius:4px;
  padding:2px 8px;cursor:pointer;min-width:34px;text-align:center;
}
#v3-ctrl .v3-alarm-ack:hover{ background:#e53935; }
#v3-ctrl .v3-alarm-ack[disabled]{
  background:#546e7a;cursor:default;opacity:0.85;
}

#v3-ctrl .v3-alarm-sep{
  height:1px;background:#37474f;
  margin:6px 0 4px;
}

/* ====================================================================
   HAZOP Worksheet panel
   --------------------------------------------------------------------
   A flat HAZOP table rendered as one card per deviation. Risk colour
   runs green (1–3) → yellow (4–8) → orange (9–14) → red (15–25). The
   status select and the Edit / Delete buttons are the whole
   interaction surface; everything else is read-only text so the
   worksheet stays legible at a glance.
   ==================================================================== */
#hazopBox{display:flex;flex-direction:column;gap:6px}

.hzStats{
  font-size:11.5px;color:#455a64;padding:2px 0 6px;
  border-bottom:1px solid #eceff1;
}
.hzStats b{color:#0b62a4}
.hzStats .hzOpen   {color:#b71c1c;font-weight:700}
.hzStats .hzIp     {color:#e65100;font-weight:700}
.hzStats .hzCl     {color:#2e7d32;font-weight:700}
.hzStats .hzHi     {color:#fff;background:#b71c1c;border-radius:3px;
                    padding:1px 6px;font-weight:700}

.hzBar{display:flex;flex-wrap:wrap;gap:4px;margin:2px 0 4px}
.hzBar button{font-size:11px;padding:3px 8px;border-radius:5px;
  background:#f5f7f9;border:1px solid #cfd8dc;color:#37474f;cursor:pointer}
.hzBar button:hover{background:#e3f2fd;border-color:#0b62a4;color:#0b62a4}
.hzBar button.del{background:#fce4ec;border-color:#e57373;color:#b71c1c}
.hzBar button.del:hover{background:#e57373;color:#fff}

.hzRow{
  border-left:4px solid #c62828;
  background:#fff;
  border-radius:0 8px 8px 0;
  padding:6px 8px;margin:2px 0;
  box-shadow:0 1px 2px rgba(0,0,0,.04);
  font-size:11.5px;
  display:flex;flex-direction:column;gap:3px;
}
.hzRow.sopen       {border-left-color:#c62828}
.hzRow.sinprogress {border-left-color:#e65100}
.hzRow.sclosed     {border-left-color:#2e7d32;opacity:.72}
.hzRow.sdeferred   {border-left-color:#7e57c2;opacity:.82}
.hzRow.hi          {background:#fff6f6}

.hzL1{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
.hzChip{
  font:700 9.5px Consolas,monospace;letter-spacing:.04em;
  background:#263238;color:#e0e6ea;
  border-radius:3px;padding:2px 6px;white-space:nowrap;
}
.hzTag{
  font:700 11px Consolas,monospace;color:#0b62a4;
  cursor:pointer;text-decoration:none;
}
.hzTag:hover{text-decoration:underline}
.hzRisk{
  margin-left:auto;
  font:700 10.5px Consolas,monospace;
  border-radius:3px;padding:2px 7px;color:#fff;
  background:#2e7d32;
}
.hzRisk.r1{background:#2e7d32}
.hzRisk.r3{background:#f9a825;color:#1c2733}
.hzRisk.r4{background:#e65100}
.hzRisk.r5{background:#b71c1c}

.hzLine{font-size:11.5px;color:#37474f;line-height:1.4}
.hzLine b{color:#0b62a4;font-weight:700}

.hzActs{display:flex;gap:4px;align-items:center;margin-top:3px}
.hzActs select{font-size:11px;padding:2px 4px;border:1px solid #cfd8dc;
  border-radius:4px;background:#fff;color:#37474f;cursor:pointer}
.hzActs button{font-size:11px;padding:2px 8px;border-radius:4px;
  background:#f5f7f9;border:1px solid #cfd8dc;cursor:pointer}
.hzActs button:hover{background:#e3f2fd;border-color:#0b62a4}
.hzActs button.del{background:#fce4ec;border-color:#e57373;color:#b71c1c}
.hzActs button.del:hover{background:#e57373;color:#fff}

/* ---- HAZOP edit modal ---- */
#hazopModal{display:none;position:fixed;inset:0;z-index:240;
  background:rgba(38,50,56,.72);
  align-items:center;justify-content:center;padding:16px}
#hazopModal.open{display:flex}
#hazopModal .hzCard{
  background:#fff;border-radius:12px;max-width:620px;width:100%;
  max-height:92vh;overflow-y:auto;
  padding:16px;box-shadow:0 12px 40px rgba(0,0,0,.4);
}
#hazopModal h2{margin:0 0 4px;color:#0b62a4;font-size:16px}
#hazopModal .hint{margin:0 0 10px}
#hazopModal .hzGrid{
  display:grid;grid-template-columns:120px 1fr;gap:6px 10px;
  align-items:center;margin-bottom:8px;
}
#hazopModal .hzGrid label{font-size:11.5px;color:#546e7a;font-weight:700}
#hazopModal .hzGrid input,
#hazopModal .hzGrid select,
#hazopModal .hzGrid textarea{
  font:inherit;font-size:12px;
  border:1px solid #b0bec5;border-radius:5px;
  padding:4px 7px;width:100%;box-sizing:border-box;
  background:#fbfcfd;color:#1c2733;
}
#hazopModal .hzGrid textarea{min-height:50px;resize:vertical;font-family:inherit}
#hazopModal .hzRange{display:flex;align-items:center;gap:8px}
#hazopModal .hzRange input[type=range]{flex:1}
#hazopModal .hzRange output{font:700 12px Consolas,monospace;
  color:#0b62a4;min-width:22px;text-align:center}
#hazopModal .hzFooter{display:flex;justify-content:flex-end;gap:6px;margin-top:12px}