/* FigureForge — Workspace (VibePaper-style infinite canvas)
   Infinite pannable/zoomable canvas with node cards (figures, images,
   notes, text), reference edges, a one-sentence prompt bar and a
   remix plaza. Follows the dual-theme variables from style.css. */

/* ---------- mode switching ---------- */
body.mode-canvas #left-panel,
body.mode-canvas #right-panel,
body.mode-canvas #canvas-container,
body.mode-canvas .canvas-empty,
body.mode-canvas #btn-undo,
body.mode-canvas #btn-redo,
body.mode-canvas #btn-insert-text,
body.mode-canvas .text-btn,
body.mode-canvas #btn-grid,
body.mode-canvas #btn-snap,
body.mode-canvas #btn-zoom-out,
body.mode-canvas #zoom-level,
body.mode-canvas #btn-zoom-in,
body.mode-canvas #btn-zoom-fit,
body.mode-canvas .export-bar { display: none !important; }

.mode-switch { display: flex; background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; margin-left: 12px; }
.mode-btn { display: inline-flex; align-items: center; gap: 6px; background: transparent; border: none; color: var(--text-dim); padding: 5px 12px; border-radius: 7px; cursor: pointer; font-size: 12px; font-weight: 550; transition: all 0.16s; white-space: nowrap; }
.mode-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.mode-btn:hover { color: var(--text-bright); }
.mode-btn.active { background: var(--bg-panel); color: var(--accent); box-shadow: 0 1px 5px rgba(0,0,0,0.3), inset 0 0 0 1px var(--border-panel); font-weight: 600; }
body.theme-light .mode-btn.active { box-shadow: 0 1px 4px rgba(30, 42, 68, 0.14); }

/* ---------- stage ---------- */
#workspace-view { position: absolute; inset: 0; display: none; overflow: hidden; z-index: 5;
  background-image:
    radial-gradient(var(--ws-dot) 1.1px, transparent 1.3px),
    radial-gradient(1200px 760px at 50% 36%, rgba(47, 196, 178, 0.09), transparent 62%),
    radial-gradient(900px 620px at 78% 82%, rgba(124, 111, 208, 0.07), transparent 65%),
    radial-gradient(760px 540px at 14% 74%, rgba(236, 111, 159, 0.05), transparent 65%);
  background-color: var(--bg-canvas); }
#workspace-view.no-grid { background-image: none,
    radial-gradient(1200px 760px at 50% 36%, rgba(47, 196, 178, 0.09), transparent 62%),
    radial-gradient(900px 620px at 78% 82%, rgba(124, 111, 208, 0.07), transparent 65%),
    radial-gradient(760px 540px at 14% 74%, rgba(236, 111, 159, 0.05), transparent 65%); }
body.mode-canvas #workspace-view { display: block; }

#ws-world { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
body.theme-light { --ws-dot: rgba(19, 24, 38, 0.13); }
body:not(.theme-light) { --ws-dot: rgba(255, 255, 255, 0.09); }

#ws-edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#ws-edges path.edge-line { fill: none; stroke: var(--text-dim); stroke-width: 1.6; opacity: 0.75; }
#ws-edges path.edge-line.selected { stroke: var(--accent); stroke-width: 2.2; opacity: 1; }
#ws-edges path.edge-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
#ws-edges path.edge-ghost { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-dasharray: 6 4; opacity: 0.9; }
#ws-nodes { position: absolute; left: 0; top: 0; }

#workspace-view.tool-hand { cursor: grab; }
#workspace-view.tool-hand.panning { cursor: grabbing; }
#workspace-view.tool-hand .ws-node { cursor: grab; }

#ws-marquee { position: absolute; border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 3px; pointer-events: none; z-index: 40; }

/* ---------- node cards ---------- */
.ws-node { position: absolute; border-radius: 12px; background: var(--bg-panel); border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35); user-select: none; touch-action: none; }
body.theme-light .ws-node { box-shadow: 0 6px 20px rgba(30, 42, 68, 0.14); }
.ws-node:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.ws-node.selected { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent), 0 10px 32px rgba(0, 0, 0, 0.4); }

.ws-node-head { display: flex; align-items: center; gap: 7px; padding: 7px 9px; border-bottom: 1px solid var(--border);
  cursor: grab; border-radius: 12px 12px 0 0; background: color-mix(in srgb, var(--bg-input) 60%, transparent); }
.ws-node-head:active { cursor: grabbing; }
.ws-node-icon { flex-shrink: 0; color: var(--accent); display: flex; }
.ws-node-icon svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ws-node-title { font-size: 11.5px; font-weight: 600; color: var(--text-bright); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; outline: none; border-radius: 4px; padding: 1px 4px; }
.ws-node-title[contenteditable="true"] { background: var(--bg-input); box-shadow: 0 0 0 1px var(--accent); cursor: text; white-space: pre-wrap; }
.ws-node-actions { display: none; gap: 2px; flex-shrink: 0; }
.ws-node:hover .ws-node-actions, .ws-node.selected .ws-node-actions { display: flex; }
.ws-node-actions button { display: flex; align-items: center; justify-content: center; background: transparent; border: none; color: var(--text-dim); width: 22px; height: 22px; border-radius: 6px; cursor: pointer; padding: 0; }
.ws-node-actions button svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ws-node-actions button:hover { background: var(--bg-input); color: var(--text-bright); }
.ws-node-actions button[data-act="del"]:hover { color: var(--danger); }

.ws-node-body { border-radius: 0 0 12px 12px; overflow: hidden; background: #ffffff; }
.ws-node.type-note .ws-node-body { background: transparent; }
.ws-fig, .ws-img { line-height: 0; }
.ws-fig svg { width: 100%; height: auto; display: block; }
.ws-img img { width: 100%; height: auto; display: block; pointer-events: none; }

/* sticky note */
.ws-node.type-note { background: #f9efd2; border-color: #e7d8a6; box-shadow: 0 8px 22px rgba(0,0,0,0.3); }
.ws-node.type-note.hue-honey { background: #f9efd2; border-color: #e7d8a6; }
.ws-node.type-note.hue-mint { background: #d9f2e3; border-color: #aedcc5; }
.ws-node.type-note.hue-rose { background: #fbe1e8; border-color: #eebfcc; }
.ws-node.type-note.hue-lilac { background: #e9e3f8; border-color: #cec0eb; }
body.theme-light .ws-node.type-note { box-shadow: 0 8px 18px rgba(120, 96, 20, 0.18); }
.ws-node.type-note.selected { box-shadow: 0 0 0 1.5px var(--accent), 0 8px 22px rgba(0,0,0,0.3); }
.ws-note-body { min-height: 150px; padding: 12px; font-size: 12.5px; line-height: 1.65; color: #6b5a1e; outline: none; border-radius: 12px; cursor: grab; white-space: pre-wrap; word-break: break-word; }
.hue-mint .ws-note-body { color: #2f5c44; }
.hue-rose .ws-note-body { color: #7c4054; }
.hue-lilac .ws-note-body { color: #4f4472; }
.ws-note-body:active { cursor: grabbing; }
.ws-note-body[contenteditable="true"], .ws-text-body[contenteditable="true"] { cursor: text; }

/* plain text node */
.ws-node.type-text { background: transparent; border: 1px dashed transparent; box-shadow: none; border-radius: 8px; }
.ws-node.type-text:hover { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.ws-node.type-text.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.ws-text-body { padding: 6px 8px; font-size: 14px; color: var(--text-bright); outline: none; cursor: grab; white-space: pre-wrap; word-break: break-word; min-width: 120px; }
.ws-text-body:active { cursor: grabbing; }

/* resize handle + edge port */
.ws-node-resize { position: absolute; right: -5px; bottom: -5px; width: 12px; height: 12px; border-radius: 3px;
  background: #ffffff; border: 1.5px solid var(--accent); cursor: nwse-resize; display: none; }
.ws-node:hover .ws-node-resize, .ws-node.selected .ws-node-resize { display: block; }
.ws-node-port { position: absolute; right: -7px; top: 50%; transform: translateY(-50%); width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: 2.5px solid #ffffff; box-shadow: 0 1px 5px rgba(0,0,0,0.4); cursor: crosshair; display: none; z-index: 3; }
.ws-node:hover .ws-node-port, .ws-node.selected .ws-node-port { display: block; }
.ws-node.type-note .ws-node-port, .ws-node.type-text .ws-node-port { top: 24px; }

/* generating state */
.ws-gen { padding: 34px 20px; display: flex; flex-direction: column; align-items: center; gap: 14px; background: var(--bg-panel); }
.ws-gen-ring { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--accent-dim); border-top-color: var(--accent); animation: ws-spin 0.9s linear infinite; }
@keyframes ws-spin { to { transform: rotate(360deg); } }
.ws-gen-label { font-size: 11.5px; color: var(--text-dim); text-align: center; line-height: 1.6; }
.ws-gen-label b { color: var(--accent); font-weight: 600; }

/* ---------- floating chrome ---------- */
#ws-toolbar { position: absolute; left: 16px; top: 16px; display: flex; flex-direction: column; gap: 3px; padding: 6px; z-index: 20;
  background: color-mix(in srgb, var(--bg-panel) 84%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-panel); border-radius: 13px; box-shadow: 0 10px 32px rgba(0,0,0,0.38); }
.ws-tool { width: 34px; height: 34px; border-radius: 9px; border: none; background: transparent; color: var(--text-dim); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.14s; }
.ws-tool svg { width: 16.5px; height: 16.5px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ws-tool:hover { background: var(--bg-input); color: var(--text-bright); }
.ws-tool.active { background: var(--accent-dim); color: var(--accent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent); }
.ws-tool-sep { height: 1px; background: var(--border); margin: 3px 6px; }

/* zoom cluster */
#ws-zoom { position: absolute; right: 16px; bottom: 16px; display: flex; align-items: center; gap: 2px; padding: 5px; z-index: 20;
  background: color-mix(in srgb, var(--bg-panel) 84%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-panel); border-radius: 11px; box-shadow: 0 10px 32px rgba(0,0,0,0.38); }
#ws-zoom .ws-tool { width: 28px; height: 26px; }
#ws-zoom .ws-tool svg { width: 14px; height: 14px; }
#ws-zoom-level { font-size: 11px; color: var(--text-dim); min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; cursor: pointer; border-radius: 6px; padding: 4px 0; transition: all 0.14s; }
#ws-zoom-level:hover { color: var(--text-bright); background: var(--bg-input); }
#ws-zoom-hint { position: absolute; right: 18px; bottom: 60px; font-size: 10.5px; color: var(--text-dim); opacity: 0.65; z-index: 19; pointer-events: none; text-align: right; line-height: 1.75; }

/* ---------- prompt bar (one-sentence generation) ---------- */
#ws-prompt { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(680px, calc(100vw - 140px)); z-index: 25; }
.ws-prompt-steps { display: flex; gap: 6px; justify-content: center; margin-bottom: 8px; flex-wrap: wrap; }
.ws-prompt-steps:empty { margin: 0; }
.ws-step-chip { font-size: 10.5px; padding: 3.5px 11px; border-radius: 20px; color: var(--text-dim);
  background: color-mix(in srgb, var(--bg-panel) 85%, transparent); border: 1px solid var(--border-panel); animation: ws-chip-in 0.25s ease; }
.ws-step-chip.running { color: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent); }
.ws-step-chip.done { color: var(--success); border-color: color-mix(in srgb, var(--success) 50%, transparent); }
@keyframes ws-chip-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.ws-prompt-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 16px;
  background: color-mix(in srgb, var(--bg-panel) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-panel); box-shadow: 0 14px 48px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255,255,255,0.04); transition: border-color 0.15s, box-shadow 0.15s; }
.ws-prompt-row:focus-within { border-color: color-mix(in srgb, var(--accent) 70%, transparent); box-shadow: 0 14px 48px rgba(0, 0, 0, 0.45), 0 0 0 3.5px color-mix(in srgb, var(--accent) 15%, transparent); }
.ws-prompt-spark { flex-shrink: 0; color: var(--accent); display: flex; }
.ws-prompt-spark svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#ws-prompt-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text-bright); font-size: 13.5px; font-family: var(--font); min-width: 0; }
#ws-prompt-input::placeholder { color: var(--text-dim); }
#ws-prompt-palette { background: var(--bg-input); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 5px 7px; font-size: 11.5px; max-width: 118px; cursor: pointer; }
#ws-prompt-go { display: inline-flex; align-items: center; gap: 6px; background: linear-gradient(135deg, #14b8a6, #0d9488); border: none; color: #ffffff; padding: 7px 15px; border-radius: 11px; cursor: pointer; font-size: 12.5px; font-weight: 600; white-space: nowrap; box-shadow: 0 4px 16px rgba(20, 184, 166, 0.3); transition: filter 0.15s, box-shadow 0.15s; }
#ws-prompt-go kbd { font-family: var(--font); font-size: 10px; opacity: 0.7; border: 1px solid rgba(255,255,255,0.45); border-radius: 4px; padding: 0 4px; line-height: 1.5; }
#ws-prompt-go:hover { filter: brightness(1.07); box-shadow: 0 6px 20px rgba(20, 184, 166, 0.4); }
#ws-prompt-go:disabled { opacity: 0.5; cursor: wait; }

/* ---------- plaza (remix gallery) ---------- */
#ws-plaza { position: absolute; left: 0; top: 0; bottom: 0; width: 300px; z-index: 30; display: flex; flex-direction: column;
  background: color-mix(in srgb, var(--bg-panel) 94%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-right: 1px solid var(--border-panel); box-shadow: 14px 0 44px rgba(0, 0, 0, 0.3);
  transform: translateX(-102%); transition: transform 0.22s ease; }
#ws-plaza.open { transform: none; }
.ws-plaza-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.ws-plaza-title { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 700; color: var(--text-bright); letter-spacing: 0.02em; }
.ws-plaza-title svg { width: 15px; height: 15px; fill: none; stroke: var(--accent); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ws-plaza-close { display: flex; align-items: center; justify-content: center; background: transparent; border: none; color: var(--text-dim); cursor: pointer; width: 26px; height: 26px; border-radius: 7px; }
.ws-plaza-close svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.ws-plaza-close:hover { background: var(--bg-input); color: var(--text-bright); }
.ws-plaza-sub { font-size: 11px; color: var(--text-dim); padding: 0 16px 12px; line-height: 1.6; border-bottom: 1px solid var(--border-panel); margin-bottom: 4px; }
#ws-plaza-body { flex: 1; overflow-y: auto; padding: 0 16px 20px; }
.ws-plaza-sec { font-size: 10.5px; font-weight: 650; color: var(--accent); text-transform: uppercase; letter-spacing: 0.1em; margin: 16px 0 9px; }
.ws-plaza-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.ws-plaza-item { background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; padding: 7px; cursor: pointer; transition: all 0.15s; }
.ws-plaza-item:hover { border-color: var(--accent); transform: translateY(-1.5px); box-shadow: 0 8px 22px rgba(0,0,0,0.38); }
.ws-plaza-thumb { width: 100%; height: 70px; background: #ffffff; border-radius: 6px; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.ws-plaza-thumb svg { max-width: 100%; max-height: 100%; }
.ws-plaza-thumb .ws-plaza-spinner { font-size: 14px; color: var(--text-dim); animation: ws-spin 1s linear infinite; }
.ws-plaza-label { font-size: 11px; font-weight: 500; color: var(--text); opacity: 0.78; text-align: center; margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-plaza-item:hover .ws-plaza-label { opacity: 1; color: var(--text-bright); }
.ws-plaza-row { display: flex; gap: 9px; }
.ws-plaza-row .ws-plaza-item { flex: 1; }
.ws-plaza-row .ws-plaza-thumb { background: var(--bg-panel); color: var(--text-dim); }
.ws-plaza-row .ws-plaza-thumb svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- empty hero ---------- */
#ws-empty { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); text-align: center; z-index: 10; pointer-events: none; }
#ws-empty.hidden { display: none; }
.ws-empty-badge { width: 64px; height: 64px; margin: 0 auto 18px; display: flex; align-items: center; justify-content: center;
  border-radius: 19px; background: var(--accent-dim); border: 1px solid var(--border-panel); color: var(--accent);
  box-shadow: 0 12px 38px rgba(20, 184, 166, 0.2), inset 0 1px 0 rgba(255,255,255,0.06); }
.ws-empty-badge svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
#ws-empty h2 { font-size: 21px; font-weight: 700; color: var(--text-bright); letter-spacing: 0.01em; }
#ws-empty p { font-size: 12.5px; color: var(--text-dim); margin-top: 9px; line-height: 1.9; }
.ws-empty-chips { display: flex; gap: 9px; justify-content: center; margin-top: 18px; flex-wrap: wrap; pointer-events: auto; }
.ws-empty-chip { display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px; font-weight: 500; padding: 6px 14px; border-radius: 22px; color: var(--text); cursor: pointer;
  background: color-mix(in srgb, var(--bg-panel) 80%, transparent); border: 1px solid var(--border-panel); transition: all 0.15s; }
.ws-empty-chip svg { width: 12.5px; height: 12.5px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: 0.75; }
.ws-empty-chip:hover { border-color: var(--accent); color: var(--text-bright); background: color-mix(in srgb, var(--accent) 8%, var(--bg-panel)); }

@media (max-width: 720px) {
  #ws-plaza { width: 84vw; }
  .mode-btn { padding: 4px 8px; font-size: 11px; }
}
