  :root {
    --bg: #fbfbfa;
    --panel: #ffffff;
    --ink: #1c1c1e;
    --muted: #8a8a8f;
    --line: #e6e6e3;
    --accent: #2f6df6;
    --accent-soft: #eaf1ff;
    --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.08);
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
  #app { position: fixed; inset: 0; }

  #canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: default; }
  #canvas.panning { cursor: grabbing; }
  #canvas.placing { cursor: crosshair; }

  /* ---------- Toolbar ---------- */
  #toolbar {
    position: fixed; left: 16px; top: 50%; transform: translateY(-50%);
    background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
    padding: 8px; display: flex; flex-direction: column; gap: 3px;
    box-shadow: var(--shadow); z-index: 10;
    width: 56px; overflow-x: hidden; overflow-y: auto; max-height: calc(100vh - 32px);
    scrollbar-width: none; transition: width .2s cubic-bezier(.2,.7,.3,1), box-shadow .2s ease;
  }
  #toolbar::-webkit-scrollbar { display: none; }
  #toolbar:hover { width: 188px; box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 12px 32px rgba(0,0,0,.12); }
  #toolbar:focus-within { width: 188px; box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 12px 32px rgba(0,0,0,.12); }
  .tool {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0;
    border: none; border-radius: 11px; background: transparent; cursor: pointer; color: #55555a;
    transition: background .12s ease, color .12s ease; text-align: left;
  }
  .tool .ico { width: 40px; height: 40px; flex: none; display: grid; place-items: center; }
  .tool .lbl {
    white-space: nowrap; font-family: "Space Grotesk", sans-serif; font-size: 13.5px; font-weight: 500; letter-spacing: .01em;
    opacity: 0; transform: translateX(-4px); transition: opacity .16s ease, transform .16s ease; line-height: 1.2;
  }
  .tool .lbl .tsub { display: block; font-family: var(--body, sans-serif); font-size: 10px; font-weight: 400; letter-spacing: 0; color: var(--muted); margin-top: 1px; }
  .tool.active .lbl .tsub { color: rgba(255,255,255,.8); }
  #toolbar:hover .lbl, #toolbar:focus-within .lbl { opacity: 1; transform: translateX(0); }
  .tool:hover { background: #f1f1ef; color: var(--ink); }
  .tool.active { background: var(--accent); color: #fff; }
  .tool svg { position: static; width: 20px; height: 20px; pointer-events: none; }
  .sep { height: 1px; background: var(--line); margin: 5px 10px; }
  .grp-label {
    font-family: "Space Grotesk", sans-serif; font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: .12em; color: var(--muted);
    padding: 6px 0 2px 12px; white-space: nowrap; opacity: 0; height: 0; overflow: hidden;
    transition: opacity .16s ease, height .16s ease;
  }
  #toolbar:hover .grp-label, #toolbar:focus-within .grp-label { opacity: 1; height: 18px; }
  /* shape search */
  .search-row { display: flex; align-items: center; height: 40px; }
  .search-row .ico { width: 40px; height: 40px; flex: none; display: grid; place-items: center; color: #55555a; cursor: text; }
  .search-row .ico svg { width: 18px; height: 18px; }
  .search-input { flex: 1; min-width: 0; border: none; background: transparent; font: inherit; font-size: 13px; color: var(--ink); opacity: 0; transition: opacity .16s ease; }
  .search-input::placeholder { color: var(--muted); }
  .search-input:focus { outline: none; }
  #toolbar:hover .search-input, #toolbar:focus-within .search-input { opacity: 1; }
  .tool-empty { font-size: 12px; color: var(--muted); padding: 10px 12px; white-space: nowrap; opacity: 0; }
  #toolbar:hover .tool-empty, #toolbar:focus-within .tool-empty { opacity: 1; }

  /* ---------- Top bar ---------- */
  #topbar {
    position: fixed; left: 50%; top: 16px; transform: translateX(-50%);
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    padding: 7px 14px; display: flex; align-items: center; gap: 12px;
    box-shadow: var(--shadow); z-index: 10; font-size: 13px;
  }
  #topbar .brand { display: flex; align-items: center; gap: 8px; font-family: "Space Grotesk", sans-serif; font-weight: 600; letter-spacing: -.01em; font-size: 14px; }
  #topbar .brand .mark { width: 19px; height: 19px; flex: none; }
  #topbar .brand .flow { color: var(--accent); }
  #topbar .brand .sub { color: var(--muted); font-weight: 400; margin-left: 7px; font-size: 13px; }
  #topbar .hint { color: var(--muted); font-size: 12px; }

  /* ---------- Zoom controls ---------- */
  #zoom {
    position: fixed; right: 16px; bottom: 16px; background: var(--panel);
    border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
    display: flex; align-items: center; z-index: 10; overflow: hidden;
  }
  #zoom button { width: 38px; height: 36px; border: none; background: transparent; cursor: pointer; font-size: 17px; color: #55555a; }
  #zoom button:hover { background: #f1f1ef; }
  #zoom .level { width: 56px; text-align: center; font-size: 12px; color: var(--muted); border-left: 1px solid var(--line); border-right: 1px solid var(--line); height: 36px; line-height: 36px; cursor: pointer; }

  /* ---------- Node visuals ---------- */
  .node-shape { transition: filter .12s ease; }
  .node:hover .node-shape { filter: drop-shadow(0 2px 6px rgba(0,0,0,.12)); }
  .node.selected .sel-ring { opacity: 1; }
  .sel-ring { opacity: 0; }
  .node-label { font-size: 13px; font-weight: 500; fill: var(--ink); pointer-events: none; user-select: none; }
  .node-sub { font-size: 11px; fill: var(--muted); pointer-events: none; user-select: none; }
  .node-type { font-size: 9.5px; font-weight: 500; fill: var(--muted); pointer-events: none; user-select: none; }

  /* connection (edge) labels */
  .edge-label { font-size: 11px; font-weight: 500; fill: #55555a; pointer-events: none; user-select: none; }
  .edge-label-bg { fill: var(--bg); stroke: var(--line); stroke-width: 1; }

  /* connection editor (shares the node editor's look) */
  #edge-editor {
    position: fixed; width: 248px; background: var(--panel); border: 1px solid var(--line);
    border-radius: 14px; box-shadow: var(--shadow); z-index: 15; padding: 16px; display: none;
  }
  #edge-editor.show { display: block; }
  #edge-editor label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: block; margin: 12px 0 5px; }
  #edge-editor label:first-child { margin-top: 0; }
  #edge-editor input, #edge-editor textarea { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font: inherit; font-size: 13px; resize: none; color: var(--ink); background: #fafafa; }
  #edge-editor input:focus, #edge-editor textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
  #edge-editor .row { display: flex; gap: 8px; margin-top: 16px; }
  #edge-editor button { flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 8px; font: inherit; font-size: 12.5px; cursor: pointer; }
  #edge-editor button.del { color: #d23b3b; }
  #edge-editor button:hover { background: #f6f6f4; }

  /* connection anchors */
  .anchor { opacity: 0; cursor: crosshair; transition: opacity .1s ease; }
  .anchor-hit { fill: transparent; cursor: crosshair; }
  .node:hover .anchor, .connecting .anchor { opacity: 1; }
  .anchor:hover, .anchor-hit:hover + .anchor { r: 6.5; }
  .node.drop-target .node-shape { filter: drop-shadow(0 0 0 3px var(--accent-soft)); }

  /* ---------- Hover popover ---------- */
  #pop {
    position: fixed; max-width: 280px; background: #1f1f22; color: #fff; border-radius: 12px;
    padding: 12px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 20; pointer-events: none;
    opacity: 0; transform: translateY(4px); transition: opacity .12s ease, transform .12s ease; font-size: 12.5px; line-height: 1.5;
  }
  #pop.show { opacity: 1; transform: translateY(0); }
  #pop .t { font-weight: 600; font-size: 13px; margin-bottom: 3px; display: flex; align-items: center; gap: 7px; }
  #pop .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
  #pop .d { color: #c7c7cc; }

  /* ---------- Editor panel ---------- */
  #editor {
    position: fixed; width: 256px; background: var(--panel);
    border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
    z-index: 15; padding: 16px; display: none;
  }
  #editor.show { display: block; }
  #editor label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: block; margin: 12px 0 5px; }
  #editor label:first-child { margin-top: 0; }
  #editor input, #editor textarea {
    width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font: inherit;
    font-size: 13px; resize: none; color: var(--ink); background: #fafafa;
  }
  #editor input:focus, #editor textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
  #editor .swatches { display: flex; gap: 7px; margin-top: 6px; }
  #editor .sw { width: 22px; height: 22px; border-radius: 7px; cursor: pointer; border: 2px solid transparent; }
  #editor .sw.on { border-color: var(--ink); }
  #editor .row { display: flex; gap: 8px; margin-top: 16px; }
  #editor button { flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 8px; font: inherit; font-size: 12.5px; cursor: pointer; }
  #editor button.del { color: #d23b3b; }
  #editor button:hover { background: #f6f6f4; }

  /* ---------- Top-bar diagram name + save status ---------- */
  .bar-sep { width: 1px; height: 18px; background: var(--line); }
  #dname {
    font-family: "Space Grotesk", sans-serif; font-size: 13px; font-weight: 500; color: var(--ink);
    background: transparent; border: none; padding: 4px 8px; border-radius: 7px; cursor: pointer;
    max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  #dname:hover { background: #f1f1ef; }
  #dname.editing { background: #fff; box-shadow: 0 0 0 2px var(--accent); cursor: text; max-width: 320px; overflow: visible; text-overflow: clip; }
  #topshare { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px 0 9px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; font-family: "Space Grotesk", sans-serif; font-size: 12.5px; font-weight: 500; color: var(--ink); }
  #topshare:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
  #topshare svg { width: 14px; height: 14px; }
  #status { width: 8px; height: 8px; border-radius: 50%; flex: none; }
  #status.local { background: #c7c7cc; }
  #status.saved { background: #16a34a; }
  #status.saving { background: #eab308; animation: pulse 1s ease infinite; }
  #status.error { background: #d23b3b; }
  @keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

  /* ---------- Account bar (top-right) ---------- */
  #account-bar { position: fixed; right: 16px; top: 16px; display: flex; align-items: center; gap: 8px; z-index: 10; }
  .pill-btn {
    display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; background: var(--panel);
    border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow); cursor: pointer;
    font-family: "Space Grotesk", sans-serif; font-size: 13px; font-weight: 500; color: var(--ink);
  }
  .pill-btn:hover { background: #f6f6f4; }
  .pill-btn svg { width: 16px; height: 16px; }

  /* Grouped action toolbar — single pill with internal dividers */
  #action-group {
    display: flex; align-items: center;
    background: var(--panel); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow);
  }
  #action-group .pill-btn { border: none; box-shadow: none; border-radius: 0; height: 36px; }
  #action-group .pill-btn:hover { background: #f1f1ef; }
  #action-group > * + * { border-left: 1px solid var(--line); }
  #action-group > button:first-child { border-radius: 10px 0 0 10px; }
  #action-group > button:last-child  { border-radius: 0 10px 10px 0; }
  body.view-only #action-group > #export-wrap .pill-btn { border-radius: 10px 0 0 10px; }
  .gbtn { gap: 9px; }
  .gbtn .g { width: 18px; height: 18px; flex: none; display: block; }
  #account .avatar {
    width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line); box-shadow: var(--shadow);
    cursor: pointer; object-fit: cover; background: var(--accent-soft); color: var(--accent);
    font-family: "Space Grotesk", sans-serif; font-weight: 600; font-size: 15px;
  }
  #account .signed { display: flex; align-items: center; gap: 8px; position: relative; }
  #acct-menu {
    position: absolute; right: 0; top: 46px; width: 224px; background: var(--panel); border: 1px solid var(--line);
    border-radius: 12px; box-shadow: var(--shadow); padding: 8px; display: none;
  }
  #acct-menu.show { display: block; }
  #acct-menu .who { padding: 8px 10px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 6px; word-break: break-all; }
  #acct-menu .who b { display: block; color: var(--ink); font-size: 13px; font-weight: 600; margin-bottom: 2px; }
  #acct-menu button { width: 100%; text-align: left; border: none; background: transparent; padding: 8px 10px; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; color: var(--ink); }
  #acct-menu button:hover { background: #f1f1ef; }

  /* ---------- Diagrams overlay / panel ---------- */
  #overlay { position: fixed; inset: 0; background: rgba(20,20,22,.28); z-index: 40; display: none; align-items: flex-start; justify-content: center; }
  #overlay.show { display: flex; }
  #diagrams-panel {
    width: 440px; max-width: calc(100vw - 32px); margin-top: 84px; background: var(--panel);
    border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.25); overflow: hidden;
  }
  #diagrams-panel header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); font-family: "Space Grotesk", sans-serif; font-weight: 600; font-size: 15px; }
  #diagrams-panel header button { border: none; background: transparent; font-size: 15px; cursor: pointer; color: var(--muted); border-radius: 8px; width: 28px; height: 28px; }
  #diagrams-panel header button:hover { background: #f1f1ef; color: var(--ink); }
  #dp-new {
    margin: 14px 18px 6px; display: flex; align-items: center; gap: 8px; padding: 11px 14px; width: calc(100% - 36px);
    border: 1px dashed var(--line); border-radius: 11px; background: #fafafa; cursor: pointer;
    font-family: "Space Grotesk", sans-serif; font-size: 13.5px; font-weight: 500; color: var(--accent);
  }
  #dp-new:hover { background: var(--accent-soft); border-color: var(--accent); }
  #dp-list { max-height: 50vh; overflow-y: auto; padding: 6px 12px 16px; }
  .dp-row { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; cursor: pointer; }
  .dp-row:hover { background: #f6f6f4; }
  .dp-row.current { background: var(--accent-soft); }
  .dp-row .info { flex: 1; min-width: 0; }
  .dp-row .nm { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dp-row .meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
  .dp-row .acts { display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
  .dp-row:hover .acts { opacity: 1; }
  .dp-row .acts button { border: none; background: transparent; width: 28px; height: 28px; border-radius: 8px; cursor: pointer; color: var(--muted); display: grid; place-items: center; }
  .dp-row .acts button svg { width: 15px; height: 15px; }
  .dp-row .acts button:hover { background: #e9e9e6; color: var(--ink); }
  .dp-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 28px 12px; line-height: 1.6; }

  /* ---------- Import dialog ---------- */
  #import-overlay { position: fixed; inset: 0; background: rgba(20,20,22,.35); z-index: 50; display: none; align-items: center; justify-content: center; }
  #import-overlay.show { display: flex; }
  #import-panel { width: 460px; max-width: calc(100vw - 32px); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 24px 70px rgba(0,0,0,.28); overflow: hidden; }
  #import-panel header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); font-family: "Space Grotesk", sans-serif; font-weight: 600; font-size: 15px; }
  #import-panel header button { border: none; background: transparent; font-size: 15px; cursor: pointer; color: var(--muted); border-radius: 8px; width: 28px; height: 28px; }
  #import-panel header button:hover { background: #f1f1ef; color: var(--ink); }
  #import-panel p { margin: 16px 18px 10px; font-size: 13px; color: var(--muted); line-height: 1.5; }
  #import-panel p code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: #f1f1ef; padding: 1px 5px; border-radius: 5px; }
  #imp-text { display: block; width: calc(100% - 36px); margin: 0 18px; height: 110px; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: #fafafa; color: var(--ink); }
  #imp-text:focus { outline: none; border-color: var(--accent); background: #fff; }
  #imp-err { color: #d23b3b; font-size: 12.5px; min-height: 16px; margin: 8px 18px 0; }
  .imp-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px 18px; }
  .imp-file { font-size: 13px; color: var(--accent); cursor: pointer; font-weight: 500; }
  .imp-file:hover { text-decoration: underline; }
  .imp-primary { border: none; background: var(--accent); color: #fff; border-radius: 10px; padding: 10px 20px; font-family: "Space Grotesk", sans-serif; font-size: 13.5px; font-weight: 500; cursor: pointer; }
  .imp-primary:hover { background: #245fe0; }

  /* ---------- Share modal ---------- */
  #share-overlay { position: fixed; inset: 0; background: rgba(20,20,22,.35); z-index: 50; display: none; align-items: center; justify-content: center; }
  #share-overlay.show { display: flex; }
  #share-panel { width: 480px; max-width: calc(100vw - 32px); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 24px 70px rgba(0,0,0,.28); overflow: hidden; }
  #share-panel header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); font-family: "Space Grotesk", sans-serif; font-weight: 600; font-size: 15px; }
  #share-panel header button { border: none; background: transparent; font-size: 15px; cursor: pointer; color: var(--muted); border-radius: 8px; width: 28px; height: 28px; }
  #share-panel header button:hover { background: #f1f1ef; color: var(--ink); }
  #share-panel p { margin: 16px 18px 10px; font-size: 13px; color: var(--muted); line-height: 1.5; }
  #share-panel p code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: #f1f1ef; padding: 1px 5px; border-radius: 5px; }
  .share-row { display: flex; align-items: center; gap: 8px; padding: 4px 18px 8px; }
  #share-link { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: #fafafa; color: var(--ink); }
  #share-link:focus { outline: none; border-color: var(--accent); background: #fff; }
  #share-note { padding: 0 18px 18px; font-size: 12px; color: var(--accent); min-height: 16px; }
  .shared-tag { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; margin-left: 7px; vertical-align: middle; }
  .shared-tag.clickable { cursor: pointer; }
  .shared-tag.clickable:hover { background: #dbe6ff; }
  .viewonly-tag { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #8a6d00; background: #fff3cd; padding: 1px 6px; border-radius: 6px; margin-left: 7px; vertical-align: middle; }

  /* share modal: role picker */
  .share-perm { display: flex; align-items: center; gap: 8px; }
  .share-perm select { font-family: "Space Grotesk", sans-serif; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: #fff; cursor: pointer; color: var(--ink); }
  .share-fine { font-size: 11.5px; color: var(--muted); margin: 10px 18px 0; line-height: 1.5; }

  /* access panel (who has access) */
  #access-overlay { position: fixed; inset: 0; background: rgba(20,20,22,.35); z-index: 50; display: none; align-items: center; justify-content: center; }
  #access-overlay.show { display: flex; }
  #access-panel { width: 460px; max-width: calc(100vw - 32px); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 24px 70px rgba(0,0,0,.28); overflow: hidden; }
  #access-panel header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); font-family: "Space Grotesk", sans-serif; font-weight: 600; font-size: 15px; }
  #access-panel header button { border: none; background: transparent; font-size: 15px; cursor: pointer; color: var(--muted); border-radius: 8px; width: 28px; height: 28px; }
  #access-panel header button:hover { background: #f1f1ef; color: var(--ink); }
  #access-list { padding: 8px 12px; max-height: 50vh; overflow-y: auto; }
  .ac-row { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 10px; }
  .ac-row:hover { background: #f6f6f4; }
  .ac-who { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ac-sub { font-size: 11.5px; font-weight: 400; color: var(--muted); margin-top: 1px; }
  .ac-role-fixed { font-size: 12px; color: var(--muted); font-weight: 500; }
  .ac-role { font-family: "Space Grotesk", sans-serif; font-size: 12.5px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; background: #fff; cursor: pointer; color: var(--ink); }
  .ac-remove { border: none; background: transparent; width: 28px; height: 28px; border-radius: 8px; cursor: pointer; color: var(--muted); display: grid; place-items: center; flex: none; }
  .ac-remove svg { width: 15px; height: 15px; }
  .ac-remove:hover { background: #e9e9e6; color: #d23b3b; }
  .ac-empty { padding: 14px 10px; font-size: 13px; color: var(--muted); }
  #access-note { padding: 0 18px 16px; font-size: 12px; color: var(--accent); min-height: 0; }

  /* ---------- Drill-down ---------- */
  #scene { transition: opacity 0.11s ease; }

  /* Magnifying glass overlay — hidden until node is drill-hovered */
  .node .drill-overlay { opacity: 0; transition: opacity .15s; pointer-events: none; }
  .node.drill-hovered .drill-overlay { opacity: 1; }
  /* Dim labels when the drill hint is showing */
  .node.drill-hovered .node-label,
  .node.drill-hovered .node-type,
  .node.drill-hovered .node-sub { opacity: 0.2; transition: opacity .15s; }
  /* The clickable icon button inside the overlay */
  .drill-btn { pointer-events: auto; cursor: pointer; }
  .drill-btn-bg { transition: fill .12s; }
  .drill-btn:hover .drill-btn-bg { fill: var(--accent); }
  /* Hide drill hint during connection dragging */
  body.connecting .node .drill-overlay { opacity: 0 !important; pointer-events: none !important; }
  body.connecting .node .node-label,
  body.connecting .node .node-type,
  body.connecting .node .node-sub { opacity: 1 !important; }

  /* Back button — floats below the topbar (centred, same axis) when drilled in */
  #drill-back { position: fixed; left: 50%; top: 72px; transform: translateX(-50%); z-index: 10; display: none; }
  #drill-back.show { display: block; }

  /* view-only mode (viewers): no editing affordances */
  body.view-only #toolbar { display: none; }
  body.view-only .anchor, body.view-only .anchor-hit { display: none !important; }
  body.view-only #tidy-btn { display: none; }

  /* export menu */
  #export-wrap { position: relative; }
  #export-menu { position: absolute; top: calc(100% + 6px); right: 0; min-width: 152px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow); padding: 5px; display: none; z-index: 20; }
  #export-menu.show { display: block; }
  #export-menu button { display: block; width: 100%; text-align: left; border: none; background: transparent; padding: 8px 10px; border-radius: 8px; font-family: "Space Grotesk", sans-serif; font-size: 13px; color: var(--ink); cursor: pointer; }
  #export-menu button:hover { background: #f3f3f1; }

  /* ---------- Live presence (cursors + avatars) ---------- */
  #cursors { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 35; }
  .cursor { position: absolute; top: 0; left: 0; will-change: transform; }
  .cursor svg { display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
  .cursor .lbl { position: absolute; left: 14px; top: 14px; white-space: nowrap; color: #fff; font-family: "Space Grotesk", sans-serif; font-size: 11px; font-weight: 500; padding: 2px 7px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
  #peers { display: flex; align-items: center; }
  #peers .peer { position: relative; margin-left: -8px; }
  #peers .peer:first-child { margin-left: 0; }
  #peers .peer-av { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 2px currentColor; overflow: hidden; display: grid; place-items: center; font-family: "Space Grotesk", sans-serif; font-size: 12px; font-weight: 600; background: #ddd; transition: transform .12s; }
  #peers .peer:hover { z-index: 2; }
  #peers .peer:hover .peer-av { transform: translateY(2px) scale(1.08); }
  #peers .peer-av img { width: 100%; height: 100%; object-fit: cover; }
  #peers .peer-name { position: absolute; top: 38px; right: 0; white-space: nowrap; background: #1f2024; color: #fff; font-family: "Space Grotesk", sans-serif; font-size: 11.5px; font-weight: 500; padding: 3px 8px; border-radius: 7px; box-shadow: 0 2px 8px rgba(0,0,0,.2); opacity: 0; transform: translateY(-3px); pointer-events: none; transition: opacity .12s, transform .12s; }
  #peers .peer:hover .peer-name { opacity: 1; transform: translateY(0); }

  /* ---------- Passphrase modal ---------- */
  #pp-overlay { position: fixed; inset: 0; background: rgba(20,20,22,.45); z-index: 60; display: none; align-items: center; justify-content: center; }
  #pp-overlay.show { display: flex; }
  #pp-panel { width: 384px; max-width: calc(100vw - 32px); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 24px 70px rgba(0,0,0,.3); padding: 26px 26px 20px; text-align: center; }
  #pp-panel .pp-lock { width: 44px; height: 44px; margin: 0 auto 14px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
  #pp-panel .pp-lock svg { width: 22px; height: 22px; }
  #pp-panel h2 { font-family: "Space Grotesk", sans-serif; font-size: 18px; font-weight: 600; margin: 0 0 8px; letter-spacing: -.01em; }
  #pp-panel p { font-size: 13px; line-height: 1.55; color: var(--muted); margin: 0 0 18px; }
  #pp-panel p b { color: var(--ink); font-weight: 600; }
  #pp-panel input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; font: inherit; font-size: 14px; background: #fafafa; margin-bottom: 10px; }
  #pp-panel input:focus { outline: none; border-color: var(--accent); background: #fff; }
  #pp-err { color: #d23b3b; font-size: 12.5px; min-height: 16px; margin-bottom: 8px; text-align: left; }
  .pp-primary { width: 100%; border: none; background: var(--accent); color: #fff; border-radius: 10px; padding: 12px; font-family: "Space Grotesk", sans-serif; font-size: 14px; font-weight: 500; cursor: pointer; }
  .pp-primary:hover { background: #245fe0; }
  .pp-primary:disabled { opacity: .6; cursor: default; }
  .pp-skip { width: 100%; border: none; background: transparent; color: var(--muted); padding: 10px; font: inherit; font-size: 13px; cursor: pointer; margin-top: 2px; }
  .pp-skip:hover { color: var(--ink); }

  /* recovery-key modals (mirror the passphrase modal) */
  #rk-overlay, #rk-in-overlay { position: fixed; inset: 0; background: rgba(20,20,22,.45); z-index: 70; display: none; align-items: center; justify-content: center; }
  #rk-overlay.show, #rk-in-overlay.show { display: flex; }
  #rk-panel, #rk-in-panel { width: 420px; max-width: calc(100vw - 32px); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 24px 70px rgba(0,0,0,.3); padding: 26px 26px 20px; text-align: center; }
  #rk-panel h2, #rk-in-panel h2 { font-family: "Space Grotesk", sans-serif; font-weight: 600; font-size: 19px; margin: 0 0 10px; }
  #rk-panel p, #rk-in-panel p { font-size: 13.5px; color: #4a4a50; line-height: 1.55; margin: 0 0 16px; }
  #rk-value { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; background: #f1f1ef; border-radius: 10px; padding: 12px; word-break: break-all; white-space: pre-wrap; margin: 0 0 16px; text-align: left; }
  #rk-in-value { width: 100%; box-sizing: border-box; height: 84px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: none; margin: 0 0 10px; }
  #rk-in-value:focus { outline: none; border-color: var(--accent); }
  #rk-in-err { color: #d23b3b; font-size: 12.5px; min-height: 16px; margin-bottom: 6px; }
