:root {
  --bg: #f7f7f5;
  --ink: #1d1d1f;
  --muted: #74747a;
  --line: #e4e4e0;
  --soft: #f2f2f0;
  --accent: #5b5bd6;
  --z: #d8f8d8;
  --x: #e8a5a5;
  --h: #ffffbf;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 10px 28px rgba(0,0,0,.09);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- canvas ---------- */
#viewport { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
/* grid dots: their own layer, so preview fades them out without touching the canvas colour */
#viewport::before { content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image: var(--gi, radial-gradient(circle, #b9b9b2 1.3px, transparent 1.7px)); background-size: var(--gs, 24px 24px); background-position: var(--gp, 0 0);
  transition: opacity .35s cubic-bezier(.22,1,.36,1); }
#viewport.preview::before { opacity: 0; }
#viewport.place { cursor: crosshair; }
#viewport.wire { cursor: crosshair; }
#viewport.hand, #viewport.hand * { cursor: grab !important; }
#viewport.panning, #viewport.panning * { cursor: grabbing !important; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.edges { position: absolute; left: 0; top: 0; overflow: visible; }
.wire-p { fill: none; stroke: #1f1f1f; stroke-width: 1.4; stroke-linecap: round; }
.hit { fill: none; stroke: transparent; stroke-width: 12; pointer-events: stroke; cursor: pointer; }
.edge:hover .wire-p { stroke: #6a6ad8; }
.edge.sel .wire-p { stroke: var(--accent); stroke-width: 2; }
.node.ghost { opacity: .55; pointer-events: none; box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--accent); }
#viewport.copying, #viewport.copying * { cursor: copy !important; }
.edge.drop .wire-p { stroke: var(--accent); stroke-width: 3.5; stroke-opacity: .55; transition: stroke-width .15s; }
.hbox { fill: var(--h); stroke: #1f1f1f; stroke-width: 1; }
.ghost-line { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 4; pointer-events: none; }
.ghost-dot { fill: rgba(91,91,214,.15); stroke: var(--accent); stroke-width: 1; pointer-events: none; }

.node { position: absolute; transform: translate(-50%, -50%); border: 1px solid #1f1f1f; display: flex; align-items: center;
  justify-content: center; font-size: 13.5px; line-height: 1; white-space: nowrap; cursor: grab; transition: box-shadow .15s; }
.node::after { content: ''; position: absolute; inset: -7px; border-radius: 50%; }
.node.tZ { background: var(--z); }
.node.tX { background: var(--x); }
.node.empty { width: 17px; height: 17px; border-radius: 50%; }
.node.tiny { width: 11px; height: 11px; border-radius: 50%; }
.node.lab { min-width: 29px; min-height: 29px; padding: 2px 6px; border-radius: 999px; }
.node.lab .katex { font-size: 1.02em; }
.node.tH { width: 16px; height: 16px; background: var(--h); border-radius: 1px; }
.node.tN { width: 11px; height: 11px; border-radius: 50%; border: 1px dashed #aeaea8; background: rgba(255,255,255,.7); }
.node.tN:hover { border-color: var(--accent); border-style: solid; }
.node.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--accent); }
.node.wfrom { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--accent); animation: wfrom 1s ease-in-out infinite alternate; }
@keyframes wfrom { to { box-shadow: 0 0 0 3px #fff, 0 0 0 6px rgba(91,91,214,.35); } }
.wire .node:hover { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px rgba(91,91,214,.5); }
.preview .node.tN { opacity: 0; }
.preview .frame, .preview .fbar, .preview .addd { display: none; }
.preview .node.sel { box-shadow: none; }

.frame { position: absolute; border-radius: 14px; pointer-events: none; border: 1px dashed transparent; transition: border-color .2s, background .2s; }
.frame.active { border-color: #dadae6; background: rgba(91,91,214,.025); }
/* frame bar: grip + name always; the tools slide out while the diagram is hovered */
.fbar { position: absolute; display: flex; gap: 1px; align-items: center; opacity: .75; transition: opacity .2s; }
.fbar.hov, .fbar.active { opacity: 1; }
/* an open bar sits on a canvas-coloured backdrop with feathered edges, so a neighbour's bar under it disappears */
.fbar { border-radius: 10px; box-shadow: 0 0 0 0 rgba(247,247,245,0); }
.fbar.hov { z-index: 3; background: var(--bg); box-shadow: 0 0 10px 8px var(--bg); transition: opacity .2s, box-shadow .25s ease, background .25s ease; }
.fbar > button { max-width: 0; opacity: 0; margin-left: -1px; transform: translateX(-6px) scale(.85); pointer-events: none; overflow: hidden;
  transition: max-width .3s cubic-bezier(.22,1,.36,1), opacity .16s, transform .3s cubic-bezier(.3,1.3,.5,1), margin .3s cubic-bezier(.22,1,.36,1), background .15s, color .15s; }
.fbar.hov > button { max-width: 24px; opacity: 1; margin-left: 0; transform: none; pointer-events: auto; }
.fbar.hov > button:nth-of-type(2) { transition-delay: 0s, .025s, .025s, 0s, 0s, 0s; }
.fbar.hov > button:nth-of-type(3) { transition-delay: 0s, .05s, .05s, 0s, 0s, 0s; }
.fbar.hov > button:nth-of-type(4) { transition-delay: 0s, .075s, .075s, 0s, 0s, 0s; }
.fbar.hov > button:nth-of-type(5) { transition-delay: 0s, .1s, .1s, 0s, 0s, 0s; }
.fbar.hov > button:nth-of-type(6) { transition-delay: 0s, .125s, .125s, 0s, 0s, 0s; }
@media (hover: none) { .fbar.active > button { max-width: 24px; opacity: 1; margin-left: 0; transform: none; pointer-events: auto; } }
.fbar .fl[data-stat] { font-size: 12px; font-weight: 650; color: #4a4a50; letter-spacing: -.005em; }
.fbar.hov .fl[data-stat] { color: var(--ink); }

.fbar .fl { font-size: 11px; color: var(--muted); padding: 0 4px 0 2px; font-variant-numeric: tabular-nums; }
.fbar button, .fbar .grip { width: 24px; height: 24px; border-radius: 6px; border: 0; background: transparent; color: var(--muted);
  display: grid; place-items: center; cursor: pointer; padding: 0; }
.fbar button:hover, .fbar .grip:hover { background: rgba(0,0,0,.06); color: var(--ink); }
.fbar .grip { cursor: move; }
.fbar button.danger:hover { color: #d33; background: #fdecec; }
.sep { position: absolute; z-index: 2; transform: translate(-50%, -50%); font-size: 23px; padding: 6px 12px; border-radius: 10px; cursor: pointer; white-space: nowrap; transition: background .15s; }
.sep:hover { background: rgba(91,91,214,.08); }
.sep .mathbf { font-size: 1.12em; }
.sep .sc { font-size: .68em; margin: 0 .12em; }   /* scalar next to a relation, as \zxScalar (\scriptstyle) */
.sep.empty { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 1px dashed #cfcfc9; color: #b5b5ae; display: grid; place-items: center; opacity: .55; transition: opacity .15s, border-color .15s, color .15s; }
.sep.empty:hover { opacity: 1; border-color: var(--accent); color: var(--accent); background: rgba(91,91,214,.06); }
.preview .sep.empty { display: none; }
.addd { position: absolute; transform: translate(-50%, -50%); width: 30px; height: 30px; border-radius: 50%; border: 1px dashed #c4c4be;
  background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; padding: 0; transition: all .15s; }
.addd:hover { border-color: var(--accent); color: var(--accent); background: rgba(91,91,214,.06); }

#marquee { position: absolute; border: 1px solid var(--accent); background: rgba(91,91,214,.08); border-radius: 3px; pointer-events: none; display: none; }
#hint { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); text-align: center; color: var(--muted); pointer-events: none; padding: 46px 70px;
  /* a soft halo of the page colour: no grid dots right behind the text, dots return further out */
  background: radial-gradient(closest-side, var(--bg) 62%, rgba(247,247,245,.85) 78%, rgba(247,247,245,0) 100%); }
.hint-title { font-size: 18px; color: var(--ink); margin-bottom: 6px; font-weight: 600; }

/* ---------- chrome ---------- */
.top { position: fixed; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: center; pointer-events: none; z-index: 10; }
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: -.01em; padding: 6px 10px; border-radius: 10px; background: rgba(247,247,245,.85); backdrop-filter: blur(6px); }
.top-actions { display: flex; gap: 4px; align-items: center; padding: 4px; border-radius: 12px; background: rgba(247,247,245,.85); backdrop-filter: blur(6px); }
.ibtn { width: 34px; height: 34px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: background .15s, color .15s; }
.ibtn:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.ibtn.on { color: var(--accent); background: rgba(91,91,214,.1); }
.btn { height: 34px; padding: 0 13px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: transform .08s, background .15s, box-shadow .15s; white-space: nowrap; }
.btn:hover { box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.ghost { background: transparent; }
.btn .bi { display: grid; place-items: center; }

#dock { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; gap: 2px; padding: 4px; background: #fff;
  border-radius: 12px; box-shadow: var(--shadow); z-index: 10; }
#dock { transition: box-shadow .2s; }
#dock[data-side] { left: 0; top: 0; bottom: auto; transform: none; }
#dock.side { flex-direction: column; }
#dock.side .dock-sep { width: auto; height: 1px; margin: 4px 6px; }
#dock.dragging { box-shadow: 0 18px 40px rgba(0,0,0,.18), 0 0 0 1px rgba(0,0,0,.04); cursor: grabbing; }
#dock.dragging .tool { pointer-events: none; }
#dock > .tool, #dock > .dock-sep, #dock > .dock-grip { flex: none; }   /* never squeezed while the frame animates */
/* grab bar: a short rounded line, like a sheet handle */
.dock-grip { position: relative; width: 14px; align-self: stretch; margin: 0 0 0 -1px; border-radius: 7px; cursor: grab; touch-action: none; }
.dock-grip::before { content: ''; position: absolute; left: 50%; top: 50%; width: 4px; height: 18px; border-radius: 2px; background: #d4d4d8;
  transform: translate(-50%, -50%); transition: background .18s, height .25s cubic-bezier(.3,1.4,.5,1), width .25s cubic-bezier(.3,1.4,.5,1); }
.dock-grip:hover::before { background: #9c9ca3; height: 22px; }
#dock.side .dock-grip { width: auto; height: 14px; align-self: stretch; margin: -1px 0 0; }
#dock.side .dock-grip::before { width: 18px; height: 4px; }
#dock.side .dock-grip:hover::before { width: 22px; height: 4px; }
#dock.dragging .dock-grip { cursor: grabbing; }
#dock.dragging .dock-grip::before { background: var(--ink); }
#dockHint { position: fixed; z-index: 9; border-radius: 12px; border: 1.5px dashed rgba(0,0,0,.22); background: rgba(0,0,0,.025); pointer-events: none;
  opacity: 0; transform: scale(.96); transition: left .28s cubic-bezier(.22,1,.36,1), top .28s cubic-bezier(.22,1,.36,1), width .28s cubic-bezier(.22,1,.36,1), height .28s cubic-bezier(.22,1,.36,1), opacity .18s, transform .28s cubic-bezier(.22,1,.36,1); }
#dockHint.show { opacity: 1; transform: none; }
.ctx { position: fixed; z-index: 80; min-width: 188px; padding: 5px; background: #fff; border-radius: 11px; box-shadow: 0 10px 30px rgba(0,0,0,.14), 0 0 0 1px rgba(0,0,0,.05);
  opacity: 0; transform: scale(.94); transition: opacity .14s, transform .18s cubic-bezier(.22,1,.36,1); }
.ctx.show { opacity: 1; transform: none; }
.ctx-i { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 16px; padding: 7px 10px; border: 0; background: none; border-radius: 7px; font: inherit; font-size: 13px; color: var(--ink); cursor: pointer; text-align: left; transition: background .1s; }
.ctx-i:hover:not(:disabled) { background: var(--soft); }
.ctx-i:disabled { opacity: .35; cursor: default; }
.ctx-i.danger { color: #d0342c; }
.ctx-i.danger:hover:not(:disabled) { background: #fdecea; }
.ctx-i kbd { font-family: inherit; font-size: 11px; color: var(--muted); }
.ctx-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.tool { width: 38px; height: 32px; border-radius: 9px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; position: relative; z-index: 1; padding: 0; transition: background .15s, color .25s, transform .12s; touch-action: none; }
.tool:not(.on):not(.pv):hover { background: var(--soft); }
.tool:active { transform: scale(.92); }
.tool.on, .tool.pv { color: #fff; }
.tool .ti { display: grid; place-items: center; line-height: 0; }
.tool svg { display: block; }
.tool kbd { position: absolute; right: 2px; bottom: 0; font-size: 8px; color: #a3a3a8; font-family: inherit; transition: color .25s; }
.tool kbd { transition: color .32s cubic-bezier(.22,1,.36,1) .04s, opacity .32s; }
.tool.on kbd, .tool.pv kbd { color: rgba(255,255,255,.88); }
#dock > .pill { background: var(--ink); border-radius: 9px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.tool:disabled { opacity: .35; cursor: default; }
.dock-sep { width: 1px; background: var(--line); margin: 6px 4px; }
.sw { display: inline-block; width: 11px; height: 11px; border-radius: 50%; border: 1px solid #222; flex: none; }
.sw.lg { width: 15px; height: 15px; }
.sw.Z { background: var(--z); } .sw.X { background: var(--x); }
.sw.H { background: var(--h); border-radius: 2px; }
.sw.N { background: #fff; border-style: dashed; border-color: #999; }
.sw.H.lg { width: 13px; height: 13px; }
.sw.N.lg { width: 11px; height: 11px; }

/* ---------- popovers ---------- */
.pop { position: fixed; z-index: 20; background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 8px; display: flex; flex-direction: column; gap: 7px; animation: popin .14s ease-out; max-width: calc(100vw - 16px); }
@keyframes popin { from { opacity: 0; transform: translateY(4px) scale(.98); } }
.row { display: flex; align-items: center; gap: 6px; }
.seg { position: relative; display: flex; background: var(--soft); border-radius: 9px; padding: 2px; gap: 2px; flex: none; touch-action: none; }
.seg button { height: 28px; min-width: 30px; padding: 0 8px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 5px; font-size: 13px; transition: background .15s; position: relative; z-index: 1; }
.seg button:not(.on):not(.pv):hover { background: rgba(255,255,255,.55); }
/* sliding highlight shared by the dock and every segmented control */
.pill { position: absolute; left: 0; top: 0; z-index: 0; pointer-events: none; border-radius: 7px; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.13), 0 0 0 .5px rgba(0,0,0,.04);
  transition: transform .34s cubic-bezier(.3,1.3,.5,1), width .34s cubic-bezier(.3,1.3,.5,1), height .2s, opacity .2s; }
.vsep { width: 1px; align-self: stretch; background: var(--line); margin: 3px 2px; }
.field { display: flex; align-items: center; gap: 8px; flex: 1; background: var(--soft); border-radius: 8px; padding: 0 9px; height: 30px; min-width: 0; }
.field > span { color: var(--muted); font-size: 12px; flex: none; }
.field input { flex: 1; border: 0; background: transparent; outline: none; font: 13px var(--mono); min-width: 120px; width: 100%; color: var(--ink); }
.field:focus-within { box-shadow: 0 0 0 2px rgba(91,91,214,.35); background: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { height: 24px; padding: 0 9px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 12px; transition: all .12s; }
.chip:hover { border-color: #b9b9b4; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.ib { width: 30px; height: 28px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--muted); padding: 0; flex: none; }
.ib:hover { background: var(--soft); color: var(--ink); }
.ib.on { color: var(--accent); background: rgba(91,91,214,.1); }
.ib.danger:hover { color: #d33; background: #fdecec; }
.muted { color: var(--muted); font-size: 12px; }
.count { font-size: 12px; color: var(--muted); padding: 0 4px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(20,20,25,.28); backdrop-filter: blur(2px); display: grid; place-items: center; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.sheet { width: min(820px, 100%); max-height: 90vh; background: #fff; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.2); display: flex; flex-direction: column; overflow: hidden; animation: rise .18s ease-out; }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 4px; }
.sheet h2 { font-size: 16px; margin: 0; font-weight: 600; }
.mbody { padding: 6px 16px 16px; flex: 1; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
textarea.code { width: 100%; min-height: 280px; resize: vertical; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: 12.5px/1.55 var(--mono); background: #fbfbfa; outline: none; color: var(--ink); white-space: pre; overflow: auto; }
textarea.code:focus { border-color: #c7c7e8; background: #fff; }
.mfoot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.eqlist { display: flex; flex-direction: column; gap: 4px; max-height: 190px; overflow: auto; }
.eq { text-align: left; border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; background: #fff; cursor: pointer; font-size: 12.5px; transition: all .12s; }
.eq:hover { border-color: #c9c9c4; }
.eq.on { border-color: var(--accent); background: rgba(91,91,214,.05); }
.eq code { color: var(--muted); font: 11px var(--mono); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.keys kbd { font: 12px var(--mono); background: var(--soft); border-radius: 5px; padding: 1px 6px; white-space: nowrap; justify-self: start; }
.subhead { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 6px; }

#toast { position: fixed; left: 50%; bottom: 86px; transform: translate(-50%, 8px); background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- phone ---------- */
/* inspector open / close + collapsible phase row */
#insp.closing { animation: popout .13s ease-in forwards; }
@keyframes popout { to { opacity: 0; transform: translateY(4px) scale(.98); } }
.collapse { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .3s cubic-bezier(.3,.9,.4,1), opacity .22s, margin-top .3s cubic-bezier(.3,.9,.4,1); }
.collapse > div { overflow: hidden; min-height: 0; display: flex; flex-direction: column; gap: 7px; padding: 2px; margin: -2px; }
.collapse.shut { grid-template-rows: 0fr; opacity: 0; margin-top: -7px; pointer-events: none; }

/* help: tabs, shortcut table, rule gallery */
.sheet.wide { width: min(1000px, 100%); height: min(760px, 90vh); }
.htabs { align-self: flex-start; }
.htabs button { padding: 0 14px; }
.hbody.in { animation: tabin .26s ease-out; }
@keyframes tabin { from { opacity: 0; transform: translateY(6px); } }
.ktop { display: flex; align-items: center; gap: 8px; margin: 2px 0 4px; }
.ktable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.ktable td { padding: 7px 4px; border-bottom: 1px solid #efefec; vertical-align: middle; }
.ktable tr:not(.kgroup):hover td { background: #fafaf8; }
.ktable .kc { width: 1%; white-space: nowrap; text-align: right; padding-right: 2px; }
.ktable .kgroup th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 16px 4px 6px; border-bottom: 1px solid var(--line); }
.ktable tbody:first-child .kgroup th { padding-top: 6px; }
.ktable .fixed td:first-child { color: #45454a; }
.kbtn, .kfix { font: 12.5px var(--mono); border-radius: 7px; padding: 4px 10px; min-width: 34px; display: inline-block; text-align: center; }
.kfix { background: var(--soft); color: #55555a; }
.kbtn { border: 1px solid var(--line); background: #fff; cursor: pointer; box-shadow: 0 1px 0 #e6e6e2; transition: all .15s; }
.kbtn:hover { border-color: #b9b9e6; color: var(--accent); }
.kbtn.custom { border-color: #c9c9ee; background: #f5f5fd; color: var(--accent); }
.kbtn.rec { border-color: var(--accent); color: var(--accent); background: #f3f3ff; animation: recpulse 1.1s ease-in-out infinite; }
@keyframes recpulse { 50% { box-shadow: 0 0 0 4px rgba(91,91,214,.15); } }
.rules { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; padding-top: 4px; }
.rule { margin: 0; padding: 14px 14px 12px; border-radius: 14px; background: #fafaf8; display: flex; flex-direction: column; gap: 10px; position: relative; transition: background .2s, transform .2s, box-shadow .2s; }
.rule:hover { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.08); transform: translateY(-2px); }
.rule-fig { min-height: 120px; display: grid; place-items: center; overflow: hidden; }
.mini { position: relative; }
.mini-in { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; }
.mini .node { cursor: default; }
.mini .node.tN { opacity: 0; }
.rule-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.rule-tag { color: #8a2a8f; font-style: italic; font-weight: 700; font-size: 13px; }
.rule-desc { color: var(--muted); font-size: 12.5px; margin-top: 2px; line-height: 1.45; }
.rule-acts { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; opacity: 0; transform: translateY(-3px); transition: opacity .18s, transform .18s; }
.rule:hover .rule-acts { opacity: 1; transform: none; }
@media (hover: none) { .rule-acts { opacity: 1; transform: none; } }
.sep .mathbf { color: #8a2a8f; font-style: italic; }
.node.tT { border: 0; background: var(--bg); border-radius: 4px; font-size: 14px; min-width: 16px; min-height: 16px; padding: 1px 2px; }   /* covers the grid dot behind it */
.preview .node.tT, .mini .node.tT { background: transparent; }
.node.tT::after { border-radius: 4px; }
.node.tT .dots { font: 17px/1 'KaTeX_Main', 'Times New Roman', serif; color: #2a2a2a; }

/* canvas menu */
.menu { width: 300px; gap: 4px; padding: 10px; transform-origin: top right; }
.msave { display: flex; gap: 6px; align-items: center; }
.msave .field input { min-width: 0; font-family: inherit; }
.mlabel { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 10px 4px 2px; }
.mlist { display: flex; flex-direction: column; max-height: 240px; overflow: auto; }
.mitem { display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 8px; border-radius: 8px; cursor: pointer; transition: background .12s; }
.mitem:hover { background: var(--soft); }
.mitem .ib { opacity: 0; transition: opacity .12s; }
.mitem:hover .ib { opacity: 1; }
@media (hover: none) { .mitem .ib { opacity: 1; } }
.mtext { flex: 1; min-width: 0; }
.mname { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mmeta { font-size: 11.5px; color: var(--muted); }
.mempty { font-size: 12px; color: var(--muted); padding: 10px 4px 2px; }
.mdiv { height: 1px; background: var(--line); margin: 8px 2px 4px; }
.mrow { display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-size: 13.5px; text-align: left; color: var(--ink); transition: background .12s; }
.mrow:hover:not(:disabled) { background: var(--soft); }
.mrow:disabled { opacity: .4; cursor: default; }
.mrow svg { color: var(--muted); flex: none; }
.mrow span { flex: 1; }
.mrow kbd { font: 11px var(--mono); color: var(--muted); }
.seg.dim { opacity: .4; pointer-events: none; }
@media (max-width: 640px) { .menu { left: 8px; right: 8px !important; width: auto; } }

/* tidy suggestion */
#suggest { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 15; display: flex; align-items: center; gap: 10px;
  padding: 5px 5px 5px 14px; background: #fff; border-radius: 12px; box-shadow: var(--shadow); font-size: 13px; white-space: nowrap;
  animation: drop .38s cubic-bezier(.3,1.35,.5,1); }
#suggest.closing { animation: lift .18s ease-in forwards; }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -16px) scale(.96); } }
@keyframes lift { to { opacity: 0; transform: translate(-50%, -10px) scale(.98); } }
.sg-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(91,91,214,.15); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(91,91,214,.05); } }
.btn.sm { height: 28px; padding: 0 11px; border-radius: 8px; font-size: 13px; }

/* zoom bar (bottom-right, no background) */
#zoombar { position: fixed; right: 14px; bottom: 18px; z-index: 9; display: flex; align-items: center; gap: 1px; color: var(--muted); }
.zb { height: 28px; min-width: 28px; padding: 0 6px; border: 0; border-radius: 8px; background: transparent; display: grid; place-items: center;
  cursor: pointer; color: inherit; font-size: 12px; font-variant-numeric: tabular-nums; transition: background .15s, color .15s, transform .1s; }
.zb:hover { background: rgba(0,0,0,.06); color: var(--ink); }
.zb:active { transform: scale(.9); }
.zb svg { display: block; }
.zp { min-width: 48px; }
.zsep { width: 1px; height: 14px; background: #d4d4ce; margin: 0 3px; }

/* minimap (bottom-left) */
#minimap { position: fixed; left: 16px; bottom: 16px; width: 188px; height: 118px; z-index: 9; border-radius: 12px; overflow: hidden; cursor: pointer;
  background: rgba(255,255,255,.72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border: 1px solid rgba(0,0,0,.05);
  box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.07); touch-action: none;
  transition: opacity .3s, transform .3s cubic-bezier(.3,1.3,.5,1), box-shadow .2s; }
#minimap:hover { box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 10px 28px rgba(0,0,0,.1); transform: translateY(-1px); }
#minimap.dragging { cursor: grabbing; }
#minimap.empty { opacity: 0; transform: translateY(10px) scale(.97); pointer-events: none; }
#minimap canvas { display: block; }
@media (max-width: 920px) { #minimap { display: none; } }
@media (max-width: 820px) { #zoombar { display: none; } }

@media (max-width: 640px) {
  .top { top: calc(8px + env(safe-area-inset-top)); left: 8px; right: 8px; }
  .brand .name, .btn .lbl, .hide-m { display: none; }
  .btn { padding: 0 10px; }
  #dock { left: 8px; right: 8px; transform: none; justify-content: space-between; bottom: calc(8px + env(safe-area-inset-bottom)); overflow-x: auto; }
  .tool { width: 36px; height: 38px; flex: none; }
  .tool kbd { display: none; }
  .dock-sep { margin: 8px 1px; }
  .dock-grip { display: none; }
  .ctx-i { padding: 10px 12px; font-size: 14px; }
  #insp, #pop { left: 8px !important; right: 8px; top: auto !important; bottom: calc(70px + env(safe-area-inset-bottom)) !important; }
  #suggest { top: calc(56px + env(safe-area-inset-top)); }
  .sg-text { font-size: 12px; }
  .field input { min-width: 0; font-size: 16px; }
  .row { flex-wrap: wrap; }
  .modal { place-items: end center; padding: 0; }
  .sheet { border-radius: 16px 16px 0 0; max-height: 92vh; }
  textarea.code { min-height: 200px; font-size: 12px; }
  #toast { bottom: 80px; }
}

/* bend handle on a selected wire: drag sideways to set the bend angle */
.edges.handles { z-index: 3; }
.bend-h { cursor: grab; }
.bend-h.on { cursor: grabbing; }
.bh-hit { fill: transparent; pointer-events: all; }
.bh-dot { fill: #fff; stroke: var(--accent); stroke-width: 2; pointer-events: none; transition: r .15s ease, fill .15s ease; }
.bend-h:hover .bh-dot, .bend-h.on .bh-dot { fill: var(--accent); }
.bend-h text { font: 600 11px/1 system-ui, sans-serif; fill: var(--accent); paint-order: stroke; stroke: #fff; stroke-width: 3px; pointer-events: none; }
@media (pointer: coarse) { .bh-hit { r: 20px; } }
.bh-dot.ring, .bend-h:hover .bh-dot.ring, .bend-h.on .bh-dot.ring { fill: none; }

/* ---------- tabs (pages of one canvas) ---------- */
.top { gap: 10px; }
.tabs { flex: 1; min-width: 0; display: flex; pointer-events: none; }
.tab-track { pointer-events: auto; display: flex; align-items: center; gap: 2px; padding: 4px; max-width: 100%; overflow-x: auto;
  border-radius: 12px; background: rgba(247,247,245,.85); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); scrollbar-width: none; }
.tab-track::-webkit-scrollbar { display: none; }
.tab { flex: none; position: relative; display: flex; align-items: center; gap: 2px; height: 30px; padding: 0 5px 0 12px; border-radius: 8px;
  color: var(--muted); font-size: 13px; white-space: nowrap; cursor: pointer; touch-action: pan-x;
  transition: background .15s, color .15s, box-shadow .2s, transform .15s; }
.tab.solo { padding-right: 12px; }
.tab:hover { background: rgba(0,0,0,.04); color: var(--ink); }
.tab.on { background: #fff; color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.07), 0 2px 8px rgba(0,0,0,.05); }
.tab.drag { transform: scale(1.04); box-shadow: 0 6px 18px rgba(0,0,0,.14); z-index: 2; cursor: grabbing; }
.tab.new { animation: tabnew .26s cubic-bezier(.3,1.3,.5,1); }
@keyframes tabnew { from { opacity: 0; transform: translateY(-4px) scale(.92); } }
.tname { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.tx { height: 20px; min-width: 20px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: inherit; display: grid; place-items: center;
  opacity: 0; cursor: pointer; transition: opacity .12s, background .12s, color .12s; }
.tab:hover .tx, .tab.on .tx { opacity: .55; }
.tx:hover { opacity: 1 !important; background: rgba(0,0,0,.06); }
.tx.arm { opacity: 1 !important; padding: 0 7px; font-size: 11.5px; font-weight: 600; color: #c0392b; background: rgba(192,57,43,.09); }
.tren { height: 22px; max-width: 180px; border: 0; padding: 0 4px; margin: 0 -4px; border-radius: 5px; font: inherit; color: inherit; background: transparent; outline: none; box-shadow: none; caret-color: var(--accent);
  transition: width .26s cubic-bezier(.22,1,.36,1), background .2s; }
.tab.renaming .tren { background: transparent; }
.tabs, .tab, .tname { -webkit-user-select: none; user-select: none; }
.tren { -webkit-user-select: text; user-select: text; }
.tab.renaming .tx { opacity: 0; pointer-events: none; }
.tmeasure { position: absolute; visibility: hidden; white-space: pre; pointer-events: none; max-width: none; }
.tren::selection { background: rgba(91,91,214,.22); }
.tadd { flex: none; width: 30px; height: 30px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: background .15s, color .15s, transform .1s; }
.tadd:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.tadd:active { transform: scale(.9); }
#world.tabin { animation: tabin .24s ease-out; }
@keyframes tabin { from { opacity: 0; } }
@media (hover: none) { .tab.on .tx { opacity: .55; } }
@media (max-width: 640px) {
  .top { gap: 6px; }
  .tname { max-width: 84px; }
  .tab { padding: 0 3px 0 9px; font-size: 12.5px; }
  .tab.solo { padding-right: 9px; }
}

/* line wrapping */
.wbtn { position: relative; }
.wbtn[data-n]:not([data-n=""])::after { content: attr(data-n); position: absolute; right: 2px; bottom: 2px; min-width: 13px; height: 13px; padding: 0 3px;
  border-radius: 7px; background: var(--accent); color: #fff; font: 600 9px/13px system-ui, sans-serif; text-align: center; }
.wraphead { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 2px; }
.phint { font-size: 12px; color: var(--muted); max-width: 330px; line-height: 1.45; padding: 0 2px; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.brrow .chip { display: inline-flex; align-items: center; gap: 5px; }
.brrow .chip svg { width: 15px; height: 15px; }

/* minimap fold */
#minimap { transition: opacity .3s, transform .3s cubic-bezier(.3,1.3,.5,1), box-shadow .2s, width .28s cubic-bezier(.3,1,.4,1), height .28s cubic-bezier(.3,1,.4,1), border-radius .28s; }
#minimap canvas { transition: opacity .18s; }
.mm-tog { position: absolute; top: 5px; right: 5px; width: 22px; height: 22px; border: 0; border-radius: 7px; padding: 0; display: grid; place-items: center;
  background: rgba(255,255,255,.85); color: var(--muted); cursor: pointer; opacity: .6; box-shadow: 0 0 0 1px rgba(0,0,0,.05); transition: opacity .15s, background .15s, color .15s, transform .1s; }
#minimap:hover .mm-tog, .mm-tog:focus-visible { opacity: 1; }
.mm-tog:hover { color: var(--ink); background: #fff; }
.mm-tog:active { transform: scale(.9); }
#minimap.collapsed { width: 36px; height: 36px; border-radius: 11px; }
#minimap.collapsed canvas { opacity: 0; pointer-events: none; }
#minimap.collapsed .mm-tog { inset: 0; width: 100%; height: 100%; opacity: 1; background: transparent; box-shadow: none; border-radius: 11px; }

/* insert a diagram between two others: small + under each relation, shown on hover */
.sepins { position: absolute; transform: translate(-50%, -50%) scale(.85); width: 22px; height: 22px; border-radius: 50%; padding: 0;
  border: 1px dashed #c4c4be; background: rgba(247,247,245,.9); color: var(--muted); display: grid; place-items: center; cursor: pointer;
  opacity: 0; transition: opacity .15s, transform .15s, color .15s, border-color .15s; }
.sep:hover + .sepins, .sepins:hover { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.sepins:hover { border-color: var(--accent); color: var(--accent); }
.sepins svg { width: 13px; height: 13px; }
@media (hover: none) { .sepins { opacity: .55; } }
.preview .sepins { display: none; }
.sepins { z-index: 1; }
.sepins::before { content: ''; position: absolute; left: -10px; right: -10px; top: -12px; bottom: -6px; }   /* bridge to the relation, never over it */

/* ---------- simplify popover ---------- */
.simsteps { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; max-width: 360px; padding: 2px; }
.simstep { display: inline-grid; place-items: center; min-height: 34px; padding: 0 6px; border-radius: 8px; background: var(--soft); font-size: 13px;
  animation: stepin .3s cubic-bezier(.3,1.3,.5,1) both; animation-delay: calc(var(--k) * 45ms); }
.simarrow { color: #c0c0ba; font-size: 15px; }
@keyframes stepin { from { opacity: 0; transform: translateY(4px) scale(.94); } }
.simacts { align-items: center; gap: 6px; flex-wrap: wrap; }
.simerr { font-size: 12.5px; color: #b03a2e; background: rgba(192,57,43,.07); border-radius: 8px; padding: 7px 9px; max-width: 360px; line-height: 1.45; }
.grow { flex: 1; }

/* ---------- matrix panel ---------- */
#matRoot { display: flex; flex-direction: column; gap: 12px; min-height: 0; flex: 1; }
.msyms { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 8px 10px; background: var(--soft); border-radius: 10px; }
.msym { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.msym input { width: 64px; height: 28px; border: 1px solid var(--line); border-radius: 7px; padding: 0 6px; font: 13px var(--mono); background: #fff; }
.mxlist { overflow: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 2px; flex: 1; min-height: 0; }
.mblock { border-radius: 12px; background: #fff; box-shadow: 0 0 0 1px var(--line); padding: 10px 12px; animation: popin .18s ease-out; }
.mhead { display: flex; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 6px; }
.mtag { font-size: 11px; color: #9a6b12; background: rgba(230,160,30,.12); border-radius: 6px; padding: 2px 7px; }
.mwrap { display: flex; align-items: center; gap: 8px; overflow-x: auto; padding: 2px 0 4px; }
/* prefix (∝, 1/√2 …) in the TeX font, centred on the matrix body (not the ⟨ket| header row) */
.mpref { flex: none; align-self: stretch; display: flex; align-items: center; padding: 26px 2px 0 0; font-size: 17px; color: var(--ink); }
.mpref .katex { font-size: 1.1em; }
.mtab { border-collapse: separate; border-spacing: 0; font-size: 13px; position: relative; }
.mtab::before, .mtab::after { content: ''; position: absolute; top: 24px; bottom: 0; width: 6px; border: 1.4px solid var(--ink); }
.mtab::before { left: 34px; border-right: 0; border-radius: 4px 0 0 4px; }
.mtab::after { right: -2px; border-left: 0; border-radius: 0 4px 4px 0; }
.mtab th { font: 10.5px var(--mono); color: #a3a39c; font-weight: 400; padding: 2px 8px; white-space: nowrap; }
.mtab thead th { height: 22px; }
.mtab tbody th { text-align: right; padding-right: 12px; width: 34px; }
.mtab td { padding: 4px 10px; text-align: center; white-space: nowrap; border-radius: 6px; transition: background .12s; }
.mtab td.z { color: #c3c3bd; }
.mtab.num td { font: 12px var(--mono); }
.mtab tbody tr:hover td { background: rgba(91,91,214,.06); }
.mcheck { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 6px 10px; border-radius: 9px; margin: -2px 14px; }
.mcheck .mci { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff; flex: none; }
.mcheck.ok { background: rgba(40,160,90,.08); } .mcheck.ok .mci { background: #2a9d5c; }
.mcheck.warn { background: rgba(230,160,30,.11); } .mcheck.warn .mci { background: #d99a1e; }
.mcheck.bad { background: rgba(192,57,43,.08); color: #8e2a20; } .mcheck.bad .mci { background: #c0392b; }
.mcheck.info { background: var(--soft); } .mcheck.info .mci { background: #a3a39c; }
.seg.sm button { height: 24px; min-width: 26px; font-size: 12px; }
@media (max-width: 640px) {
  .simsteps { max-width: none; }
  .mcheck { margin: 0; flex-wrap: wrap; }
  .mtab td { padding: 3px 6px; }
}

/* compute buttons in the top bar */
.tsep { width: 1px; height: 18px; background: #deded8; margin: 0 4px; }
.btn.cbtn { border-color: transparent; color: var(--ink); }
.btn.cbtn:hover { background: rgba(91,91,214,.08); color: var(--accent); box-shadow: none; }
.btn.cbtn .bi { color: var(--accent); }
.mbusy { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); padding: 10px 2px; }
.spin { width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(91,91,214,.2); border-top-color: var(--accent); animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* live step check: badge at the bottom-right of each relation */
.sepok { position: absolute; right: -4px; bottom: -2px; width: 17px; height: 17px; border-radius: 50%; display: grid; place-items: center;
  font: 700 10px/1 system-ui, sans-serif; color: #fff; box-shadow: 0 0 0 2px var(--bg); animation: okpop .25s cubic-bezier(.3,1.5,.5,1); pointer-events: auto; }
.sepok.ok { background: #2a9d5c; }
.sepok.warn { background: #d99a1e; }
.sepok.bad { background: #c0392b; }
.sepok.err { background: #a3a39c; }
.sepok.wait { background: transparent; box-shadow: none; border: 2px solid rgba(91,91,214,.25); border-top-color: var(--accent); width: 13px; height: 13px; animation: spin .7s linear infinite; }
@keyframes okpop { from { transform: scale(.3); opacity: 0; } }
.preview .sepok { display: none; }
.cbtn.on { background: rgba(42,157,92,.1); color: #1f7a47; }
.cbtn.on .bi { color: #2a9d5c; }
.cbtn .cbad { min-width: 15px; height: 15px; padding: 0 4px; border-radius: 8px; background: #c0392b; color: #fff; font: 600 10px/15px system-ui, sans-serif; }
/* switch */
.switch { display: flex; align-items: center; gap: 9px; font-size: 13px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 32px; height: 19px; border-radius: 10px; background: #d6d6d0; position: relative; transition: background .18s; flex: none; }
.switch .track::after { content: ''; position: absolute; left: 2px; top: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .2s cubic-bezier(.3,1.3,.5,1); }
.switch input:checked + .track { background: #2a9d5c; }
.switch input:checked + .track::after { transform: translateX(13px); }
.legend { display: flex; flex-direction: column; gap: 7px; padding: 2px 2px 0; font-size: 12.5px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 8px; line-height: 1.3; }
.legend i { flex: none; display: grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; color: #fff; }
.legend i.ok { background: #2a9d5c; } .legend i.warn { background: #d99a1e; } .legend i.bad { background: #c0392b; }
/* status marks: one size everywhere, centred by the grid */
.legend i svg, .sepok svg, .sepfix .fx svg, .mcheck .mci svg { width: 11px; height: 11px; display: block; }
.sepfix { display: flex; align-items: center; gap: 8px; min-height: 0; font-size: 13px; color: var(--ink, #333); animation: fadeUp .18s ease; }
.sepfix:empty { display: none; }
.sepfix .fx { flex: none; width: 17px; height: 17px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.sepfix .fx.ok { background: #2a9d5c; } .sepfix .fx.warn { background: #d99a1e; } .sepfix .fx.bad { background: #c0392b; }
.sepfix .chip { margin-left: auto; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.mcheck .mci svg { width: 12px; height: 12px; }
/* the insert + only takes clicks once it is shown (hovering the relation), so clicks under "=" never hit it by accident */
.sepins { pointer-events: none; }
.sep:hover + .sepins, .sepins:hover { pointer-events: auto; }
@media (hover: none) { .sepins { pointer-events: auto; } }

/* image export */
#expBody { display: flex; flex-direction: column; gap: 12px; min-height: 0; flex: 1; }
.imgprev { flex: 1; min-height: 160px; overflow: auto; display: flex; flex-direction: column; gap: 12px; align-items: center; padding: 14px; border-radius: 12px; background: var(--soft); }
.imgcard { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 100%; animation: popin .2s ease-out; }
.imgcard svg { max-width: 100%; height: auto; background: #fff; border-radius: 6px; box-shadow: 0 0 0 1px rgba(0,0,0,.05), 0 6px 18px rgba(0,0,0,.06); }
.imgcard.checker svg { background: repeating-conic-gradient(#f1f1ee 0 25%, #fff 0 50%) 0 0 / 14px 14px; }
.imgcard figcaption { font: 11px var(--mono); color: var(--muted); }

/* ---------- guide ---------- */
.guide { display: grid; grid-template-columns: 168px 1fr; gap: 20px; min-height: 0; flex: 1; }
#helpBody:has(.guide) { display: flex; min-height: 0; flex: 1; }
.gnav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; align-self: start; }
.gnav button { text-align: left; border: 0; background: transparent; height: 32px; padding: 0 12px; border-radius: 8px; color: var(--muted); font-size: 13.5px; cursor: pointer; transition: background .15s, color .15s; }
.gnav button:hover { background: var(--soft); color: var(--ink); }
.gnav button.on { background: var(--soft); color: var(--ink); font-weight: 600; }
.gmain { overflow: auto; min-height: 0; padding: 0 6px 30px 0; scroll-behavior: smooth; }
.gmain section { padding-bottom: 26px; }
.gmain section + section { border-top: 1px solid var(--line); padding-top: 18px; }
.gmain h3 { font-size: 17px; margin: 2px 0 6px; letter-spacing: -.01em; }
.gmain h4 { font-size: 14px; margin: 0 0 4px; }
.gmain p { margin: 0 0 8px; font-size: 13px; line-height: 1.55; color: #4a4a4f; }
.glead { color: var(--muted) !important; }
.gmain code { font: 12px var(--mono); background: var(--soft); padding: 1px 5px; border-radius: 5px; }
.gsteps { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.gsteps li { display: flex; gap: 14px; }
.gnum { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 600; }
.gstep { flex: 1; min-width: 0; }
.grow2 { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.grow2 .btn svg { width: 15px; height: 15px; }
.gcode { position: relative; margin-top: 6px; }
.gcode pre { margin: 0; padding: 12px 14px; padding-right: 86px; background: #1f1f23; color: #e9e9ee; border-radius: 10px; font: 12.5px/1.55 var(--mono); overflow-x: auto; }
.gcopy { position: absolute; top: 8px; right: 8px; display: inline-flex; align-items: center; gap: 5px; background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.18); }
.gcopy:hover { background: rgba(255,255,255,.2); border-color: rgba(255,255,255,.3); }
.gcopy svg { width: 13px; height: 13px; }
.gio { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 10px; }
.giocard { padding: 14px; border-radius: 14px; background: #fafaf8; transition: background .2s, box-shadow .2s, transform .2s; }
.giocard:hover { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.08); transform: translateY(-2px); }
.gioi { width: 32px; height: 32px; border-radius: 9px; background: #fff; box-shadow: 0 0 0 1px var(--line); display: grid; place-items: center; color: var(--accent); margin-bottom: 8px; }
.ggrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 10px; }
.gcard { border-radius: 14px; background: #fafaf8; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; transition: background .2s, box-shadow .2s, transform .2s; }
.gcard:hover { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.08); transform: translateY(-2px); }
.gdemo { border-radius: 10px; background: #fff; box-shadow: 0 0 0 1px #ececea; overflow: hidden; }
.demo { display: block; width: 100%; height: auto; }
.dlabel { font: 600 10px system-ui, sans-serif; fill: var(--muted); text-anchor: middle; }
.dkey { font: 700 10px system-ui, sans-serif; fill: #1d1d1f; text-anchor: middle; }
.gtitle { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 13.5px; margin-top: 4px; }
.gkeys { display: inline-flex; align-items: center; gap: 3px; flex: none; }
.cap { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 6px; background: #fff; border: 1px solid #dcdcd6; box-shadow: 0 1.5px 0 #dcdcd6; font: 600 11.5px system-ui, sans-serif; color: var(--ink); margin: 0 2px; }
.gplus { font-size: 11px; color: var(--muted); font-weight: 500; }
.gsep { color: #c3c3bc; font-size: 11px; }
.gcard p { margin: 0; font-size: 12.5px; }
.gmore { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 14px; font-size: 12.5px; color: #4a4a4f; }
.gmore span { display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 640px) {
  .guide { grid-template-columns: 1fr; gap: 10px; }
  .gnav { flex-direction: row; overflow-x: auto; position: static; }
  .gnav button { flex: none; }
  .gsteps li { gap: 10px; }
  #hint { padding: 36px 30px; }
}

/* ---------- first-run tour ---------- */
#tour { position: fixed; inset: 0; z-index: 200; opacity: 0; transition: opacity .25s ease; }
#tour.on { opacity: 1; }
.t-spot { position: fixed; border-radius: 14px; pointer-events: none;
  box-shadow: 0 0 0 2px rgba(255,255,255,.9), 0 0 0 6px rgba(91,91,214,.35), 0 0 0 200vmax rgba(24,24,32,.42);
  transition: left .45s cubic-bezier(.3,.9,.25,1), top .45s cubic-bezier(.3,.9,.25,1), width .45s cubic-bezier(.3,.9,.25,1), height .45s cubic-bezier(.3,.9,.25,1), box-shadow .3s; }
.t-spot:not(.none)::after { content: ''; position: absolute; inset: -2px; border-radius: inherit; border: 2px solid var(--accent); animation: tpulse 1.8s ease-out infinite; }
.t-spot.none { box-shadow: 0 0 0 0 transparent, 0 0 0 0 transparent, 0 0 0 200vmax rgba(24,24,32,.42); }
@keyframes tpulse { 0% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(1.12); } }
.t-card { position: fixed; left: 0; top: 0; background: #fff; border-radius: 16px; padding: 18px 18px 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,.08), 0 24px 60px rgba(0,0,0,.22);
  transition: transform .45s cubic-bezier(.3,.9,.25,1); will-change: transform; }
.t-card.nudge { animation: tnudge .32s ease; }
@keyframes tnudge { 30% { margin-left: -5px; } 65% { margin-left: 4px; } }
.t-body { transition: opacity .15s ease, translate .15s ease; }
.t-body.out { opacity: 0; translate: 8px 0; }
.t-body.out.back { translate: -8px 0; }
.t-demo { margin: -4px -4px 12px; padding: 6px 12px; background: var(--soft); border-radius: 12px; }
.t-demo .demo { max-height: 104px; }
.t-step { font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.t-card h3 { margin: 4px 0 6px; font-size: 17px; letter-spacing: -.01em; }
.t-card p { margin: 0; color: #4a4a50; line-height: 1.55; font-size: 13.5px; }
.t-card code { font: 12px var(--mono); background: var(--soft); padding: 1px 5px; border-radius: 5px; }
.t-keys { margin-top: 10px; }
.t-keys .cap { margin: 0 4px 0 0; }
.t-card footer { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.t-dots { display: flex; gap: 5px; margin-right: auto; }
.t-dots i { width: 6px; height: 6px; border-radius: 99px; background: #dcdcd6; transition: width .3s ease, background .3s; }
.t-dots i.on { width: 18px; background: var(--ink); }
.t-skip { border: 0; background: none; color: var(--muted); font-size: 12.5px; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.t-skip:hover { color: var(--ink); background: var(--soft); }
.t-card.center { text-align: left; }
.t-card .btn.sm { height: 30px; }
.gtour { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; border: 0; background: none; color: var(--accent); font-size: 12.5px; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.gtour:hover { background: var(--soft); }
@media (prefers-reduced-motion: reduce) { .t-spot, .t-card { transition: none; } .t-spot::after { animation: none; } }

#zPct.flash { animation: zflash .38s cubic-bezier(.22,1,.36,1); }
@keyframes zflash { 0% { transform: scale(.86); } 60% { transform: scale(1.08); } 100% { transform: none; } }

/* single-graph switch */
.swt { flex: none; display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 6px 0 10px; margin-right: -6px; border: 0; border-radius: 10px; background: transparent;
  font: inherit; font-size: 12.5px; color: var(--muted); cursor: pointer; pointer-events: auto; transition: background .15s, color .2s; }
.swt:hover { background: var(--soft); color: var(--ink); }
.swt.on { color: var(--ink); }
.swt-track { position: relative; width: 30px; height: 18px; border-radius: 9px; background: #dcdce0; transition: background .25s; }
.swt.on .swt-track { background: var(--ink); }
.swt-knob { position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .34s cubic-bezier(.3,1.5,.5,1), width .18s; }
.swt.on .swt-knob { transform: translateX(12px); }
.swt:active .swt-knob { width: 17px; }
.swt.on:active .swt-knob { transform: translateX(9px); }
.swt.nudge { animation: swtnudge .45s cubic-bezier(.3,1.4,.5,1); }
@keyframes swtnudge { 0%,100% { transform: none; } 25% { transform: translateX(-3px); } 50% { transform: translateX(3px); } 75% { transform: translateX(-1px); } }
/* step chrome fades out in single-graph mode */
#world .fbar .fl, #world .addd, #world .sepins, #world .frame { transition: opacity .22s, border-color .2s, background .2s; }
#world.single .fbar .fl, #world.single .addd, #world.single .sepins, #world.single .fbar [data-act="dup"] { opacity: 0; pointer-events: none; }
#world.single .frame.active { border-color: transparent; background: none; }
@media (max-width: 640px) { .swt-lbl { display: none; } .swt { padding: 0 6px; margin-right: 2px; } }
.ti-t { display: grid; place-items: center; line-height: 0; }
.ti-t svg { width: 16px; height: 16px; }

/* page tabs: ‹ › when they overflow */
.tabs { align-items: center; }
.tabs .tadd { pointer-events: auto; flex: none; }
.tarr { pointer-events: auto; flex: none; width: 0; height: 28px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  display: grid; place-items: center; cursor: pointer; opacity: 0; overflow: hidden; transition: width .22s cubic-bezier(.22,1,.36,1), opacity .18s, background .15s, color .15s; }
.tabs.over .tarr { width: 26px; }
.tabs.can-l .tarr.l, .tabs.can-r .tarr.r { opacity: 1; }
.tarr:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.tarr:active svg { transform: scale(.85); }
.tarr svg { transition: transform .12s; }
.tabs.over:not(.can-l) .tarr.l, .tabs.over:not(.can-r) .tarr.r { pointer-events: none; }
.tabs.can-l .tab-track { -webkit-mask-image: linear-gradient(90deg, transparent, #000 24px); mask-image: linear-gradient(90deg, transparent, #000 24px); }
.tabs.can-r .tab-track { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent); }
.tabs.can-l.can-r .tab-track { -webkit-mask-image: linear-gradient(90deg, transparent, #000 24px, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(90deg, transparent, #000 24px, #000 calc(100% - 24px), transparent); }
@media (hover: none) { .tarr { display: none; } }
.ctx-i.arm { background: #fdecea; color: #d0342c; }
.ctx-i.danger.arm { background: #d0342c; color: #fff; animation: ctxarm .3s cubic-bezier(.3,1.4,.5,1); }
@keyframes ctxarm { from { transform: scale(.96); } }
.cfm { width: 290px; padding: 14px 14px 12px; }
.cfm-t { font-size: 13.5px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.cfm-d { font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.cfm-b { display: flex; justify-content: flex-end; gap: 6px; margin-top: 12px; }
@media (max-width: 640px) { .cfm { width: calc(100vw - 16px); } }
/* preview (eye) lives at the right end of the zoom bar */
.zpv { --cut: var(--bg); }
.zpv .eye-slash, .zpv .eye-cut { stroke-dasharray: 22; stroke-dashoffset: 22; transition: stroke-dashoffset .38s cubic-bezier(.65,0,.35,1); }
.zpv .eye-cut { stroke: var(--cut); stroke-width: 4.6; }
.zpv.on .eye-slash, .zpv.on .eye-cut { stroke-dashoffset: 0; }
.zpv svg { transition: transform .3s cubic-bezier(.3,1.5,.5,1); }
.zpv:active svg { transform: scale(.86); }
@media (max-width: 820px) {
  #zoombar { display: flex !important; }
  #zoombar > :not(.zpv) { display: none; }
  #zoombar .zpv { width: 36px; height: 36px; border-radius: 11px; background: #fff; box-shadow: var(--shadow); --cut: #fff; }
}
@media (max-width: 640px) { #zoombar { right: 8px; bottom: calc(66px + env(safe-area-inset-bottom)); } }
#btnSimp .bi { display: grid; place-items: center; line-height: 0; }
#btnSimp.on, #btnSimp[aria-expanded="true"] { color: var(--accent); background: rgba(91,91,214,.1); }

/* every plain checkbox is drawn as a switch (the .switch component keeps its own track) */
input[type="checkbox"]:not(.switch input) { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 30px; height: 18px; margin: 0;
  border-radius: 9px; background: #d6d6d0; cursor: pointer; vertical-align: middle; outline: none;
  transition: background .25s cubic-bezier(.22,1,.36,1), box-shadow .15s; }
input[type="checkbox"]:not(.switch input)::after { content: ''; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.22); transition: transform .34s cubic-bezier(.3,1.5,.5,1), width .18s; }
input[type="checkbox"]:not(.switch input):checked { background: var(--ink); }
input[type="checkbox"]:not(.switch input):checked::after { transform: translateX(12px); }
input[type="checkbox"]:not(.switch input):active::after { width: 17px; }
input[type="checkbox"]:not(.switch input):checked:active::after { transform: translateX(9px); }
input[type="checkbox"]:not(.switch input):focus-visible { box-shadow: 0 0 0 3px rgba(91,91,214,.25); }
input[type="checkbox"]:not(.switch input):disabled { opacity: .4; cursor: default; }
.chk { gap: 8px; }
/* the older .switch component: same motion */
.switch .track::after { transition: transform .34s cubic-bezier(.3,1.5,.5,1), width .18s; }
.switch input:checked + .track { background: var(--ink); }

/* export: tabs and the tab's options share one row */
.exphead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.exphead .htabs { align-self: center; }
.exp-sep { width: 1px; height: 20px; background: var(--line); flex: none; }
#expOpts { display: grid; flex: 1; min-width: 0; align-items: center; }
#expOpts > .expopts { grid-area: 1 / 1; margin: 0; }
#expOpts .grow { display: none; }
.expopts.in { animation: optsIn .32s cubic-bezier(.22,1,.36,1); }
.expopts.out { animation: optsOut .22s ease-in forwards; pointer-events: none; }
@keyframes optsIn { from { opacity: 0; transform: translateX(10px); } }
@keyframes optsOut { to { opacity: 0; transform: translateX(-8px); } }
#expBody > .hbody, #expBody { margin-top: 0; }
/* items that come and go inside an option row */
.cond { display: inline-flex; align-items: center; max-width: 420px; white-space: nowrap; overflow: hidden;
  transition: max-width .38s cubic-bezier(.22,1,.36,1), opacity .26s, transform .38s cubic-bezier(.22,1,.36,1), margin .38s cubic-bezier(.22,1,.36,1); }
.cond.off { max-width: 0; opacity: 0; transform: scale(.92); margin-left: -8px; pointer-events: none; }
.nt, .nt::after, .nt * { transition: none !important; }
@media (max-width: 640px) { .exp-sep { display: none; } #expOpts { flex-basis: 100%; } }
/* brand sits closer to the page tabs */
.brand { padding-right: 4px; }
.brand + .tabs { margin-left: -6px; }

/* tab delete confirmation: Delete? ✓ ✕ */
.tconf { display: inline-flex; align-items: center; gap: 2px; margin-left: 4px; padding: 0 2px 0 8px; height: 22px; border-radius: 7px; background: rgba(192,57,43,.09);
  animation: tconfIn .26s cubic-bezier(.3,1.4,.5,1); transform-origin: left center; }
.tconf.out { animation: tconfOut .16s ease-in forwards; }
@keyframes tconfIn { from { opacity: 0; transform: scale(.85); } }
@keyframes tconfOut { to { opacity: 0; transform: scale(.9); } }
.tc-q { font-size: 11.5px; font-weight: 600; color: #c0392b; margin-right: 3px; white-space: nowrap; }
.tc-yes, .tc-no { width: 20px; height: 18px; padding: 0; border: 0; border-radius: 5px; background: transparent; display: grid; place-items: center; cursor: pointer; transition: background .12s, color .12s, transform .1s; }
.tc-yes { color: #c0392b; }
.tc-yes:hover { background: #c0392b; color: #fff; }
.tc-no { color: var(--muted); }
.tc-no:hover { background: rgba(0,0,0,.07); color: var(--ink); }
.tc-yes:active, .tc-no:active { transform: scale(.88); }

/* open wire ends: inputs (left) indigo, outputs (right) amber */
:root { --in: #5b5bd6; --out: #d9822b; }
.node.tN.bin, .node.tP.bin { border: 1.4px dashed var(--in); background: rgba(91,91,214,.12); }
.node.tN.bout, .node.tP.bout { border: 1.4px dashed var(--out); background: rgba(217,130,43,.13); }
.node.tN.bin:hover, .node.tN.bout:hover { border-style: solid; }
.node[data-io]::before { content: attr(data-io); position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translate(-50%, 3px) scale(.9);
  padding: 2px 6px; border-radius: 6px; font: 600 10px/1.4 system-ui, sans-serif; letter-spacing: .02em; white-space: nowrap; color: #fff;
  background: var(--in); opacity: 0; pointer-events: none; transition: opacity .15s, transform .22s cubic-bezier(.3,1.4,.5,1); }
.node.bout[data-io]::before { background: var(--out); }
.node[data-io]:hover::before { opacity: 1; transform: translate(-50%, 0) scale(1); }
.preview .node[data-io]::before { display: none; }

/* Dot: a small routing point */
.node.tP { width: 7px; height: 7px; border-radius: 50%; background: #3a3a40; border: 0; transition: transform .15s; }
.node.tP:hover { transform: translate(-50%, -50%) scale(1.35); }
.node.tP.bin, .node.tP.bout { width: 9px; height: 9px; }
.preview .node.tP, .mini .node.tP { opacity: 0; }
.sw.P { width: 7px; height: 7px; background: #3a3a40; border: 0; }
.sw.P.lg { width: 8px; height: 8px; }

/* diagram facts card */
.fbar .fl[data-stat] { cursor: default; border-radius: 6px; transition: background .15s, color .15s; padding: 2px 6px; }
.fbar .fl[data-stat]:hover { background: rgba(0,0,0,.06); color: var(--ink); }
#statCard { position: fixed; z-index: 70; width: 232px; padding: 12px 14px 11px; background: #fff; border-radius: 13px; pointer-events: none;
  box-shadow: 0 12px 34px rgba(0,0,0,.13), 0 0 0 1px rgba(0,0,0,.05); opacity: 0; transform: translateY(4px) scale(.96);
  transition: opacity .16s, transform .26s cubic-bezier(.22,1,.36,1); font-size: 12.5px; color: var(--ink); }
#statCard.below { transform: translateY(-4px) scale(.96); }
#statCard.show { opacity: 1; transform: none; }
.sc-h { display: flex; align-items: center; justify-content: space-between; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.sc-kind { text-transform: none; letter-spacing: 0; font-size: 11px; padding: 2px 7px; border-radius: 10px; background: var(--soft); color: var(--ink); }
.sc-kind.k-Clifford { background: rgba(42,157,92,.12); color: #1f7a47; }
.sc-kind.k-CliffordT { background: rgba(91,91,214,.12); color: #4747b8; }
.sc-kind.k-General { background: rgba(217,130,43,.14); color: #a85f14; }
.sc-io { display: flex; align-items: baseline; gap: 6px; margin: 8px 0 9px; }
.sc-n { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.sc-n.in { color: var(--in); } .sc-n.out { color: var(--out); }
.sc-arr { color: var(--muted); font-size: 15px; }
.sc-dim { margin-left: 4px; font-size: 11.5px; color: var(--muted); }
.sc-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.sc-sp { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }
.sc-w { margin-left: auto; color: var(--muted); }
.sc-foot { display: flex; flex-wrap: wrap; gap: 4px 12px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; }
.sc-foot b { color: var(--ink); font-weight: 600; margin-left: 2px; }

/* page lock */
.zlk svg { overflow: visible; }
.zlk .lk-sh { transform-origin: 16px 11px; transform: translateY(-2px) rotate(32deg); transition: transform .42s cubic-bezier(.3,1.5,.5,1); }
.zlk.on .lk-sh { transform: none; }
.zlk .lk-b { fill: transparent; transition: fill .25s; }
.zlk.on { color: var(--ink); }
.zlk.on .lk-b { fill: currentColor; fill-opacity: .14; }
.zlk.nudge { animation: swtnudge .45s cubic-bezier(.3,1.4,.5,1); }
.tlock { display: grid; place-items: center; margin-right: 4px; color: var(--muted); animation: tconfIn .3s cubic-bezier(.3,1.4,.5,1); }
/* locked page: editing affordances step back, viewing stays */
.pg-locked #dock .tool[data-tool]:not([data-tool="select"]):not([data-tool="hand"]), .pg-locked #dock #dUndo, .pg-locked #dock #dRedo, .pg-locked #dock #dDel { opacity: .32; }
.pg-locked #viewport { cursor: grab; }
.pg-locked #viewport .node, .pg-locked #viewport .edge, .pg-locked #viewport .sep { cursor: inherit; }
.pg-locked #world .addd, .pg-locked #world .sepins, .pg-locked #world .fbar [data-act="dup"], .pg-locked #world .fbar [data-act="opts"], .pg-locked #world .fbar [data-act="rot"], .pg-locked #world .fbar [data-act="del"], .pg-locked #world .fbar .grip { opacity: 0; pointer-events: none; }
.pg-locked #btnSingle, .pg-locked #btnTidy, .pg-locked #btnWrap { opacity: .4; }
@media (max-width: 820px) { #zoombar .zlk { display: grid !important; width: 36px; height: 36px; border-radius: 11px; background: #fff; box-shadow: var(--shadow); margin-right: 6px; } }

/* facts card: pinned by a click, title renames in place */
#statCard.pinned { pointer-events: auto; }
.sc-name { text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 600; color: var(--ink); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 4px; transition: color .15s; }
#statCard.pinned .sc-name { cursor: text; }
#statCard.pinned .sc-name:hover { color: var(--accent); }
.sc-inp { font: inherit; font-size: 13px; font-weight: 600; color: var(--ink); border: 0; outline: none; background: transparent; padding: 0; margin: 0; max-width: 150px; caret-color: var(--accent); transition: width .2s cubic-bezier(.22,1,.36,1); }
.sc-inp::placeholder { color: #b5b5b0; }
.sc-inp::selection { background: rgba(91,91,214,.22); }
.sc-inp.dup { color: #c0392b; animation: swtnudge .4s cubic-bezier(.3,1.4,.5,1); }
.fbar .fl[data-stat] { cursor: pointer; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* canvas menu: backups */
.bk-list { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows .3s cubic-bezier(.22,1,.36,1), opacity .2s; }
.bk-list > .bk-in { min-height: 0; overflow: hidden; }   /* one child: the 0fr row collapses all of it */
.bk-list.open { grid-template-rows: 1fr; opacity: 1; }
.bk-list.open > .bk-in { max-height: 260px; overflow-y: auto; }
.bk-item { display: flex; align-items: center; gap: 6px; padding: 5px 6px 5px 30px; border-radius: 8px; }
.bk-item:hover { background: var(--soft); }
.bk-item .mtext { flex: 1; min-width: 0; }

/* a calculation complained about these nodes */
.errbox { position: absolute; border: 1.6px dashed rgba(214,69,58,.55); background: rgba(214,69,58,.06); border-radius: 16px; pointer-events: none; z-index: 2;
  animation: errIn .5s cubic-bezier(.3,1.4,.5,1) both, errPulse 1.1s ease-in-out .5s 2; }
@keyframes errIn { from { opacity: 0; transform: scale(1.25); } }
@keyframes errPulse { 50% { box-shadow: 0 0 0 7px rgba(214,69,58,.12); border-color: rgba(214,69,58,.85); } }
.preview .errbox { display: none; }
.errgo { margin-left: 6px; font-size: inherit; }

.ghost-line.fan { stroke: var(--accent); stroke-dasharray: 4 4; opacity: .55; animation: fanDash .6s linear infinite; }
@keyframes fanDash { to { stroke-dashoffset: -8; } }

.warnline { color: #a85f14; }
select.sel { height: 30px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font: inherit; font-size: 13px; padding: 0 8px; }

/* TikZ tab: code and the image it draws, side by side */
.tkwrap { display: grid; grid-template-columns: 1fr minmax(180px, 38%); gap: 10px; }
.tkwrap .code { min-height: 260px; }
.tkprev { border-radius: 10px; background: #fff; box-shadow: inset 0 0 0 1px var(--line); display: grid; place-items: center; padding: 10px; overflow: auto; max-height: 340px; }
.tkprev svg { max-width: 100%; height: auto; }
@media (max-width: 640px) { .tkwrap { grid-template-columns: 1fr; } }

/* background computing */
.mbusy .linkbtn { margin-left: 10px; font-size: 12.5px; }
.sbar { height: 3px; border-radius: 2px; background: var(--soft); overflow: hidden; margin-top: 8px; }
.sbar span { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .35s cubic-bezier(.22,1,.36,1); }
#matRoot .mxlist { transition: opacity .2s; }
#matRoot.mstale .mxlist { opacity: .45; }

/* presentation */
.zplay { color: var(--ink); }
.zplay svg { transition: transform .25s cubic-bezier(.3,1.5,.5,1); }
.zplay:hover svg { transform: scale(1.12); }
#show { position: fixed; inset: 0; z-index: 300; background: #fbfbf9; opacity: 0; transition: opacity .26s ease; cursor: default; user-select: none; }
#show.open { opacity: 1; }
#show.idle { cursor: none; }
.show-stage { position: absolute; inset: 0; overflow: hidden; }
.show-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.show-world .node { cursor: inherit; }
.show-world .node.tN, .show-world .node.tP { opacity: 0 !important; }
.show-svg { position: absolute; left: 0; top: 0; overflow: visible; }
.show-wire { fill: none; stroke: #1d1d1f; stroke-width: 1.4; stroke-linecap: round; }
.show-h { fill: var(--h); stroke: #1d1d1f; stroke-width: 1; }
.show-cap { position: absolute; left: 0; right: 0; top: 7vh; display: flex; flex-direction: column; align-items: center; gap: 10px; pointer-events: none; }
.show-cap.in .show-rel { animation: capIn .5s cubic-bezier(.22,1,.36,1) both; }
.show-cap.in .show-name { animation: capIn .5s cubic-bezier(.22,1,.36,1) .06s both; }
@keyframes capIn { from { opacity: 0; transform: translateY(8px); } }
.show-rel { font-size: 30px; color: #6b2d8f; }
.show-name { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.show-bar { position: absolute; left: 50%; bottom: 5vh; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 14px;
  background: rgba(255,255,255,.9); box-shadow: 0 6px 24px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04); transition: opacity .35s, transform .35s cubic-bezier(.22,1,.36,1); }
#show.idle .show-bar { opacity: 0; transform: translate(-50%, 10px); }
.show-btn { width: 30px; height: 30px; border: 0; border-radius: 9px; background: transparent; color: var(--ink); display: grid; place-items: center; cursor: pointer; transition: background .15s, transform .1s; }
.show-btn:hover { background: var(--soft); }
.show-btn:active { transform: scale(.9); }
.show-dots { display: flex; gap: 6px; padding: 0 6px; }
.show-dot { width: 7px; height: 7px; padding: 0; border: 0; border-radius: 4px; background: #d0d0cc; cursor: pointer; transition: width .3s cubic-bezier(.22,1,.36,1), background .2s; }
.show-dot.on { width: 20px; background: var(--ink); }
.show-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 36px; text-align: center; }
@media (max-width: 820px) { #zoombar .zplay { display: grid !important; width: 36px; height: 36px; border-radius: 11px; background: #fff; box-shadow: var(--shadow); margin-right: 6px; } .show-rel { font-size: 24px; } }

/* export format tabs in the title row */
.sheet header .hdr-tabs { margin: 0 auto 0 16px; animation: optsIn .3s cubic-bezier(.22,1,.36,1); }
@media (max-width: 640px) { .sheet header .hdr-tabs { margin-left: 10px; } .sheet header .hdr-tabs button { padding: 0 9px; } }

/* presentation: two diagrams per slide */
.show-prel { position: absolute; transform: translate(-50%, -50%); font-size: 34px; color: #6b2d8f; white-space: nowrap; }
.show-arrow { margin: 0 10px; color: #b9b9b2; font-weight: 400; }
.show-sep { width: 1px; height: 18px; background: var(--line); margin: 0 2px; }
.show-pairbtn { color: var(--muted); }
.show-pairbtn.on { color: #fff; background: var(--ink); }
.show-pairbtn.on:hover { background: #333; }
.show-pairbtn svg rect { transition: transform .3s cubic-bezier(.3,1.4,.5,1); transform-box: fill-box; transform-origin: center; }
.show-pairbtn.on svg rect:first-child { transform: translateX(-1px); }
.show-pairbtn.on svg rect:last-child { transform: translateX(1px); }
.show-stage.swap { animation: showSwap .38s ease; }
@keyframes showSwap { from { opacity: 0; } }
@media (max-width: 640px) { .show-prel { font-size: 24px; } }
.mini-empty { position: absolute; border: 1.5px dashed #c9c9c4; border-radius: 4px; box-sizing: border-box; }

/* ---- matrix arrow: bold wire + chevron on the canvas ---- */
.node.tM { width: 60px; height: 30px; border: 0; background: transparent; border-radius: 9px; overflow: visible; }
.node.tM::after { inset: -6px -4px; border-radius: 10px; }
.node.tM .marr { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.m-bar { stroke: #1f1f1f; stroke-width: 3.4; fill: none; }
.m-chev { fill: #b3b3bb; stroke: #1f1f1f; stroke-width: 1.3; stroke-linejoin: miter; transition: fill .2s; }
.node.tM:hover .m-chev { fill: #c9c9e8; }
.node.tM .ml { position: absolute; transform: translateX(-50%); font-size: 10.5px; line-height: 1; color: #2a2a2e; pointer-events: none; white-space: nowrap; }
.node.tM .ml .katex { font-size: 1em; }
.node.tM .ml-a { left: 50%; bottom: calc(50% + 7px); font-size: 12px; }
.node.tM .ml-l { left: 24%; bottom: calc(50% + 3.5px); }
.node.tM .ml-r { left: 76%; bottom: calc(50% + 3.5px); }
.node.tM.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--accent); background: rgba(91,91,214,.06); }
.node.tM.warn .m-chev { fill: #f3c37a; animation: mwarn 1.8s ease-in-out infinite; }
@keyframes mwarn { 50% { fill: #f8dcae; } }
.node.tM[data-warn]::before { content: attr(data-warn); position: absolute; left: 50%; top: calc(100% + 6px); transform: translate(-50%, -3px) scale(.92);
  padding: 3px 7px; border-radius: 6px; font: 600 10.5px/1.35 system-ui, sans-serif; white-space: nowrap; color: #fff; background: #c27a16;
  opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none; z-index: 3; }
.node.tM[data-warn]:hover::before { opacity: 1; transform: translate(-50%, 0) scale(1); }
.tool[data-tool="M"] .ti svg { display: block; }

/* ---- matrix arrow panel ---- */
#insp.mpanel { width: 330px; }
.m-head { margin-bottom: 1px; }
.m-ttl { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; padding-left: 4px; color: var(--ink); }
.m-ttl svg { color: var(--ink); }
.m-sp { flex: 1; }
.m-f { flex: 1 1 0; padding: 0 8px; gap: 6px; }
.m-f input { min-width: 0; font-family: inherit; font-size: 13px; }
.m-body { display: flex; gap: 12px; align-items: flex-start; }
.m-gw { position: relative; padding: 4px 9px; flex: none; transition: opacity .2s; }
.m-gw::before, .m-gw::after { content: ''; position: absolute; top: 2px; bottom: 16px; width: 6px; border: 1.4px solid #8a8a90; }
.m-gw::before { left: 0; border-right: 0; border-radius: 6px 0 0 6px; }
.m-gw::after { right: 14px; border-left: 0; border-radius: 0 6px 6px 0; }
.m-gw.none { display: none; }
.m-grid { display: grid; grid-auto-rows: 24px; gap: 2px; }
.mb { border: 0; border-radius: 6px; background: transparent; font: 500 13px/1 var(--mono); color: #b0b0b6; cursor: pointer; padding: 0;
  transition: background .15s, color .15s, transform .1s; }
.mb:hover { background: var(--soft); color: var(--ink); }
.mb.on { color: #8a4b08; background: #fdebd3; box-shadow: inset 0 0 0 1px #efc795; }
.mb.on:hover { background: #fbdfba; }
.mb:active { transform: scale(.9); }
.madd { border: 0; background: transparent; color: #b8b8be; font-size: 12px; line-height: 1; border-radius: 6px; cursor: pointer; padding: 0; opacity: 0; transition: opacity .15s, background .15s; }
.m-gw:hover .madd { opacity: 1; }
.madd:hover { background: rgba(91,91,214,.1); color: var(--accent); }
.madd.mc { margin-left: 4px; }
.madd.mr { height: 12px; align-self: start; }
.m-grid { grid-auto-rows: 24px; }
.m-tw { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.m-text { width: 100%; resize: vertical; min-height: 66px; border: 0; border-radius: 8px; background: var(--soft); padding: 7px 9px; outline: none;
  font: 13px/1.45 var(--mono); color: var(--ink); transition: box-shadow .15s, background .15s; }
.m-text:focus { background: #fff; box-shadow: 0 0 0 2px rgba(91,91,214,.35); }
.m-text.bad, .m-text.bad:focus { box-shadow: 0 0 0 2px rgba(211,51,51,.35); }
.m-hint { font-size: 10.5px; color: var(--muted); line-height: 1.3; }
.m-foot { margin-top: 2px; }
.m-stat { flex: 1; font-size: 12px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-stat.warn { color: #b06a0c; }
.m-stat.err { color: #c43a3a; }
.m-exp { display: inline-flex; align-items: center; gap: 7px; }
.m-exp kbd { font: 10.5px var(--mono); color: var(--muted); background: var(--soft); border-radius: 4px; padding: 1px 4px; }
.m-exp:disabled { opacity: .45; cursor: default; box-shadow: none; transform: none; }
@media (max-width: 640px) {
  #insp.mpanel { width: auto; }
  .m-body { flex-direction: column; gap: 8px; }
  .m-gw { align-self: center; }
  .madd { opacity: 1; }
  .m-grid { --mbw: 30px; }
  .m-grid { grid-auto-rows: 30px; }
}

/* ports: one per wire on each side; they grow and show their number while the wire tool is near */
.m-fan { fill: none; stroke: #1f1f1f; stroke-width: 1.1; stroke-linejoin: round; }
.m-pt { fill: #fff; stroke: #8c8c94; stroke-width: 1; transform-box: fill-box; transform-origin: center; transition: fill .15s; }
.m-pt.on { fill: #1f1f1f; stroke: #1f1f1f; }
.node.tM:not(.warn) .m-pt.on { transform: scale(.75); }
.marr.near .m-pt { animation: mpIn .34s cubic-bezier(.3,1.5,.5,1) both; animation-delay: calc(var(--age) + var(--i) * 35ms);
  --s: 1.7; stroke: var(--accent); stroke-width: .9; }
.marr.near .m-pt:not(.on) { fill: #fff; }
.marr.near .m-pt.on { fill: var(--accent); }
.marr.near .m-pt.hot { --s: 2.4; fill: var(--accent); stroke: #fff; stroke-width: .7; filter: drop-shadow(0 0 2px rgba(91,91,214,.6)); }
@keyframes mpIn { from { transform: scale(.6); opacity: .4; } to { transform: scale(var(--s)); opacity: 1; } }
.marr.near .m-pt { transform: scale(var(--s)); }
.m-num { font: 600 7.5px/1 system-ui, sans-serif; fill: var(--accent); opacity: 0; animation: mnIn .3s ease-out both;
  animation-delay: calc(var(--age) + 80ms + var(--i) * 35ms); }
.m-num.hot { font-size: 9px; }
@keyframes mnIn { from { opacity: 0; transform: translateY(2px); } to { opacity: .9; transform: none; } }
.node.tM .marr { left: 50%; top: 50%; transform: translate(-50%, -50%); }

/* panel v2: the name is the title (inline rename), no extra rows */
.m-name { border: 0; background: transparent; outline: none; padding: 2px 3px; margin-left: -3px; border-radius: 5px;
  font: 600 14px/1.2 inherit; font-family: inherit; color: var(--ink); min-width: 2ch; max-width: 170px; cursor: text; transition: background .15s, box-shadow .15s; }
.m-name:hover { background: var(--soft); }
.m-name:focus { background: transparent; box-shadow: 0 1.5px 0 var(--accent); border-radius: 0; }
.m-body .m-text { flex: 1; min-width: 0; }
.m-stat[hidden] { display: none; }
.m-stat { white-space: normal; }
.ib:disabled { opacity: .35; cursor: default; background: transparent; }
/* arrow → arrow: one bold wire */
.edge.bundle .wire-p { stroke-width: 3.4; stroke-linecap: butt; }
.edge.bundle.sel .wire-p { stroke: var(--accent); }
/* convert-to-matrix-arrow icon in the selection panel: appears with a small pop */
.ib.m-conv { width: 34px; color: var(--ink); animation: mconv .3s cubic-bezier(.3,1.5,.5,1); }
.ib.m-conv:hover { color: var(--accent); background: rgba(91,91,214,.1); }
@keyframes mconv { from { transform: scale(.6); opacity: 0; } }

/* ---------- box-select filter (click V again / right-click V) ---------- */
.tool.filt::after { content: ''; position: absolute; top: 4px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1.5px #fff; animation: pkdot .3s cubic-bezier(.3,1.6,.5,1); }
@keyframes pkdot { from { transform: scale(0); } }
.pickpop { position: fixed; z-index: 85; width: 216px; padding: 6px; background: #fff; border-radius: 13px; box-shadow: 0 14px 36px rgba(0,0,0,.16), 0 0 0 1px rgba(0,0,0,.05);
  opacity: 0; transform: translateY(10px) scale(.86); transition: opacity .16s, transform .32s cubic-bezier(.22,1.25,.36,1); }
.pickpop[data-side="left"] { transform: translateX(-10px) scale(.86); }
.pickpop[data-side="right"] { transform: translateX(10px) scale(.86); }
.pickpop.show { opacity: 1; transform: none; }
.pickpop .pk-row { opacity: 0; transform: translateY(4px); transition: opacity .2s, transform .25s cubic-bezier(.22,1,.36,1), background .1s; }
.pickpop.show .pk-row { opacity: 1; transform: none; }
.pickpop.show .pk-row:nth-child(2) { transition-delay: .02s; } .pickpop.show .pk-row:nth-child(3) { transition-delay: .04s; }
.pickpop.show .pk-row:nth-child(4) { transition-delay: .06s; } .pickpop.show .pk-row:nth-child(5) { transition-delay: .08s; }
.pickpop.show .pk-row:nth-child(6) { transition-delay: .10s; } .pickpop.show .pk-row:nth-child(7) { transition-delay: .12s; }
.pickpop.show .pk-row:nth-child(8) { transition-delay: .14s; }
.pk-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 6px 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.pk-all { border: 0; background: none; font: inherit; font-size: 12px; color: var(--accent); cursor: pointer; padding: 2px 6px; border-radius: 6px; transition: opacity .15s, background .1s; }
.pk-all:hover:not(:disabled) { background: rgba(91,91,214,.1); }
.pk-all:disabled { opacity: 0; pointer-events: none; }
.pk-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.pk-row:hover { background: var(--soft); }
.pk-ic { width: 16px; display: grid; place-items: center; flex: none; }
.pk-l { flex: 1; }
.pk-t { font-weight: 700; line-height: 1; }
.pk-m { width: 14px; height: 3px; background: #1f1f1f; border-radius: 2px; position: relative; }
.pk-m::after { content: ''; position: absolute; right: -1px; top: -3px; border: 4.5px solid transparent; border-left: 5px solid #1f1f1f; border-right: 0; }
.pk-w { width: 14px; height: 1.6px; background: #1f1f1f; border-radius: 1px; }
@media (max-width: 640px) { .pickpop { width: min(260px, calc(100vw - 16px)); } .pk-row { padding: 9px 8px; } }

/* ---------- wire colour + line style ---------- */
.edge.colored .wire-p, .edge.colored:hover .wire-p { stroke: var(--wc); }
.edge.colored.sel .wire-p { stroke: var(--wc); stroke-width: 2.2; }
.edge.colored.sel .hit { stroke: rgba(91,91,214,.16); }
.edge.colored:hover:not(.sel) .hit { stroke: rgba(0,0,0,.05); }
.edge.ls-dash .wire-p { stroke-dasharray: 6 4; }
.edge.ls-dot .wire-p { stroke-dasharray: 0 4; stroke-width: 2.2; }
.edge.ls-dot.sel .wire-p { stroke-width: 2.8; }
.wlook { margin-top: 6px; gap: 6px; }
.wcols { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; padding: 0 4px; }
.wc { width: 15px; height: 15px; border-radius: 4px; border: 0; padding: 0; cursor: pointer; background: var(--c); position: relative; flex: none;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.07); transition: transform .18s cubic-bezier(.3,1.6,.5,1), box-shadow .18s, border-radius .18s; }
.wc:hover { transform: scale(1.15); }
.wc:active { transform: scale(.88); }
.wc.on { border-radius: 5px; box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--c); }
.lsi { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.lsi.ls-dash { stroke-dasharray: 5 3.5; }
.lsi.ls-dot { stroke-dasharray: 0 4; stroke-width: 2.4; }
@media (max-width: 640px) { .wcols { gap: 10px; } .wc { width: 20px; height: 20px; } }
.pk-row { position: relative; }
/* floats over the label next to the switch: takes no room until hovered */
.pk-sw { position: relative; display: flex; align-items: center; flex: none; }
.pk-only { position: absolute; right: calc(100% + 8px); top: 50%; height: 22px; margin-top: -11px; display: inline-flex; align-items: center; line-height: 1; white-space: nowrap; border: 0; background: #e9e9fb; color: var(--accent); font: inherit; font-size: 11px; font-weight: 600; padding: 0 8px; border-radius: 6px; cursor: pointer;
  box-shadow: -10px 0 8px -2px var(--soft);
  opacity: 0; transform: translateX(6px) scale(.9); pointer-events: none; transition: opacity .16s, transform .22s cubic-bezier(.22,1.3,.36,1), background .12s, color .12s; }
.pk-row:hover .pk-only, .pk-only:focus-visible { opacity: 1; transform: none; pointer-events: auto; }
.pk-only:hover { background: #dcdcf8; }
.pk-only:active { transform: scale(.9); }
.pk-only.pop { animation: pkonly .32s cubic-bezier(.3,1.6,.5,1); }
@keyframes pkonly { 40% { transform: scale(.85); background: rgba(91,91,214,.2); color: var(--accent); } }
@media (hover: none) { .pk-sw { gap: 8px; } .pk-only { position: static; margin: 0; box-shadow: none; background: var(--soft); color: var(--muted); opacity: 1; transform: none; pointer-events: auto; } }
#insp button:focus:not(:focus-visible) { outline: none; }
.chip.glyph { min-width: 32px; padding: 0 8px; font-size: 15px; line-height: 1; font-family: 'Cambria Math', 'STIX Two Math', 'Times New Roman', serif; }

/* ---------- hold ⌘ / Ctrl: neighbours of the selection pulse ---------- */
.nb-layer { position: absolute; left: 0; top: 0; pointer-events: none; }
.nb-ring, .nb-src { position: absolute; transform: translate(-50%, -50%); pointer-events: none; }
.nb-ring { box-shadow: var(--nbs); animation: nbpulse 1.25s cubic-bezier(.35,0,.25,1) var(--nbd, 0s) infinite both; }
.nb-ring::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: 0 0 0 2px var(--nbg); animation: nbwave 1.25s cubic-bezier(.2,.6,.3,1) var(--nbd, 0s) infinite both; }
.nb-src { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--nbc); animation: nbsrc 1.25s ease-in-out var(--nbd, 0s) infinite both; }
@keyframes nbpulse { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.75); } 22% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); } 45% { transform: translate(-50%, -50%) scale(1); } 75% { opacity: .9; } 100% { opacity: .15; transform: translate(-50%, -50%) scale(1); } }
@keyframes nbwave { 0%, 18% { opacity: 0; transform: scale(1); } 25% { opacity: .7; } 100% { opacity: 0; transform: scale(2.1); } }
@keyframes nbsrc { 0%, 100% { opacity: .55; } 22% { opacity: 1; } }
.edge.nb-wire .wire-p { stroke: var(--nbc); stroke-width: 2.4; animation: nbwire 1.25s ease-in-out var(--nbd, 0s) infinite both; }
@keyframes nbwire { 0%, 100% { stroke-opacity: .35; } 22% { stroke-opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .nb-ring, .nb-ring::after, .nb-src, .edge.nb-wire .wire-p { animation: none; } }

/* ---------- grid switch: no dots when off ---------- */
/* Check / Matrix / Simplify as plain icons in the top bar */
.ibtn { position: relative; }
.ibtn .bi { display: grid; place-items: center; line-height: 0; }
.ibtn.cbtn.on { background: rgba(42,157,92,.1); color: #2a9d5c; }
.ibtn.cbtn.on:hover { background: rgba(42,157,92,.16); }
.ibtn.cbtn .cbad { position: absolute; top: 2px; right: 1px; min-width: 14px; height: 14px; padding: 0 3px; border-radius: 7px; font: 600 9px/14px system-ui, sans-serif; box-shadow: 0 0 0 2px var(--bg); animation: okpop .25s cubic-bezier(.3,1.5,.5,1); }

/* ---- Hadamard edge: blue, bold, dashed (a wire with an H on it) ---- */
:root { --he: #4488cc; }
.edge.hedge .wire-p, .edge.hedge:hover .wire-p, .edge.hedge.colored .wire-p { stroke: var(--he); stroke-width: 3.2; stroke-dasharray: 6.5 4; stroke-linecap: butt; }
.edge.hedge:hover:not(.sel) .wire-p { stroke: #2f6fb0; }
.edge.hedge.sel .wire-p { stroke: var(--he); stroke-width: 3.8; filter: drop-shadow(0 0 2.5px rgba(91,91,214,.55)); }
.wire-p.hedge-p, .show-wire.hedge-p { stroke: var(--he); stroke-width: 3.2; stroke-dasharray: 6.5 4; stroke-linecap: butt; }
.sw.HE { width: 16px; height: 0; border: 0; border-top: 2.6px dashed var(--he); border-radius: 0; background: none; }

/* wire tool kinds (click E again / right-click): two small icon buttons, name on a long hover */
.wirepop { width: auto; display: flex; flex-direction: column; gap: 2px; padding: 4px; border-radius: 11px; overflow: visible; }
.wirepop.row { flex-direction: row; }
.wk { position: relative; display: grid; place-items: center; width: 40px; height: 32px; border: 0; background: none; border-radius: 8px; cursor: pointer; padding: 0;
  opacity: 0; transform: scale(.8); transition: opacity .18s, transform .26s cubic-bezier(.3,1.5,.5,1), background .12s; -webkit-tap-highlight-color: transparent; }
.wirepop.show .wk { opacity: 1; transform: none; }
.wirepop.show .wk:nth-child(2) { transition-delay: .035s, .035s, 0s; }
.wk:hover { background: var(--soft); }
.wk:active { transform: scale(.9); }
.wk.on { background: #ececfb; }
.wk-line { fill: none; stroke: #1f1f1f; stroke-width: 1.5; stroke-linecap: round; }
.wk-line.h { stroke: var(--he); stroke-width: 2.6; stroke-dasharray: 3.6 2.4; stroke-linecap: butt; }
.wk-end { fill: #fff; stroke: #1f1f1f; stroke-width: 1.2; }
.wk.on .wk-end { stroke: var(--accent); }
.wk::after { content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translate(-50%, 3px); white-space: nowrap; pointer-events: none;
  font-size: 11.5px; font-weight: 500; color: #fff; background: rgba(29,29,31,.92); padding: 4px 8px; border-radius: 6px; opacity: 0; transition: opacity .12s, transform .12s; }
.wirepop:not(.row) .wk::after { left: calc(100% + 8px); bottom: auto; top: 50%; transform: translate(-3px, -50%); }
.wirepop[data-side="right"] .wk::after { left: auto; right: calc(100% + 8px); transform: translate(3px, -50%); }
.wk:hover::after { opacity: 1; transform: translate(-50%, 0); transition-delay: .75s; }
.wirepop:not(.row) .wk:hover::after { transform: translate(0, -50%); }
@media (hover: none) { .wk::after { display: none; } }
@media (max-width: 640px) { .wk { width: 46px; height: 38px; } }

/* export looks: one quiet row of toggles at the bottom of LaTeX / Image / TikZ */
.looks { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 10px 0 2px; }
.lk-lab { font-size: 12px; color: var(--muted); margin-right: 4px; }
.lk { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 9px 0 10px; border: 0; border-radius: 999px; background: transparent; color: var(--muted);
  font: inherit; font-size: 12.5px; cursor: pointer; transition: background .18s, color .18s, transform .18s cubic-bezier(.3,1.6,.5,1); -webkit-tap-highlight-color: transparent; }
.lk:hover { background: var(--soft); }
.lk:active { transform: scale(.94); }
.lk.on { background: #ededfb; color: var(--ink); }
.lk-ic { display: grid; place-items: center; }
.lk-ic svg path { stroke-linecap: round; stroke-width: 2; }
.lk:not(.on) .lk-ic { filter: grayscale(1); opacity: .45; transition: filter .2s, opacity .2s; }
.lk-tick { position: relative; width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1.4px #c9c9cf; transition: box-shadow .2s, background .2s; }
.lk-tick::after { content: ''; position: absolute; left: 4.6px; top: 2.6px; width: 3px; height: 6px; border: solid #fff; border-width: 0 1.7px 1.7px 0; transform: rotate(45deg) scale(0); transition: transform .28s cubic-bezier(.3,1.6,.5,1); }
.lk.on .lk-tick { background: var(--accent); box-shadow: none; }
.lk.on .lk-tick::after { transform: rotate(45deg) scale(1); }
@media (max-width: 640px) { .looks { gap: 4px; } .lk-lab { width: 100%; margin-bottom: 2px; } .lk { height: 34px; } }
.pk-w.h { height: 0; background: none; border-top: 2.4px dashed var(--he); border-radius: 0; }
.pickpop.show .pk-row:nth-child(9) { transition-delay: .16s; }

/* Grid / Half grid: one switch, the state written on it */
.gsw { padding: 0 4px; }
.gsw-track { position: relative; display: block; width: 66px; height: 20px; border-radius: 10px; background: #3a3a3c; overflow: hidden;
  transition: background .3s cubic-bezier(.22,1,.36,1); }
.swt.gsw:not(.on) .gsw-track { background: var(--accent); }
.gsw-knob { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transform: translateX(46px); transition: transform .38s cubic-bezier(.3,1.4,.5,1), width .18s; }
.swt.gsw:not(.on) .gsw-knob { transform: none; }
.swt.gsw:active .gsw-knob { width: 17px; }
.swt.gsw.on:active .gsw-knob { transform: translateX(43px); }
.gsw-t { position: absolute; top: 0; line-height: 20px; font-size: 10.5px; font-weight: 600; color: #fff; white-space: nowrap; letter-spacing: 0;
  transition: opacity .22s, transform .34s cubic-bezier(.22,1,.36,1); }
.gsw-t.g1 { left: 1px; width: 47px; text-align: center; }
.gsw-t.g2 { right: 1px; width: 48px; text-align: center; opacity: 0; transform: translateX(10px); }
.swt.gsw:not(.on) .gsw-t.g1 { opacity: 0; transform: translateX(-10px); }
.swt.gsw:not(.on) .gsw-t.g2 { opacity: 1; transform: none; }
.swt.gsw:hover { background: transparent; }
.swt.gsw:hover .gsw-track { filter: brightness(1.08); }

/* box (t B): a labelled gate spanning cells; size set inline from ZX.boxGeom */
.node.tB { background: var(--bx, #e9ecf1); border-radius: 2px; font-size: 14px; transition: box-shadow .15s, width .08s ease-out, height .08s ease-out; }
.node.tB::after { inset: -5px; border-radius: 6px; }
.node.tB .bxl { pointer-events: none; display: inline-block; white-space: nowrap; transition: transform .2s ease; }
.node.tB .bxl.vt { transform: rotate(-90deg); }
.node.tB.sel, .wire .node.tB:hover { box-shadow: none; border-color: var(--accent); transition: border-color .15s, width .08s ease-out, height .08s ease-out; }   /* its own edge lights up, no outer ring */
.preview .node.tB.sel { border-color: #1f1f1f; }
.node.tB .bxl .katex { font-size: 1.05em; }
.bxh { position: absolute; z-index: 2; background: #fff; border: 1.5px solid var(--accent); border-radius: 3px; opacity: 0; transition: opacity .15s, transform .15s; }
.node.tB.sel .bxh { opacity: 1; }
.bxh.l, .bxh.r { width: 6px; height: 16px; top: 50%; margin-top: -8px; cursor: ew-resize; }
.bxh.t, .bxh.b { width: 16px; height: 6px; left: 50%; margin-left: -8px; cursor: ns-resize; }
.bxh.l { left: -4px; } .bxh.r { right: -4px; } .bxh.t { top: -4px; } .bxh.b { bottom: -4px; }
.bxh:hover { transform: scale(1.25); background: var(--accent); }
.bxh::after { content: ''; position: absolute; inset: -8px; }
.preview .bxh { display: none; }
.chip.bxc .katex { font-size: 1em; pointer-events: none; }
.bxtop { align-items: center; gap: 8px; }
.bxtop .chips { flex: 1; min-width: 0; }
.bszrow { gap: 8px; }
.bsz { display: inline-flex; align-items: center; height: 24px; padding-left: 7px; border-radius: 7px; background: var(--soft); color: var(--muted); }
.bsz svg { flex: none; margin-right: 1px; width: 12px; height: 12px; }
.bsz button { width: 22px; height: 24px; border: 0; background: transparent; color: var(--muted); font-size: 15px; line-height: 1; cursor: pointer; border-radius: 7px; transition: color .12s, background .12s, transform .1s; }
.bsz button:hover:not(:disabled) { color: var(--ink); background: rgba(0, 0, 0, .05); }
.bsz button:active:not(:disabled) { transform: scale(.88); }
.bsz button:disabled { opacity: .3; cursor: default; }
/* box panel: a size smaller than the other panels */
#insp.bxpanel { padding: 6px; gap: 5px; }
#insp.bxpanel .field { height: 26px; border-radius: 7px; }
#insp.bxpanel .field input { font-size: 12px; }
#insp.bxpanel .ib { width: 26px; height: 24px; }
#insp.bxpanel .chips { gap: 3px; }
#insp.bxpanel .chip { height: 21px; padding: 0 7px; font-size: 11px; }
#insp.bxpanel .seg { padding: 2px; border-radius: 8px; }
#insp.bxpanel .seg button { height: 22px; min-width: 24px; padding: 0 5px; }
#insp.bxpanel .seg button svg { width: 15px; height: 15px; }
#insp.bxpanel .wcols { gap: 6px; }
#insp.bxpanel .wc { width: 13px; height: 13px; }
.bsz input { width: 26px; border: 0; background: transparent; outline: none; text-align: center; font: 12px var(--mono); color: var(--ink); padding: 0; }
@media (max-width: 640px) { .bsz button { width: 32px; height: 34px; } .bsz { height: 34px; } }
.pend-h .bh-dot { stroke-width: 1.8; }
.pend-h { cursor: grab; }
/* snapping a wire end: preview of the connection */
.mag-dot { fill: rgba(91,91,214,.14); stroke: var(--accent); stroke-width: 1.4; pointer-events: none; transform-box: fill-box; transform-origin: center;
  animation: magIn .13s cubic-bezier(.3,1.5,.5,1), magPulse 1s ease-in-out .13s infinite; }
@keyframes magIn { from { transform: scale(.2); opacity: 0; } }
@keyframes magPulse { 50% { transform: scale(1.35); opacity: .55; } }
.edge.pv, .edge.pv-src { pointer-events: none; }
.edge.pv .wire-p { stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 5 4; opacity: .62; animation-name: pvIn, pvFlow; animation-duration: .09s, .6s; animation-timing-function: ease-out, linear; animation-iteration-count: 1, infinite; animation-delay: inherit; }
@keyframes pvIn { from { opacity: 0; } }
@keyframes pvFlow { to { stroke-dashoffset: -9; } }
.edge.pv-src { opacity: .28; animation-name: pvIn; animation-duration: .09s; animation-timing-function: ease-out; }

/* ---------- share card, embedded view ---------- */
.pop[data-kind="share"] { width: 330px; }
.shrow { display: flex; gap: 6px; align-items: center; }
.shrow.end { justify-content: flex-end; gap: 12px; margin-top: 6px; }
.shrow .field { height: 32px; }
.shlink, .shemb textarea { flex: 1; min-width: 0; border: 0; border-radius: 8px; background: var(--soft); color: var(--ink); font: 12.5px var(--mono); padding: 0 10px; height: 32px; outline: none; }
.shemb textarea { height: auto; padding: 8px 10px; resize: none; line-height: 1.4; }
.shlink:focus, .shemb textarea:focus { box-shadow: 0 0 0 2px rgba(91,91,214,.35); }
.shgo { height: 36px; width: 100%; justify-content: center; }
.shgo[disabled] { opacity: .7; cursor: progress; }
.shemb summary { font-size: 12px; color: var(--muted); cursor: pointer; padding: 2px; list-style: none; user-select: none; }
.shemb summary::before { content: '›'; display: inline-block; width: 12px; transition: transform .18s; }
.shemb[open] summary::before { transform: rotate(90deg); }
.shemb[open] .shrow:first-of-type { margin-top: 6px; animation: popin .14s ease-out; }
.sherr { font-size: 12px; color: #c0392b; padding: 0 2px; }
@media (max-width: 640px) { .pop[data-kind="share"] { width: auto; } }
body.embed .top, body.embed #dock, body.embed #minimap, body.embed #suggest, body.embed #hint, body.embed #zoombar { display: none !important; }
.emb-open { position: fixed; right: 10px; bottom: 8px; z-index: 30; font-size: 12px; color: var(--muted); text-decoration: none; background: rgba(255,255,255,.85); padding: 3px 8px; border-radius: 6px; }
.emb-open:hover { color: var(--ink); }
