  :root {
    --bg: transparent;
    --ink: #0f172a;
    --accent: #0ea5e9;
    --accent-2: #22c55e;
    --muted: #94a3b8;
    --shadow: 0 6px 24px rgba(2,8,23,.08), 0 2px 8px rgba(2,8,23,.06);
    --radius: 16px;
  }
  html, body {
    height: 100%;
    margin: 0; padding: 0;
    background: transparent;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
    overflow: auto;
  }

  #map {
    display: flex;
    flex-direction: column;
  position: absolute;
  inset: 0;
  height: 100vh;
  background: var(--bg);
}

#viewport {
  flex: 1; /* take remaining space below toolbar */
   position: relative;
   overflow: hidden; /* still prevent internal scroll */
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  transform-origin: 0 0;
}

#paper {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

#stage {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

#wires {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

  .toolbar {
    position: fixed; top: 16px; left: 16px; right: 16px; z-index:1000;
    background: white; border-radius: 14px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    flex-wrap: wrap;
  }
  .toolbar button, .toolbar input[type="file"], .toolbar label {
    border: 1px solid #e2e8f0; background: white; border-radius: 12px;
    padding: 8px 12px; font-weight: 600; cursor: pointer;
  }
  .toolbar button:hover {
    background: var(--accent-2); color: white;
  }


/* Toggle button styling */
#toggleToolbarBtn {
  position: fixed;
  top: 30px; /* Adjust to appear just under toolbar */
  left: 12px;
  z-index: 1010;
  padding: 6px 12px;
  background: #466370;
  font-weight: 600;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: top 0.3s ease;
}

/* When toolbar is hidden, move toggle button to top */
.toolbar-hidden + #toggleToolbarBtn {
  top: 12px; /* Near top of the window */
}
  .userInfoInput {
    position: fixed;
    inset: auto 16px 16px 16px; /* keep bottom/left/right spacing */
    max-height: 80vh; /* don't block the whole screen */
    overflow-y: auto; /* scroll if content is tall */
    width: auto;
      z-index: 1000;
      background: white;
      border-radius: 14px;
      box-shadow: var(--shadow);
      display: flex;
      gap: 8px;
      align-items: flex-start;
      padding: 10px 12px;
      flex-direction: column;

  }
  .userInfoInput:active {
    cursor: grabbing;
  }
  .userInfoInput label {
    font-weight: 600;
    color: var(--ink);
  }
  .userInfoInput textarea {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px;
    font-family: inherit;
    resize: vertical;
    min-height: 36px;
    width: 80%;
  }
  #summaryOutput {
    font-family: inherit;
    margin-top: 12px; color: #6b84de;
    background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px;
    padding: 12px;
    font-weight: 500;
    max-width: 560px;
  }
  #viewport {
    cursor: grab;
    background:
      radial-gradient(circle at 1px 1px, #e5e7eb 1px, transparent 0) 0 0 / 28px 28px,
      radial-gradient(circle at 1px 1px, #f1f5f9 1px, transparent 0) 14px 14px / 28px 28px;
  }
  #viewport.grabbing {
    cursor: grabbing;
  }
  .node {
    position: absolute;
    min-width: 140px;
    max-width: 260px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px 12px 10px 14px;
    user-select: none;
    touch-action: none;
    transition: box-shadow 0.15s, transform 0.05s;
  }
  .node.selected {
    outline: 2px solid var(--accent);
    outline-offset: 0;
  }
  .node .label {
    font-weight: 700;
    font-size: 16px;
    color: var(--ink);
    padding-right: 36px;
    outline: none;
    border: none;
  }
  .node .sub {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
  }
  .node .actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
  }
  .chip {
    border: 1px solid #e2e8f0;
    background: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 12px;
    cursor: pointer;
  }
  .chip.danger {
    border-color: #fecaca;
    background: #fff1f2;
    color: #b91c1c;
  }
  .wire {
    fill: none;
    stroke: #b2a6ff;
    stroke-width: 2.5px;
    filter: drop-shadow(0 2px 0 rgba(2,8,23,.04));
  }
  .wire.root {
    stroke: url(#wireGradient);
  }
  .wire.great-grandchild {
    stroke: #ff7e55 !important;
    stroke-width: 2px;
  }
  .wire.active {
    stroke: var(--accent);
    stroke-width: 3px;
  }
  .hint{
    position: fixed; left: 16px; bottom: 14px; font-size: 13px; color:#64748b; background:#ffffffcc;
    padding: 6px 10px; border-radius: 10px; border:1px solid #e2e8f0; box-shadow: var(--shadow)
  }

  input[type="file"] {
    display: none;
  }

  .custom-file-upload {
    border: 1px solid #ccc;
    display: inline-block;
    padding: 6px 12px;
    cursor: pointer;
  }


  @media (max-width: 900px) {
    .userInfoInput {
      max-width: 90vw;
      left: 5vw !important;
      top: 70px !important;
      padding: 12px;
      font-size: 14px;
    }
    .userInfoInput textarea {
      font-size: 14px;
    }
    .toolbar {
      flex-wrap: wrap;
    }
    .toolbar button, .toolbar label {
      flex: 1 1 100px;
      font-size: 14px;
      padding: 6px 8px;
    }
    #summaryOutput {
      max-width: 90vw;
      font-size: 14px;
    }
    .node {
      min-width: 100px;
      max-width: 200px;
      font-size: 14px;
    }
    .node .label {
      font-size: 14px;
    }
  }


  @media (max-width: 600px) {
  .toolbar {
    position: sticky; /* so it scrolls naturally but stays on top */
    top: 0;
    left: 0;
    right: 0;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 4px;
    padding: 6px 8px;
  }

  .toolbar button, .toolbar label, .toolbar input[type="range"] {
    flex: 1 1 45%; /* let buttons shrink but remain usable */
    min-width: 120px;
    font-size: 13px;
    white-space: normal; /* allow text wrap */
    padding: 4px 6px;
  }

  .toolbar small {
    flex-basis: 100%;
    font-size: 11px;
    margin-top: 4px;
  }
}
