/* ============================================================
   CANVAS VIEW — Game Designer's Hub
   ============================================================ */

#space-canvas {
    padding: 0 !important;
    overflow: hidden;
}

#space-canvas.active {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ── Toolbar ─────────────────────────────────────────────── */
.canvas-toolbar {
    height: 46px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    gap: 12px;
    z-index: 10;
}

.canvas-toolbar-left  { display: flex; align-items: center; gap: 12px; min-width: 140px; }
.canvas-toolbar-center { display: flex; gap: 4px; align-items: center; }
.canvas-toolbar-right { display: flex; align-items: center; gap: 10px; min-width: 200px; justify-content: flex-end; }

/* Thin vertical separator between view-toggle and tool-toggle in toolbar */
.toolbar-sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
}

/* ── View Switcher — pill/segmented control ───────────────── */
.view-switcher {
    display: flex;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px;
    gap: 2px;
}

.view-switcher-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 16px;
    border-radius: 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.18s ease;
    white-space: nowrap;
    letter-spacing: 0.1px;
}

.view-switcher-btn.active {
    background: var(--blue-bright);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(30,128,232,0.35);
}

.view-switcher-btn:not(.active):hover {
    background: var(--blue-glow-strong);
    color: var(--text-secondary);
}

.canvas-project-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.tool-btn:hover  { border-color: var(--blue-mid); color: var(--text-secondary); background: var(--blue-glow); }
.tool-btn.active { border-color: var(--blue-bright); color: var(--blue-bright); background: var(--blue-glow-strong); }

.canvas-ctrl-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 10px;
    font-family: 'Inter', sans-serif;
    transition: var(--transition);
}

.canvas-ctrl-btn:hover { border-color: var(--blue-mid); color: var(--text-primary); background: var(--blue-glow); }

.zoom-label  { font-size: 12px; color: var(--text-muted); min-width: 36px; text-align: center; }
.save-indicator { font-size: 11px; color: var(--text-muted); min-width: 54px; text-align: right; transition: color 0.3s; }

/* ── Layout ──────────────────────────────────────────────── */
.canvas-layout {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

/* ── Items Panel ─────────────────────────────────────────── */
.canvas-items-panel {
    width: 196px;
    min-width: 196px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.2s ease, min-width 0.2s ease;
    overflow: hidden;
}

.canvas-items-panel.collapsed { width: 0; min-width: 0; border-right-color: transparent; }

/* Always-visible vertical toggle bar. Sits between the items panel and the canvas
   in the flex flow. Permanent — never disappears, so the user can always reopen
   a collapsed panel. Bigger hit area + clear hover state to be discoverable. */
.canvas-panel-toggle-bar {
    flex-shrink: 0;
    width: 18px;
    background: var(--bg-sidebar);
    border: 0;
    border-right: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    font-family: 'Inter', sans-serif;
    line-height: 1;
    padding: 0;
    z-index: 5;
    transition: background 0.14s, color 0.14s;
}
.canvas-panel-toggle-bar:hover {
    background: var(--blue-deep);
    color: var(--text-primary);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.7px;
    text-transform: uppercase;
    color: var(--text-primary);
    flex-shrink: 0;
}

.panel-toggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 15px;
    padding: 0;
    font-family: 'Inter', sans-serif;
    transition: var(--transition);
    line-height: 1;
}

.panel-toggle:hover { color: var(--text-primary); }

.panel-scroll {
    overflow-y: auto;
    flex: 1;
    padding: 8px;
}

.panel-scroll::-webkit-scrollbar { width: 4px; }
.panel-scroll::-webkit-scrollbar-thumb { background: var(--blue-deep); border-radius: 4px; }

.panel-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px 8px 13px;
    border-radius: var(--radius-sm);
    cursor: grab;
    transition: var(--transition);
    border: 1px solid transparent;
    margin-bottom: 4px;
    background: var(--bg-card);
    user-select: none;
    position: relative;
    overflow: hidden;
}

.panel-item:hover  { border-color: var(--blue-mid); background: var(--bg-card-hover); }
.panel-item:active { cursor: grabbing; opacity: 0.7; }

.panel-item-strip {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
}

.panel-item-icon  { font-size: 13px; flex-shrink: 0; }
.panel-item-title {
    font-size: 11.5px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.panel-empty { font-size: 12px; color: var(--text-muted); padding: 20px 12px; text-align: center; line-height: 1.6; }

/* Search input above the items list */
.panel-search-wrap {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.panel-search {
    width: 100%;
    padding: 5px 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-primary);
    font-size: 11.5px;
    font-family: 'Inter', sans-serif;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.12s;
}
.panel-search:focus { border-color: var(--blue-bright); }
.panel-search::placeholder { color: var(--text-muted); }
/* Hide the native browser X clear button — we use Esc instead */
.panel-search::-webkit-search-cancel-button { display: none; }

/* Collapsible section header. Clicking toggles per-type collapse state. */
.panel-section-header {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    padding: 9px 8px 4px;
    background: transparent;
    border: 0;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    text-align: left;
}
.panel-section-header:hover { color: var(--text-primary); }
.panel-section-chev {
    font-size: 8px;
    line-height: 1;
    width: 9px;
    flex-shrink: 0;
    color: inherit;
}
.panel-section-count {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-secondary);
    background: rgba(255,255,255,0.06);
    padding: 1px 6px;
    border-radius: 8px;
    flex-shrink: 0;
}

.panel-section-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.7px;
    text-transform: uppercase;
    color: inherit;
    display: block;
}

/* Divider between base types and template types in items panel */
.panel-section-divider {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #c08fe0;
    padding: 14px 10px 4px;
    margin-top: 4px;
    border-top: 1px solid var(--border);
}

/* ── Viewport ────────────────────────────────────────────── */
.canvas-viewport {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
    overscroll-behavior: none; /* Prevent browser swipe-back gesture */
    background-color: var(--bg-base);
    background-image:
        linear-gradient(rgba(30, 128, 232, 0.055) 1px, transparent 1px),
        linear-gradient(90deg, rgba(30, 128, 232, 0.055) 1px, transparent 1px);
    background-size: 40px 40px;
    user-select: none;
}

.canvas-world {
    position: absolute;
    top: 0; left: 0;
    transform-origin: 0 0;
}

/* ── Canvas Nodes ────────────────────────────────────────── */
.canvas-node {
    position: absolute;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: grab;
    user-select: none;
    min-height: 54px;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
    overflow: visible; /* allow connect-dot to bleed outside */
    display: flex;
    flex-direction: column;
    /* Sit above comment boxes (z-index:0) even when added to the DOM later */
    z-index: 1;
}

/* When user has explicitly resized a node, inner preview/text fills the space */
.canvas-node.resized .node-preview {
    flex: 1;
    max-height: none;
    overflow: hidden;
}
.canvas-node.resized .node-preview-text {
    max-height: none;
    overflow: hidden;
    padding-bottom: 6px;
}
.canvas-node.resized .sticky-text {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* Image preview: when the user grows the frame (resize handle), let the image
   container grow with it AND switch object-fit from `cover` to `contain` so
   parts of the image that were cropped at default size are revealed instead
   of just adding empty padding around an unchanged crop. The dark backdrop
   keeps non-square images looking intentional rather than awkwardly floating. */
.canvas-node.resized .node-preview-image {
    max-height: none;
    height: 100%;
    overflow: hidden;
    background: rgba(0,0,0,0.35);
}
.canvas-node.resized .node-preview-img {
    height: 100%;
    object-fit: contain;
    object-position: center center;
}

/* inner clip so content doesn't bleed */
.canvas-node > *:not(.connect-dot):not(.node-delete-btn) { }
.node-inner-clip {
    border-radius: 10px;
    overflow: hidden;
}

.canvas-node:hover {
    border-color: var(--blue-mid);
    box-shadow: 0 0 18px var(--blue-glow), 0 4px 16px rgba(0,0,0,0.4);
    z-index: 10;
}

.canvas-node.selected {
    border-color: var(--blue-bright) !important;
    box-shadow: 0 0 0 2px rgba(30,128,232,0.25), 0 4px 20px rgba(0,0,0,0.5) !important;
    z-index: 11;
}

/* ── Node Header (type icon + title) ─────────────────────── */
.node-type-strip { height: 3px; width: 100%; flex-shrink: 0; border-radius: 10px 10px 0 0; }

.node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 26px 8px 12px;
    border-radius: 10px 10px 0 0;
    overflow: hidden;
}

.node-icon  { font-size: 13px; flex-shrink: 0; }
.node-title {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* ── Node Preview Area ───────────────────────────────────── */
.node-preview {
    position: relative;
    overflow: hidden;
    max-height: 88px;
    border-top: 1px solid rgba(255,255,255,0.04);
    border-radius: 0 0 10px 10px;
}

.node-preview-text {
    padding: 7px 12px 22px;
    font-size: 11px;
    line-height: 1.55;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-word;
}

.node-preview-link {
    padding: 7px 12px;
    font-size: 10px;
    color: var(--blue-mid);
    word-break: break-all;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: 'Courier New', monospace;
}

.node-preview-image {
    max-height: 110px;
    overflow: hidden;
    border-radius: 0 0 10px 10px;
}

.node-preview-img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    display: block;
}

/* Painted character portraits — bias the crop up so the face shows.
   Class is added by canvas.js when rendering a character node's preview. */
.node-preview-img.node-preview-portrait {
    object-position: 50% 15%;
}

.node-preview-fade {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 52px;
    /* Starts mid-transparent so you can see text being cut off, then fully opaque */
    background: linear-gradient(to bottom,
        rgba(14,21,36,0)    0%,
        rgba(14,21,36,0.6) 40%,
        rgba(14,21,36,1)   100%);
    pointer-events: none;
    border-radius: 0 0 10px 10px;
    /* "more" indicator */
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 5px;
}
.node-preview-fade::after {
    content: '• • •';
    font-size: 9px;
    letter-spacing: 2px;
    color: var(--text-muted);
    opacity: 0.7;
}

/* Change 3: Rich text preview for note nodes */
.node-preview-rich {
    padding: 7px 12px 22px;
    font-size: 10.5px;
    line-height: 1.5;
    color: var(--text-muted);
    word-break: break-word;
    overflow: hidden;
}
.node-preview-rich h1, .node-preview-rich h2, .node-preview-rich h3 {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    margin: 3px 0 2px;
}
.node-preview-rich strong, .node-preview-rich b { color: var(--text-secondary); font-weight: 600; }
.node-preview-rich em, .node-preview-rich i { opacity: 0.8; font-style: italic; }
.node-preview-rich p { margin: 0 0 3px; }
.node-preview-rich ul, .node-preview-rich ol { padding-left: 14px; margin: 2px 0; }
.node-preview-rich li { margin: 1px 0; }

/* Change 5: Video play overlay */
.node-preview-video-play {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 32px; height: 32px;
    background: rgba(0,0,0,0.65);
    border: 2px solid rgba(255,255,255,0.7);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
    color: #fff;
    pointer-events: none;
}

/* ── Delete button ───────────────────────────────────────── */
.node-delete-btn {
    position: absolute;
    top: 5px; right: 5px;
    width: 18px; height: 18px;
    border-radius: 3px;
    background: rgba(6,11,20,0.9);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 9px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition);
    z-index: 20;
}

.canvas-node:hover .node-delete-btn { opacity: 1; }
.node-delete-btn:hover { background: rgba(192,57,43,0.35); color: #e05c4a; border-color: #c03930; }

/* Change 1: Remove the left-override for sticky delete btn — keep it at top-right.
   Add padding-right to drag handle so label doesn't overlap X button.
   Remove any margin-right offset on the color picker (handle padding handles the gap). */
.canvas-sticky .sticky-drag-handle { padding-right: 26px; }
.canvas-sticky .sticky-color-picker { margin-right: 0; }

/* ── Connect dots ─────────────────────────────────────────── */
/* Base shared by all three dots */
/* Connection dots — 4 cardinal positions, all BIDIRECTIONAL.
   Every dot is a drag SOURCE and a drop TARGET — no input/output distinction.
   Drag from any dot on one card to any dot on another to create a connection. */
.connect-dot {
    position: absolute;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--blue-bright);
    border: 2px solid var(--bg-base);
    opacity: 0;
    transition: opacity 0.14s, transform 0.14s, box-shadow 0.14s, background 0.14s;
    z-index: 30;
    box-shadow: 0 0 7px rgba(30,128,232,0.65);
    pointer-events: all;
    cursor: crosshair;
    box-sizing: border-box;
}
/* Cardinal dot positions — centered on each edge of the node */
.connect-dot-top {
    top: -8px;
    left: 50%;
    margin-left: -8px;
}
.connect-dot-right {
    right: -8px;
    top: 50%;
    margin-top: -8px;
}
.connect-dot-bottom {
    bottom: -8px;
    left: 50%;
    margin-left: -8px;
}
.connect-dot-left {
    left: -8px;
    top: 50%;
    margin-top: -8px;
}
/* Dots are visible whenever the card is hovered or selected */
.canvas-node:hover .connect-dot,
.canvas-node.selected .connect-dot { opacity: 1; }
.connect-dot:hover {
    /* Bigger + brighter on hover. Each dot uses CSS vars so the centering math stays right. */
    background: #4dd1ff;
    box-shadow: 0 0 14px rgba(77,209,255,0.95), 0 0 0 2px rgba(255,255,255,0.55);
    transform: scale(1.35);
}
/* When a connection drag is happening, ALL dots on every card light up so the user
   sees every drop target at a glance. */
.canvas-node.connect-target .connect-dot {
    opacity: 1;
    animation: dotPulse 0.7s ease-in-out infinite alternate;
}
@keyframes dotPulse {
    from { box-shadow: 0 0 5px rgba(30,128,232,0.5); }
    to   { box-shadow: 0 0 14px rgba(30,128,232,1); }
}
/* Backward-compat: legacy class .connect-dot-src is the old name for the right dot */
.connect-dot-src {
    right: -8px;
    top: 50%;
    margin-top: -8px;
}

/* ── Multi-select rectangle ──────────────────────────────── */
.selection-rect {
    position: absolute;
    border: 1.5px solid rgba(30,128,232,0.75);
    background: rgba(30,128,232,0.07);
    border-radius: 4px;
    pointer-events: none;
    z-index: 3;
}

/* ── Sticky Notes ────────────────────────────────────────── */
.canvas-sticky {
    background: var(--sc, #1c1600) !important;
    border-color: rgba(255,255,255,0.07) !important;
    border-radius: 8px !important;
    min-height: 110px !important;
    overflow: visible !important;
}

.canvas-sticky:hover {
    border-color: rgba(255,255,255,0.16) !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.45) !important;
}

/* sticky drag handle — always grabbable */
.sticky-drag-handle {
    padding: 7px 10px 5px 12px;
    cursor: grab;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    border-radius: 8px 8px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.sticky-drag-handle:active { cursor: grabbing; }

.sticky-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.7px;
    text-transform: uppercase;
    /* Was 0.25 -- too dim against the brighter 2026-05-08 STICKY_COLORS palette.
       0.7 keeps the label readable on every hue (including the pale yellows) without
       fighting the user's note text for attention. */
    color: rgba(255,255,255,0.7);
    user-select: none;
    flex-shrink: 0;
}

.sticky-text {
    padding: 10px 14px 14px;
    font-size: 12.5px;
    line-height: 1.65;
    color: rgba(255,255,255,0.92);
    min-height: 80px;
    outline: none;
    cursor: default;  /* looks drag-friendly until focused */
    word-break: break-word;
    white-space: pre-wrap;
}
.sticky-text:focus {
    cursor: text;
    background: rgba(255,255,255,0.03);
    border-radius: 0 0 8px 8px;
}

.sticky-text:empty::before {
    content: 'Write anything...';
    color: rgba(255,255,255,0.22);
    pointer-events: none;
}

/* ── Resize Handle ───────────────────────────────────────── */
.node-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 25;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 3px;
    border-radius: 0 0 10px 0;
}
.node-resize-handle::after {
    content: '';
    display: block;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    border-radius: 0 0 2px 0;
}
.canvas-node:hover .node-resize-handle { opacity: 0.7; }
.node-resize-handle:hover { opacity: 1 !important; }

/* Change 9: comment box resize handle border radius matches comment box */
.canvas-comment .node-resize-handle { border-radius: 0 0 10px 0; }

/* ── Sticky Color Picker (popup) ─────────────────────────── */
.sticky-color-picker {
    position: relative;
    margin-left: auto;
    flex-shrink: 0;
}

/* Small circle button that shows current color */
.sticky-color-trigger {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.3);
    transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
    display: block;
}
.sticky-color-trigger:hover {
    transform: scale(1.25);
    border-color: rgba(255,255,255,0.7);
    box-shadow: 0 0 6px rgba(255,255,255,0.25);
}

/* Grid popup — hidden by default, shown on click */
.sticky-color-popup {
    position: absolute;
    top: calc(100% + 10px);
    right: -4px;
    background: rgba(10, 15, 26, 0.97);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    padding: 10px;
    display: none;
    grid-template-columns: repeat(5, 1fr);
    gap: 7px;
    z-index: 200;
    box-shadow: 0 8px 28px rgba(0,0,0,0.65), 0 2px 8px rgba(0,0,0,0.4);
    min-width: 116px;
    animation: popupFadeIn 0.12s ease;
}

.sticky-color-popup.open { display: grid; }

@keyframes popupFadeIn {
    from { opacity: 0; transform: translateY(-4px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.sticky-color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.15);
    transition: transform 0.12s, border-color 0.12s;
    flex-shrink: 0;
}
.sticky-color-dot:hover  { transform: scale(1.3); border-color: rgba(255,255,255,0.6); }
.sticky-color-dot.active { border-color: #fff !important; transform: scale(1.2); }

/* ── Drag Ghost ──────────────────────────────────────────── */
.panel-drag-ghost {
    position: fixed;
    z-index: 9999;
    background: var(--bg-card);
    border: 1px solid var(--blue-mid);
    border-radius: var(--radius-md);
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text-primary);
    pointer-events: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.55);
    white-space: nowrap;
}

/* ── Minimap ─────────────────────────────────────────────── */
/* `bottom: 60px` clears the floating account chip (#gh-account-chip) which
   sits at bottom:16px right:16px with z-index:9999. Without this offset the
   minimap and the chip stack on top of each other in the corner. */
.canvas-minimap {
    position: absolute;
    bottom: 60px;
    right: 16px;
    background: rgba(6, 11, 20, 0.92);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    z-index: 20;
}

#minimap-canvas { display: block; cursor: pointer; }

/* ── Connect mode hint ───────────────────────────────────── */
.connect-hint {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(21, 96, 168, 0.9);
    border: 1px solid var(--blue-mid);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 12px;
    color: var(--text-primary);
    pointer-events: none;
    z-index: 20;
    backdrop-filter: blur(4px);
    white-space: nowrap;
    display: none;
}

.connect-hint.visible { display: block; }

/* ── Canvas toolbar back button ─────────────────────────── */
#space-canvas .btn-back {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    padding: 5px 14px;
    transition: var(--transition);
    white-space: nowrap;
}
#space-canvas .btn-back:hover {
    border-color: var(--blue-mid);
    color: var(--text-primary);
    background: var(--blue-glow);
}

/* ── Canvas right-click context menu ────────────────────── */
.canvas-ctx-menu {
    position: fixed;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 5px;
    min-width: 210px;
    max-width: 270px;
    z-index: 9000;
    display: none;
    box-shadow: 0 8px 32px rgba(0,0,0,0.55), 0 2px 8px rgba(0,0,0,0.3);
}

.canvas-ctx-menu.open { display: block; }

.canvas-ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12.5px;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}

.canvas-ctx-item:hover {
    background: var(--blue-glow);
    color: var(--text-primary);
}

.canvas-ctx-item.ctx-danger { color: #e05c4a; }
.canvas-ctx-item.ctx-danger:hover { background: rgba(192,57,43,0.15); color: #f07060; }

.canvas-ctx-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.7px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 8px 12px 3px;
    display: block;
}

.canvas-ctx-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 6px;
}

.canvas-ctx-empty {
    font-size: 11.5px;
    color: var(--text-muted);
    padding: 8px 12px 10px;
    text-align: center;
    line-height: 1.55;
}

#ctx-items-list {
    max-height: 220px;
    overflow-y: auto;
}
#ctx-items-list::-webkit-scrollbar { width: 3px; }
#ctx-items-list::-webkit-scrollbar-thumb { background: var(--blue-deep); border-radius: 3px; }

.ctx-strip {
    width: 3px; height: 14px;
    border-radius: 2px;
    flex-shrink: 0;
    display: inline-block;
    background: var(--type-color, transparent);
}

/* Flyout sub-menu (Add to Project & Canvas → 11 types in a 2-col grid) */
.canvas-ctx-flyout-trigger {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.canvas-ctx-flyout-arrow {
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
}
.canvas-ctx-menu .canvas-ctx-flyout {
    display: none;
    position: fixed;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 5px;
    z-index: 9001;
    box-shadow: 0 8px 32px rgba(0,0,0,0.55), 0 2px 8px rgba(0,0,0,0.3);
    width: 320px;
}
.canvas-ctx-menu .canvas-ctx-flyout.open { display: block; }
.canvas-ctx-flyout-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
}
.canvas-ctx-flyout-grid .canvas-ctx-item {
    padding: 7px 10px;
    font-size: 12px;
}
.canvas-ctx-flyout-grid .ctx-strip {
    width: 3px;
    height: 16px;
    margin-right: 4px;
}

/* ── Dragging state on node ──────────────────────────────── */
.canvas-node.dragging {
    cursor: grabbing !important;
    opacity: 0.92;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6) !important;
    z-index: 50 !important;
}

/* ── Locked node — shows a small 🔒 corner badge + dashed amber outline.
   Pinning is purely behavioral (handled in JS); the visual makes it obvious. */
.canvas-node.locked {
    cursor: default !important;
    border-color: rgba(220,170,40,0.55) !important;
    border-style: dashed;
}
.canvas-node.locked::before {
    content: '🔒';
    position: absolute;
    top: 4px;
    right: 22px;
    font-size: 11px;
    line-height: 1;
    z-index: 2;
    opacity: 0.85;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

/* ── Undo / Redo disabled state ──────────────────────────── */
.canvas-ctrl-btn:disabled {
    opacity: 0.32;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Snap-to-grid: brighter grid when active ─────────────── */
.canvas-viewport.snap-active {
    background-image:
        linear-gradient(rgba(30, 128, 232, 0.13) 1px, transparent 1px),
        linear-gradient(90deg, rgba(30, 128, 232, 0.13) 1px, transparent 1px);
}

/* ── Hint Overlay ────────────────────────────────────────── */
.canvas-hint-overlay {
    position: absolute;
    bottom: 174px;   /* above minimap (which sits at 60px + ~100px tall) */
    right: 16px;
    z-index: 25;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.hint-toggle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(10,18,34,0.9);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    backdrop-filter: blur(4px);
}
.hint-toggle:hover {
    border-color: var(--blue-mid);
    color: var(--text-primary);
    background: var(--blue-glow-strong);
}

.hint-panel {
    background: rgba(8, 14, 26, 0.97);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    min-width: 230px;
    display: none;
    flex-direction: column;
    gap: 6px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    backdrop-filter: blur(6px);
    animation: popupFadeIn 0.14s ease;
}
.hint-panel.open { display: flex; }

.hint-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.hint-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 11px;
    color: var(--text-secondary);
}

.hint-key {
    background: rgba(30,128,232,0.12);
    border: 1px solid rgba(30,128,232,0.2);
    border-radius: 5px;
    padding: 2px 7px;
    font-size: 10.5px;
    font-family: 'Inter', sans-serif;
    color: var(--blue-mid);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Comment Boxes (Blueprint-style) ────────────────────────── */
.canvas-comment {
    position: absolute;
    background: var(--cc-bg, rgba(20,60,120,0.12));
    border: 2px solid var(--cc-border, rgba(30,128,232,0.45));
    border-radius: 12px;
    cursor: default;
    user-select: none;
    z-index: 0;
    min-width: 140px;
    min-height: 80px;
    overflow: visible;
    /* Body area is click-through so nodes inside can be freely clicked/dragged */
    pointer-events: none;
}

/* Only the header strip captures mouse events for dragging the comment */
.comment-header {
    pointer-events: all;
}
.comment-delete-btn,
.node-resize-handle,
.comment-color-dot {
    pointer-events: all;
}

.canvas-comment.selected {
    border-color: #4aa0ff !important;
    box-shadow: 0 0 0 2px rgba(30,128,232,0.2);
}

.comment-header {
    background: var(--cc-header, rgba(20,80,160,0.3));
    border-radius: 10px 10px 0 0;
    padding: 6px 10px 6px 12px;
    cursor: grab;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--cc-border, rgba(30,128,232,0.3));
}
.comment-header:active { cursor: grabbing; }

.comment-label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255,255,255,0.75);
    flex: 1;
    cursor: inherit;
    outline: none;
    border-radius: 3px;
    padding: 1px 3px;
    min-width: 40px;
}
.comment-label[contenteditable="true"] {
    cursor: text;
    background: rgba(255,255,255,0.08);
}

.comment-color-strip {
    display: flex;
    gap: 5px;
    align-items: center;
}

.comment-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    cursor: pointer;
    border: 1.5px solid rgba(255,255,255,0.2);
    opacity: 0;
    transition: opacity 0.15s;
}
.canvas-comment:hover .comment-color-dot { opacity: 1; }
.comment-color-dot:hover  { transform: scale(1.35); border-color: rgba(255,255,255,0.6); opacity: 1 !important; }
.comment-color-dot.active { border-color: #fff !important; opacity: 1 !important; transform: scale(1.2); }

.comment-font-ctrl {
    display: flex;
    gap: 3px;
    pointer-events: all;
}
.comment-font-btn {
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 4px;
    color: rgba(255,255,255,0.6);
    font-size: 9px;
    font-family: 'Inter', sans-serif;
    padding: 1px 5px;
    cursor: pointer;
    opacity: 0.45;  /* visible by default so users can discover them */
    transition: opacity 0.15s, background 0.1s;
    pointer-events: all;
}
.canvas-comment:hover .comment-font-btn { opacity: 1; }
.comment-font-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }

.comment-delete-btn {
    width: 18px; height: 18px;
    border-radius: 3px;
    background: transparent;
    border: 1px solid transparent;
    color: rgba(255,255,255,0.35);
    font-size: 9px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition);
    flex-shrink: 0;
    font-family: 'Inter', sans-serif;
}
.canvas-comment:hover .comment-delete-btn { opacity: 1; }
.comment-delete-btn:hover { background: rgba(192,57,43,0.35); color: #e05c4a; border-color: #c03930; }

/* Make resize handle visible on comment hover */
.canvas-comment:hover .node-resize-handle { opacity: 0.7; }
