    :root {
      --bg: #0e0f13;
      --panel: #16181f;
      --panel-2: #1d2029;
      --border: #2a2e3a;
      --text: #e7e9ee;
      --muted: #8b90a0;
      --accent: #6c8cff;
      --ok: #3ecf8e;
      --err: #ff6b6b;
      --grid: #181b22;
    }
    * { box-sizing: border-box; }
    html, body { height: 100%; margin: 0; }
    body {
      background: var(--bg);
      color: var(--text);
      font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      height: 100dvh;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      user-select: none;
    }

    header {
      padding: 10px 16px;
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      gap: 12px;
      z-index: 5;
      background: var(--panel);
    }
    header h1 { font-size: 14px; margin: 0; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
    nav.crumbs { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; overflow: hidden; font-size: 13px; }
    nav.crumbs .crumb {
      color: var(--muted); cursor: pointer; padding: 3px 8px; border-radius: 7px; white-space: nowrap;
      max-width: 220px; overflow: hidden; text-overflow: ellipsis;
    }
    nav.crumbs .crumb:hover { background: var(--panel-2); color: var(--text); }
    nav.crumbs .crumb.current { color: var(--text); font-weight: 600; cursor: default; }
    nav.crumbs .sep { color: var(--border); flex: none; }

    .tools { display: flex; gap: 6px; flex: none; }
    button {
      background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 9px;
      padding: 0 12px; height: 32px; font: inherit; cursor: pointer; white-space: nowrap;
    }
    button:hover { border-color: var(--accent); }
    button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
    #cloudBtn.ok { border-color: var(--ok); color: var(--ok); }
    #cloudBtn.sync { border-color: var(--accent); color: var(--accent); }
    #cloudBtn.err { border-color: var(--err); color: var(--err); }
    #cloudBtn.off { color: var(--muted); }

    #viewport {
      flex: 1; position: relative; overflow: hidden; min-height: 0;
      background:
        linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 28px 28px,
        linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 28px 28px,
        radial-gradient(circle at 50% 0%, #15171f 0%, var(--bg) 70%);
      cursor: grab;
    }
    #viewport.panning { cursor: grabbing; }
    #viewport.drawmode { cursor: crosshair; }

    #world { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
    #edges { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
    #edges line { stroke: #3a4150; stroke-width: 2; }
    #edges line.temp { stroke: var(--accent); stroke-dasharray: 5 4; }
    #edges .hit { stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }

    .card {
      position: absolute; width: 180px; min-height: 64px;
      background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--c, var(--accent));
      border-radius: 12px; padding: 9px 11px 10px; box-shadow: 0 6px 20px rgba(0,0,0,.35);
      cursor: grab; transition: border-color .12s, box-shadow .12s;
    }
    .card:hover { box-shadow: 0 8px 26px rgba(0,0,0,.5); }
    .card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(108,140,255,.35), 0 8px 26px rgba(0,0,0,.5); }
    .card .title {
      font-weight: 600; font-size: 13px; outline: none; cursor: text;
      word-break: break-word; min-height: 18px;
    }
    .card .note {
      font-size: 12px; color: var(--muted); margin-top: 4px; outline: none; cursor: text;
      word-break: break-word; white-space: pre-wrap; min-height: 0;
    }
    .card .title:empty::before { content: "Без названия"; color: var(--muted); }
    .card .note:empty::before { content: "+ заметка"; color: #555a6a; }
    .card .row {
      display: flex; align-items: center; gap: 6px; margin-top: 8px; opacity: 0; transition: opacity .12s;
    }
    .card:hover .row, .card.selected .row { opacity: 1; }
    .card .row .spacer { flex: 1; }
    .card .ico {
      width: 24px; height: 22px; display: inline-flex; align-items: center; justify-content: center;
      border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); cursor: pointer; font-size: 12px; color: var(--muted);
    }
    .card .ico:hover { color: var(--text); border-color: var(--accent); }
    .card .dive {
      display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px;
      background: var(--panel-2); border: 1px solid var(--border); cursor: pointer; font-size: 12px; color: var(--accent); font-weight: 600;
    }
    .card .dive:hover { border-color: var(--accent); background: rgba(108,140,255,.12); }
    .card .swatches { display: none; gap: 4px; }
    .card.editcolor .swatches { display: flex; }
    .card.editcolor .row > *:not(.swatches):not(.spacer) { display: none; }
    .swatches i { width: 16px; height: 16px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
    .swatches i:hover { border-color: #fff; }

    /* frames (grouping rectangles) — render under cards/edges; body is click-through */
    .frame {
      position: absolute; min-width: 60px; min-height: 40px;
      border: 1.5px solid var(--fc, var(--accent)); border-radius: 12px;
      background: color-mix(in srgb, var(--fc, var(--accent)) 7%, transparent);
      pointer-events: none;
    }
    .frame .fhead {
      position: absolute; top: 0; left: 0; right: 0; height: 26px;
      display: flex; align-items: center; gap: 6px; padding: 0 8px;
      background: color-mix(in srgb, var(--fc, var(--accent)) 18%, var(--panel));
      border-bottom: 1px solid color-mix(in srgb, var(--fc, var(--accent)) 40%, transparent);
      border-radius: 11px 11px 0 0; pointer-events: auto; cursor: grab;
    }
    .frame .ftitle {
      font-size: 12px; font-weight: 600; color: var(--text); outline: none; cursor: text;
      max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .frame .ftitle:empty::before { content: "Рамка"; color: var(--muted); }
    .frame .fspacer { flex: 1; }
    .frame .fico {
      width: 20px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
      border-radius: 5px; cursor: pointer; font-size: 12px; color: var(--muted); opacity: .65;
    }
    .frame .fico:hover { opacity: 1; color: var(--text); background: rgba(255,255,255,.08); }
    .frame .fswatches { display: none; gap: 4px; }
    .frame.editcolor .fswatches { display: flex; }
    .frame.editcolor .fhead > *:not(.fswatches):not(.fspacer) { display: none; }
    .frame .fswatches i { width: 14px; height: 14px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
    .frame .fswatches i:hover { border-color: #fff; }
    .frame .fhandle {
      position: absolute; right: -6px; bottom: -6px; width: 13px; height: 13px; border-radius: 3px;
      background: var(--fc, var(--accent)); border: 2px solid var(--bg);
      pointer-events: auto; cursor: nwse-resize; opacity: .55;
    }
    .frame .fhandle:hover { opacity: 1; }

    /* connection handle */
    .card .handle {
      position: absolute; right: -7px; top: 50%; transform: translateY(-50%);
      width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg);
      cursor: crosshair; opacity: 0; transition: opacity .12s;
    }
    .card:hover .handle { opacity: 1; }

    .hint {
      position: absolute; left: 14px; bottom: 12px; z-index: 2; color: var(--muted); font-size: 12px;
      background: rgba(22,24,31,.82); border: 1px solid var(--border); border-radius: 10px; padding: 7px 11px;
      backdrop-filter: blur(6px); max-width: 60%;
    }
    .hint b { color: var(--text); font-weight: 600; }
    .empty {
      position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column;
      gap: 6px; color: var(--muted); pointer-events: none; text-align: center; padding: 20px;
    }
    .empty .big { font-size: 16px; color: var(--text); }
    .zoomwrap { position: absolute; right: 14px; bottom: 12px; z-index: 2; display: flex; gap: 6px; align-items: center; }
    .zoomwrap span { color: var(--muted); font-size: 12px; min-width: 42px; text-align: center; }

    /* agent modal */
    .modal-back {
      position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
      background: rgba(8,9,12,.6); backdrop-filter: blur(3px);
    }
    .modal-back[hidden] { display: none; }
    .modal {
      width: min(540px, 92vw); background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
      box-shadow: 0 20px 60px rgba(0,0,0,.6); padding: 16px; display: flex; flex-direction: column; gap: 10px;
    }
    .modal-h { font-weight: 600; font-size: 15px; }
    .modal-sub { color: var(--muted); font-size: 12px; margin-top: -4px; word-break: break-word; }
    .modal textarea {
      width: 100%; min-height: 92px; resize: vertical; background: var(--panel-2); color: var(--text);
      border: 1px solid var(--border); border-radius: 10px; padding: 10px; font: inherit; outline: none;
    }
    .modal textarea:focus { border-color: var(--accent); }
    .modal-row { display: flex; align-items: center; gap: 8px; }
    .modal-row .spacer { flex: 1; }
    .modal-status { font-size: 12px; color: var(--muted); }
    .modal-status.err { color: var(--err); }
    .modal-status.busy { color: var(--accent); }

    #minimap {
      position: absolute; top: 12px; right: 14px; z-index: 3; width: 200px; height: 140px;
      background: rgba(22,24,31,.82); border: 1px solid var(--border); border-radius: 10px;
      backdrop-filter: blur(6px); overflow: hidden; cursor: pointer; display: none;
    }
    #mmSvg { display: block; }
    #mmSvg .mm-frame { fill: none; stroke-width: 1; }
    #mmSvg .mm-view { fill: rgba(108,140,255,.14); stroke: var(--accent); stroke-width: 1.5; }
    input[type=file] { display: none; }
    .marquee {
      position: absolute; z-index: 4; display: none; pointer-events: none;
      border: 1px solid var(--accent); background: rgba(108,140,255,.12); border-radius: 3px;
    }
