* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: #0a0a0a;
    color: #e0e0e0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* --- Toolbar --- */

#toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: rgba(15, 15, 15, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #222;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
    z-index: 1000;
    user-select: none;
}

#toolbar .back {
    color: #666;
    text-decoration: none;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s;
}

#toolbar .back:hover { color: #ccc; }

#toolbar .title {
    font-size: 14px;
    font-weight: 500;
    color: #999;
    flex: 1;
}

#toolbar .tools {
    display: flex;
    gap: 8px;
}

#toolbar button {
    background: #1a1a1a;
    border: 1px solid #333;
    color: #aaa;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

#toolbar button:hover {
    background: #252525;
    border-color: #555;
    color: #ddd;
}

.zoom-display {
    font-size: 11px;
    color: #555;
    min-width: 40px;
    text-align: right;
}

/* --- Canvas --- */

#canvas-viewport {
    position: fixed;
    top: 48px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    cursor: grab;
}

#canvas-viewport.panning { cursor: grabbing; }
#canvas-viewport.placing { cursor: crosshair; }

#canvas-world {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    width: 1px;
    height: 1px;
}

/* --- SVG overlay for arrows --- */

#svg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    overflow: visible;
    transform-origin: 0 0;
    pointer-events: none;
    z-index: 50;
}

#svg-layer .connection {
    pointer-events: stroke;
    cursor: pointer;
}

#svg-layer .connection path {
    fill: none;
    stroke: #555;
    stroke-width: 2;
    transition: stroke 0.15s;
}

#svg-layer .connection:hover path {
    stroke: #888;
}

#svg-layer .connection.selected path {
    stroke: #4a9eff;
}

#svg-layer .connection-label {
    fill: #888;
    font-size: 11px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    pointer-events: none;
    user-select: none;
}

/* --- Nodes --- */

.node {
    position: absolute;
    cursor: move;
    user-select: none;
    transition: box-shadow 0.15s;
    z-index: 100;
}

.node:hover { z-index: 200; }
.node.dragging {
    z-index: 300;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.node.selected {
    outline: 2px solid #4a9eff;
    outline-offset: 2px;
}

/* Process node */
.node-process {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 6px;
    min-width: 120px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.node-process:hover {
    border-color: #555;
}

/* Question node */
.node-question {
    min-width: 140px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.node-question .diamond-bg {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 70.7%;
    height: 70.7%;
    transform: translate(-50%, -50%) rotate(45deg);
    background: #1a2030;
    border: 1px solid #3a4a6a;
    border-radius: 4px;
    z-index: -1;
    transition: border-color 0.15s;
}

.node-question:hover .diamond-bg {
    border-color: #5a6a8a;
}

/* Label node (plain text, no box, no ports) */
.node-label {
    background: none;
    border: none;
}

.node-label .node-text {
    font-size: 16px;
    font-weight: 500;
    color: #999;
    padding: 4px 8px;
}

.node-label .node-text:focus {
    color: #ddd;
}

/* Node text */
.node-text {
    font-size: 13px;
    line-height: 1.4;
    color: #ccc;
    outline: none;
    word-wrap: break-word;
    white-space: pre-wrap;
    text-align: center;
    padding: 10px 14px;
    max-width: 100%;
    z-index: 1;
}

.node-text:empty::before {
    content: 'Type...';
    color: #444;
}

.node-text:focus {
    color: #eee;
}

/* --- Connection ports --- */

.port {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #333;
    border: 2px solid #555;
    cursor: crosshair;
    z-index: 400;
    transition: background 0.15s, transform 0.15s;
    pointer-events: auto;
}

.port:hover {
    background: #4a9eff;
    border-color: #4a9eff;
    transform: scale(1.3);
}

.port.port-active {
    background: #4a9eff;
    border-color: #4a9eff;
}

/* Port positions */
.port-in {
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
}

.port-in:hover {
    transform: translateX(-50%) scale(1.3);
}

.port-out {
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
}

.port-out:hover {
    transform: translateX(-50%) scale(1.3);
}

.port-no {
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
}

.port-no:hover {
    transform: translateY(-50%) scale(1.3);
}

/* Port labels */
.port-label {
    position: absolute;
    font-size: 9px;
    color: #666;
    pointer-events: none;
    white-space: nowrap;
}

.port-out .port-label,
.port-out + .port-label {
    /* positioned via JS */
}

/* --- Selection rect --- */

#selection-rect {
    position: absolute;
    border: 1px dashed #4a9eff;
    background: rgba(74, 158, 255, 0.08);
    pointer-events: none;
    display: none;
    z-index: 1000;
}

/* --- Context menu --- */

#context-menu {
    display: none;
    position: fixed;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 4px 0;
    min-width: 160px;
    z-index: 3000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
    font-size: 13px;
}

#context-menu.open { display: block; }

#context-menu .ctx-item {
    padding: 7px 14px;
    color: #ccc;
    cursor: pointer;
    transition: background 0.1s;
}

#context-menu .ctx-item:hover {
    background: #2a2a2a;
    color: #fff;
}

#context-menu .ctx-item.ctx-delete {
    color: #c44;
}

#context-menu .ctx-item.ctx-delete:hover {
    background: #2a1a1a;
    color: #e55;
}

#context-menu .ctx-sep {
    height: 1px;
    background: #333;
    margin: 4px 0;
}

/* --- Resize handle --- */

.node .resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 500;
}

.node:hover .resize-handle { opacity: 1; }

.node .resize-handle::after {
    content: '';
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 8px;
    height: 8px;
    border-right: 2px solid #555;
    border-bottom: 2px solid #555;
}

/* --- Pending connection line --- */

#pending-connection {
    fill: none;
    stroke: #4a9eff;
    stroke-width: 2;
    stroke-dasharray: 6 4;
    pointer-events: none;
}

/* --- Arrow marker --- */

.arrow-marker {
    fill: #555;
}
