:root{
      --bg:#08111a;
      --bg2:#0c1826;
      --panel:rgba(8,17,27,.88);
      --panel2:rgba(11,23,36,.92);
      --line:rgba(95,168,214,.72);
      --lineActive:rgba(130,236,255,.98);
      --text:#edf5ff;
      --muted:#8ea8be;
      --accent:#7eecff;
      --accent2:#19c8f2;
      --danger:#ff7f8f;
      --grid:rgba(112,166,205,.09);
      --shadow:0 16px 36px rgba(0,0,0,.30);
      --radius:18px;
      --node-w:170px;
      --node-h:56px;
      --safe-top:env(safe-area-inset-top);
      --safe-bottom:env(safe-area-inset-bottom);
      --safe-left:env(safe-area-inset-left);
      --safe-right:env(safe-area-inset-right);
    }
    *{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
    html,body{
      margin:0;height:100%;overflow:hidden;
      background:var(--bg);
      color:var(--text);
      font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
    }
    body{
      background:
        radial-gradient(circle at top, rgba(25,200,242,.10), transparent 28%),
        linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
    }
    .app{position:fixed;inset:0;display:flex;flex-direction:column;overflow:hidden}
    .topbar{
      position:relative;z-index:40;
      padding:calc(var(--safe-top) + 10px) calc(var(--safe-right) + 14px) 10px calc(var(--safe-left) + 14px);
      background:linear-gradient(180deg, rgba(6,13,22,.97), rgba(6,13,22,.76));
      border-bottom:1px solid rgba(255,255,255,.05);
      backdrop-filter:blur(16px);
    }
    .top-row{display:flex;gap:10px;align-items:flex-start}
    .title-wrap{min-width:0;flex:1}
    .title{font-size:16px;font-weight:800;letter-spacing:.1px}
    .meta{margin-top:3px;font-size:12px;color:var(--muted)}
    .version{
      flex:none;
      padding:9px 12px;
      border-radius:999px;
      border:1px solid rgba(126,236,255,.14);
      background:rgba(18,35,52,.86);
      color:#b7fbff;
      font-size:12px;font-weight:800;
      white-space:nowrap;
      box-shadow:0 10px 26px rgba(0,0,0,.18);
    }
    .status-row{
      display:flex;gap:8px;margin-top:10px;overflow:auto hidden;scrollbar-width:none;
    }
    .status-row::-webkit-scrollbar{display:none}
    .tiny{
      flex:none;
      padding:7px 10px;
      border-radius:999px;
      border:1px solid rgba(255,255,255,.06);
      background:rgba(255,255,255,.03);
      color:var(--muted);
      font-size:12px;font-weight:700;
      white-space:nowrap;
    }

    .workspace{position:relative;flex:1;min-height:0;overflow:hidden}
    .viewport{
      position:absolute;inset:0;overflow:hidden;
      user-select:none;
      background:
        linear-gradient(var(--grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid) 1px, transparent 1px);
      background-size:28px 28px, 28px 28px;
      background-position:center;
      touch-action:none;
    }
    .world{
      position:absolute;left:0;top:0;width:4200px;height:4200px;
      transform-origin:0 0;
      will-change:transform;
    }
    canvas.edges{position:absolute;inset:0;width:4200px;height:4200px;pointer-events:none}
    .nodes{position:absolute;inset:0}

    .node{
      position:absolute;
      width:var(--node-w);
      min-height:var(--node-h);
      padding:12px 14px;
      border-radius:18px;
      display:flex;align-items:center;justify-content:center;
      text-align:center;
      color:var(--text);
      font-size:14px;font-weight:800;line-height:1.22;
      border:1px solid rgba(255,255,255,.09);
      background:linear-gradient(180deg, rgba(16,33,51,.98), rgba(9,20,32,.98));
      box-shadow:inset 0 0 0 1px rgba(126,236,255,.03), 0 14px 28px rgba(0,0,0,.22);
      transition:border-color .12s ease, box-shadow .12s ease, transform .08s ease;
      cursor:grab;
      touch-action:none;
    }
    .node.root{
      color:#06222d;
      border-color:rgba(255,255,255,.22);
      background:linear-gradient(180deg, #3ae1ff 0%, #16bbe5 100%);
      box-shadow:0 16px 34px rgba(22,187,229,.24);
    }
    .node.selected{
      border-color:rgba(126,236,255,.88);
      box-shadow:0 0 0 2px rgba(126,236,255,.20), 0 18px 34px rgba(0,0,0,.26);
    }
    .node.dragging{
      cursor:grabbing;
      transform:scale(1.015);
      box-shadow:0 0 0 2px rgba(126,236,255,.25), 0 22px 40px rgba(0,0,0,.30);
    }
    .node.drop-target{
      border-color:rgba(126,236,255,.98);
      box-shadow:0 0 0 3px rgba(126,236,255,.18), inset 0 0 0 1px rgba(126,236,255,.14), 0 22px 40px rgba(0,0,0,.30);
    }
    .node-text{
      display:-webkit-box;
      -webkit-box-orient:vertical;
      -webkit-line-clamp:2;
      overflow:hidden;
      word-break:break-word;
    }

    .zoom-box{
      position:absolute;right:12px;top:12px;z-index:31;
      display:flex;flex-direction:column;gap:8px;align-items:flex-end;
    }
    .zoom-row{display:flex;gap:8px;}
    .zoom-btn{
      width:52px;height:44px;border-radius:16px;
      border:1px solid rgba(255,255,255,.08);
      background:rgba(8,17,27,.84);
      color:var(--text);
      font-size:18px;font-weight:900;
      box-shadow:var(--shadow);
      backdrop-filter:blur(12px);
    }
    .fit-btn{width:52px;align-self:flex-end;}

    .toolbar{
      position:absolute;left:10px;right:10px;bottom:calc(var(--safe-bottom) + 10px);
      z-index:45;
      padding:10px;
      border-radius:24px;
      border:1px solid rgba(255,255,255,.07);
      background:rgba(7,14,23,.78);
      box-shadow:var(--shadow);
      backdrop-filter:blur(18px);
      display:flex;flex-direction:column;gap:8px;
    }
    .toolbar-row{display:flex;gap:8px;align-items:center}
    .actions-row .tool{min-width:0}
    .bottom-row{align-items:center}
    .tool{
      flex:1 1 0;
      min-height:46px;
      padding:0 12px;
      border-radius:16px;
      border:1px solid rgba(255,255,255,.08);
      background:linear-gradient(180deg, rgba(17,31,47,.98), rgba(9,18,30,.98));
      color:var(--text);
      font-size:15px;font-weight:800;
      letter-spacing:.1px;
      box-shadow:0 10px 22px rgba(0,0,0,.18);
      white-space:nowrap;
      overflow:hidden;
      text-overflow:ellipsis;
    }
    .tool.primary{
      background:linear-gradient(180deg, #43e6ff, #17bde7);
      color:#06232d;
      border-color:rgba(255,255,255,.18);
      box-shadow:0 12px 28px rgba(23,189,231,.24);
    }
    .tool.warn{
      color:#ffd6dc;
      border-color:rgba(255,127,143,.28);
      background:linear-gradient(180deg, rgba(35,18,25,.98), rgba(23,11,16,.98));
    }
    .tool.ghost{
      flex:0 0 auto;
      min-width:72px;
      padding:0 14px;
      background:rgba(255,255,255,.03);
      color:var(--muted);
    }
    .util-btn{min-width:78px}
    .segment{
      flex:1 1 auto;
      display:flex;
      padding:4px;
      border-radius:18px;
      border:1px solid rgba(255,255,255,.07);
      background:rgba(255,255,255,.03);
      min-width:0;
      box-shadow:inset 0 1px 0 rgba(255,255,255,.02);
    }
    .seg{
      flex:1 1 0;
      min-height:40px;
      border:none;
      border-radius:14px;
      background:transparent;
      color:var(--muted);
      font-size:13px;
      font-weight:800;
      white-space:nowrap;
      padding:0 10px;
    }
    .seg.active{
      color:#06232d;
      background:linear-gradient(180deg, #43e6ff, #17bde7);
      box-shadow:0 10px 18px rgba(23,189,231,.22);
    }
    .layout-segment .seg{font-size:12px;padding:0 8px}

    .log-panel{
      position:absolute;left:10px;right:10px;bottom:calc(var(--safe-bottom) + 136px);
      z-index:44;
      border-radius:20px;
      border:1px solid rgba(255,255,255,.08);
      background:rgba(7,14,23,.90);
      box-shadow:var(--shadow);
      backdrop-filter:blur(16px);
      overflow:hidden;
      opacity:0;pointer-events:none;
      transform:translateY(16px);
      transition:opacity .16s ease, transform .16s ease;
      max-height:min(38vh,320px);
    }
    .log-panel.open{opacity:1;pointer-events:auto;transform:translateY(0)}
    .log-head{
      display:flex;align-items:center;justify-content:space-between;gap:8px;
      padding:12px 14px;border-bottom:1px solid rgba(255,255,255,.06);font-weight:800;
    }
    .log-actions{display:flex;gap:8px}
    .mini-btn{
      min-height:36px;padding:0 12px;border-radius:12px;
      border:1px solid rgba(255,255,255,.08);
      background:rgba(255,255,255,.03);
      color:var(--text);font-size:12px;font-weight:700;
    }
    .log-content{
      padding:8px 14px 14px;overflow:auto;max-height:220px;
      white-space:pre-wrap;word-break:break-word;
      font-family:ui-monospace,SFMono-Regular,Menlo,monospace;
      font-size:12px;line-height:1.45;color:#b9cde0;
    }
    .log-line{padding:5px 0;border-bottom:1px dashed rgba(255,255,255,.04)}

    .editor{
      position:fixed;inset:0;z-index:80;
      display:none;align-items:flex-end;
      background:rgba(0,0,0,.34);
      backdrop-filter:blur(3px);
    }
    .editor.open{display:flex}
    .editor-sheet{
      width:100%;
      padding:14px calc(var(--safe-right) + 14px) calc(var(--safe-bottom) + 14px) calc(var(--safe-left) + 14px);
      border-radius:24px 24px 0 0;
      background:linear-gradient(180deg, rgba(12,22,35,.98), rgba(8,16,26,.98));
      border-top:1px solid rgba(255,255,255,.07);
      box-shadow:0 -16px 40px rgba(0,0,0,.28);
    }
    .editor-top{
      display:flex;align-items:flex-start;justify-content:space-between;gap:10px;
    }
    .editor-label{font-size:12px;color:var(--muted);font-weight:700}
    .editor-title{font-size:18px;font-weight:800;margin-top:4px}
    .editor-node-chip{
      flex:none;
      max-width:42vw;
      padding:8px 12px;
      border-radius:999px;
      border:1px solid rgba(126,236,255,.16);
      background:rgba(18,35,52,.86);
      color:#b7fbff;
      font-size:12px;
      font-weight:800;
      white-space:nowrap;
      overflow:hidden;
      text-overflow:ellipsis;
    }
    .editor-area{
      width:100%;min-height:132px;resize:none;
      margin-top:14px;padding:16px 16px 18px;
      border-radius:18px;
      border:1px solid rgba(126,236,255,.10);
      background:linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.025));
      color:var(--text);
      font:700 17px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
      outline:none;
      box-shadow:inset 0 0 0 1px rgba(126,236,255,.02);
    }
    .editor-foot{
      margin-top:14px;
      display:flex;justify-content:space-between;align-items:center;gap:10px;
    }
    .count{font-size:12px;color:var(--muted)}
    .editor-actions{display:flex;gap:8px}
    .sheet-btn{
      min-height:44px;padding:0 16px;border-radius:14px;
      border:1px solid rgba(255,255,255,.08);
      background:rgba(255,255,255,.03);
      color:var(--text);font-size:14px;font-weight:800;
    }
    .sheet-btn.primary{
      background:linear-gradient(180deg, #43e6ff, #17bde7);
      color:#06232d;border-color:rgba(255,255,255,.16);
      box-shadow:0 12px 26px rgba(23,189,231,.22);
    }

    @media (min-width: 860px){
      .topbar{padding:14px 16px 12px}
      .toolbar{left:16px;right:auto;width:620px}
      .log-panel{left:16px;right:auto;width:560px}
      .editor{align-items:center;justify-content:center}
      .editor-sheet{
        width:min(540px,calc(100vw - 32px));
        border-radius:24px;
        padding:16px;
        border:1px solid rgba(255,255,255,.08);
      }
    }
