:root {
  --bg: #0f1420;
  --bg-panel: #161d2e;
  --bg-panel-2: #1c2740;
  --bg-elevated: #212c47;
  --border: #2a3654;
  --border-soft: #223050;
  --text: #e6ebf5;
  --text-dim: #93a0bd;
  --text-faint: #5f6c8a;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.15);

  --c-idle: #5f6c8a;
  --c-healthy: #22c55e;
  --c-warning: #eab308;
  --c-critical: #f97316;
  --c-overloaded: #ef4444;
  --c-throttled: #d946ef;
  --c-crashed: #7f1d1d;

  --cat-generic: #64748b;
  --cat-aws: #FF9900;
  --cat-gcp: #4285F4;
  --cat-azure: #0078D4;

  --radius: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Toolbar ---------- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 5px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; }
.toolbar-right { margin-left: auto; }
.brand { gap: 6px; padding-right: 12px; border-right: 1px solid var(--border); }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-weight: 700; letter-spacing: 0.2px; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #283759; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #06122b; font-weight: 700; }
.btn-primary:hover { background: #7aa1ff; }
.btn-primary.running { background: var(--c-overloaded); border-color: var(--c-overloaded); color: white; }
.btn-warning { background: #3a2c0e; border-color: #6b4f10; color: #ffce54; }
.btn-warning:hover { background: #4a3812; }
.btn-warning.active { background: var(--c-warning); color: #241c00; }
.btn-danger-outline { border-color: #5c2323; color: #ff8a8a; background: transparent; }
.btn-danger-outline:hover { background: #351616; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-elevated); }

select, input[type="text"], input[type="number"] {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-size: 12.5px;
}
.speed-label { display: flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 12px; }
.file-btn { position: relative; overflow: hidden; }

/* ---------- Main layout ---------- */
#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#palette {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.palette-search { padding: 10px; border-bottom: 1px solid var(--border-soft); }
.palette-search input { width: 100%; }

.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--border-soft); flex-wrap: wrap; }
.tab-btn {
  background: transparent; border: none; color: var(--text-dim);
  padding: 7px 10px; border-radius: 6px 6px 0 0; cursor: pointer; font-size: 12px; font-weight: 600;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); background: var(--bg-panel-2); }

.palette-list { flex: 1; overflow-y: auto; padding: 8px; }
.palette-category { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin: 10px 4px 6px; }
.palette-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; margin-bottom: 4px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  cursor: grab;
  user-select: none;
}
.palette-item:hover { border-color: var(--accent); background: var(--bg-elevated); }
.palette-item:active { cursor: grabbing; }
.palette-item .badge { flex-shrink: 0; }
.palette-item-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.palette-item .name { font-size: 12px; font-weight: 600; }
.palette-item .blurb {
  font-size: 10.5px; color: var(--text-faint); line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.palette-item:hover .blurb { color: var(--text-dim); }

/* ---------- Badge / icon ---------- */
.badge {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 800; color: white;
  border: 1.5px solid rgba(255,255,255,0.35);
  flex-shrink: 0;
  line-height: 1;
  text-align: center;
  overflow: hidden;
}
.badge.shape-badge { border-radius: 7px; }
.badge.shape-circle { border-radius: 50%; }
.badge.shape-diamond { border-radius: 6px; transform: rotate(45deg); }
.badge.shape-diamond .badge-glyph { transform: rotate(-45deg); display:block; }
.badge-svg { width: 18px; height: 18px; display: block; }
.badge.shape-diamond .badge-svg { transform: rotate(-45deg); }
.badge.badge-lg { width: 34px; height: 34px; }
.badge.badge-lg .badge-svg { width: 22px; height: 22px; }

/* ---------- Canvas ---------- */
#canvas-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
  background:
    radial-gradient(circle, #263252 1px, transparent 1px);
  background-size: 22px 22px;
  background-color: #10182a;
  overflow: hidden;
}
#canvas-toolbar {
  position: absolute; top: 10px; left: 10px; z-index: 5;
  display: flex; align-items: center; gap: 6px;
  background: rgba(22, 29, 46, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  backdrop-filter: blur(4px);
  max-width: calc(100% - 20px);
}
.icon-btn {
  width: 22px; height: 22px; border-radius: 5px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.icon-btn:hover { background: #283759; }
#zoom-label { font-size: 11px; color: var(--text-dim); width: 38px; text-align: center; }
.hint { font-size: 11px; color: var(--text-faint); margin-left: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#viewport { position: absolute; inset: 0; overflow: hidden; cursor: grab; }
#viewport.panning { cursor: grabbing; }
#world { position: absolute; top: 0; left: 0; width: 4000px; height: 3000px; transform-origin: 0 0; }
#edge-layer { position: absolute; top: 0; left: 0; width: 4000px; height: 3000px; overflow: visible; pointer-events: none; }
/* node-layer itself must NOT capture pointer events, or every empty-space click on the
   canvas would hit this div instead of falling through to #world/#viewport (which is
   what enables pan-to-scroll and click-to-deselect on empty canvas). Individual .node
   elements opt back into pointer events below. */
#node-layer { position: absolute; top: 0; left: 0; width: 4000px; height: 3000px; pointer-events: none; }

#empty-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none; text-align: center; color: var(--text-faint);
}
#empty-hint.hidden { display: none; }
#empty-hint p { margin: 2px; }
.muted { color: var(--text-faint); font-size: 12px; }

/* ---------- Nodes ---------- */
.node {
  position: absolute;
  width: 168px;
  background: var(--bg-panel-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 10px;
  cursor: grab;
  user-select: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  transition: box-shadow 0.15s, border-color 0.15s;
  pointer-events: auto;
}
.node:active { cursor: grabbing; }
.node.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), 0 2px 8px rgba(0,0,0,0.4); }
.node.status-idle { border-left: 4px solid var(--c-idle); }
.node.status-healthy { border-left: 4px solid var(--c-healthy); }
.node.status-warning { border-left: 4px solid var(--c-warning); }
.node.status-critical { border-left: 4px solid var(--c-critical); }
.node.status-overloaded { border-left: 4px solid var(--c-overloaded); box-shadow: 0 0 0 2px rgba(239,68,68,0.35), 0 2px 8px rgba(0,0,0,0.4); animation: pulse-red 1.1s infinite; }
.node.status-throttled { border-left: 4px solid var(--c-throttled); }
.node.status-crashed { border-left: 4px solid var(--c-crashed); opacity: 0.55; filter: grayscale(0.6); }

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 2px rgba(239,68,68,0.35), 0 2px 8px rgba(0,0,0,0.4); }
  50% { box-shadow: 0 0 0 5px rgba(239,68,68,0.15), 0 2px 8px rgba(0,0,0,0.4); }
}

.node-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.node-title { font-size: 12.5px; font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-crash-btn {
  width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--border);
  background: transparent; color: var(--text-faint); cursor: pointer; font-size: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.node-crash-btn:hover { background: var(--c-crashed); color: white; border-color: var(--c-crashed); }
.node.status-crashed .node-crash-btn { background: var(--c-crashed); color: white; }

.node-stats { display: flex; flex-direction: column; gap: 2px; font-size: 10.5px; color: var(--text-dim); }
.node-stats .row { display: flex; justify-content: space-between; gap: 6px; }
.node-stats .stat-value { color: var(--text); font-variant-numeric: tabular-nums; }
.node-util-bar { height: 4px; border-radius: 2px; background: #0e1526; margin-top: 4px; overflow: hidden; }
.node-util-fill { height: 100%; background: var(--c-healthy); transition: width 0.2s, background 0.2s; }

.node-handle {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--bg-elevated); border: 2px solid var(--accent);
  cursor: crosshair; z-index: 3;
}
.node-handle.in { left: -7px; }
.node-handle.out { right: -7px; }
.node-handle:hover { background: var(--accent); }

.node-label-tag {
  position: absolute; top: -9px; left: 10px; background: var(--bg);
  padding: 0 4px; font-size: 9px; color: var(--text-faint); border-radius: 3px;
}

/* ---------- Edges ---------- */
.edge-path { fill: none; stroke: #45577f; stroke-width: 2; pointer-events: stroke; cursor: pointer; }
.edge-path.selected { stroke: var(--accent); stroke-width: 3; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.edge-particle { pointer-events: none; }
.edge-arrow { fill: #45577f; }

/* ---------- Side panel ---------- */
#side-panel {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#side-tabs { padding-top: 8px; }
.tab-panel { display: none; flex: 1; overflow-y: auto; padding: 14px; min-height: 0; }
.tab-panel.active { display: block; }

.field-group { margin-bottom: 14px; }
.field-group label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.field-group input, .field-group select { width: 100%; }
.inspector-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.inspector-header .badge { width: 32px; height: 32px; font-size: 9px; }
.inspector-title { font-weight: 700; font-size: 14px; }
.inspector-subtitle { color: var(--text-faint); font-size: 11px; }
.inspector-empty { color: var(--text-faint); text-align: center; padding: 40px 10px; font-size: 12.5px; }
.status-chip {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.03em; margin: 6px 0 14px;
}
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.metric-tile { background: var(--bg-panel-2); border: 1px solid var(--border-soft); border-radius: 6px; padding: 7px 9px; }
.metric-tile .m-label { font-size: 10px; color: var(--text-faint); }
.metric-tile .m-value { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.inspector-actions { display: flex; gap: 8px; margin-top: 6px; }
.inspector-actions .btn { flex: 1; }

/* ---------- Metrics tab ---------- */
.global-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.chart-block { margin-bottom: 16px; }
.chart-title { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; display:flex; justify-content: space-between; }
.chart-title b { color: var(--text); }
.sparkline { width: 100%; height: 46px; display: block; }
.node-metric-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--border-soft);
  font-size: 11.5px; cursor: pointer;
}
.node-metric-row:hover { background: var(--bg-panel-2); }
.node-metric-row .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.node-metric-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-metric-row .val { color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ---------- Legend ---------- */
.legend-item { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.legend-text b { display: block; font-size: 12px; }
.legend-text span { color: var(--text-faint); font-size: 11px; }

/* ---------- Status bar ---------- */
#statusbar {
  display: flex; gap: 18px; padding: 6px 14px;
  background: var(--bg-panel); border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-dim); flex-shrink: 0;
}
#statusbar span b { color: var(--text); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(6,10,20,0.7); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px 26px; max-width: 560px; max-height: 80vh; overflow-y: auto; }
.modal-card h2 { margin-top: 0; }
.modal-card code { background: var(--bg-panel-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- Toasts ---------- */
#toast-container { position: fixed; bottom: 40px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 14px; font-size: 12.5px; box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  animation: toast-in 0.15s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2c3958; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4a70; }

/* ---------- Toolbar group labels ---------- */
/* Labelled toolbar groups: caption in normal flow above a row of controls, so the
   labels can never overlap each other or the buttons regardless of wrapping. */
.toolbar-group[data-label] {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.toolbar-group[data-label]::before {
  content: attr(data-label);
  font-size: 8px; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
  padding-left: 2px;
  line-height: 1;
}
.tg-controls { display: flex; align-items: center; gap: 8px; }
.toolbar-group[data-label] + .toolbar-group[data-label] {
  border-left: 1px solid var(--border);
  padding-left: 16px;
}
.drawer-toggle { display: none; }

/* ---------- Zones (VPC / subnet / AZ containers) ---------- */
#zone-layer { position: absolute; top: 0; left: 0; width: 4000px; height: 3000px; pointer-events: none; }
.zone {
  position: absolute;
  border: 1.5px dashed var(--zone-color, #3b82f6);
  border-radius: 12px;
  background: color-mix(in srgb, var(--zone-color, #3b82f6) 7%, transparent);
  pointer-events: none;
}
.zone.selected { box-shadow: 0 0 0 2px var(--zone-color, #3b82f6); }
.zone-header {
  position: absolute; top: -13px; left: 12px;
  display: flex; align-items: center; gap: 6px;
  padding: 2px 8px 2px 3px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 10.5px; font-weight: 700; color: var(--text);
  cursor: grab; pointer-events: auto; user-select: none;
  max-width: 80%;
}
.zone-header:active { cursor: grabbing; }
.zone-badge .badge { width: 16px; height: 16px; border-width: 1px; }
.zone-badge .badge-svg { width: 11px; height: 11px; }
.zone-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zone-resize {
  position: absolute; right: -7px; bottom: -7px;
  width: 16px; height: 16px; border-radius: 4px;
  background: var(--bg-panel); border: 1.5px solid var(--zone-color, #3b82f6);
  cursor: nwse-resize; pointer-events: auto;
}

/* ---------- Text notes (diagram annotations) ---------- */
.note {
  position: absolute;
  background: #2a2a1c;
  border: 1px solid #5c5326;
  border-left: 3px solid #eab308;
  border-radius: 6px;
  padding: 7px 9px;
  pointer-events: auto;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  overflow: hidden;
}
.note:active { cursor: grabbing; }
.note.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), 0 2px 8px rgba(0,0,0,0.4); }
.note-body {
  font-size: 11.5px; line-height: 1.4; color: #f4e9c1;
  white-space: pre-wrap; word-break: break-word;
  width: 100%; height: 100%; overflow: auto;
  outline: none;
}
.note-body.editing { cursor: text; background: rgba(0,0,0,0.15); }
.note-resize {
  position: absolute; right: 0; bottom: 0;
  width: 14px; height: 14px;
  cursor: nwse-resize; pointer-events: auto;
  background: linear-gradient(135deg, transparent 50%, #5c5326 50%);
}

.node-title.editing {
  outline: 1px solid var(--accent); background: var(--bg-elevated);
  border-radius: 3px; cursor: text; padding: 0 2px;
}

/* ---------- Inspector: plain-language additions ---------- */
.inspector-blurb { font-size: 12px; color: var(--text-dim); margin: 8px 0 10px; line-height: 1.5; }
.why-box { margin-bottom: 12px; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--bg-panel-2); }
.why-box > summary {
  cursor: pointer; padding: 7px 10px; font-size: 11px; font-weight: 700; color: var(--text-dim);
  list-style: none;
}
.why-box > summary::-webkit-details-marker { display: none; }
.why-box > summary::before { content: '▸ '; color: var(--text-faint); }
.why-box[open] > summary::before { content: '▾ '; }
.why-box p { margin: 0 10px 8px; font-size: 11.5px; color: var(--text-dim); line-height: 1.5; }
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 11px; padding: 0 10px 8px; font-weight: 600;
}
.link-btn:hover { text-decoration: underline; }
.field-section-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); margin-bottom: 10px; }
.field-group label .field-term {
  display: block; font-size: 9.5px; color: var(--text-faint); font-weight: 400; margin-top: 1px;
}
.field-hint { font-size: 10px; color: var(--text-faint); margin-top: 4px; line-height: 1.4; }

/* ---------- Learn tab ---------- */
.learn-intro { font-size: 11.5px; color: var(--text-dim); line-height: 1.5; margin: 0 0 12px; }
.learn-entry { border-bottom: 1px solid var(--border-soft); }
.learn-entry > summary {
  cursor: pointer; padding: 9px 2px; font-size: 12px; font-weight: 600; color: var(--text);
  list-style: none;
}
.learn-entry > summary::-webkit-details-marker { display: none; }
.learn-entry > summary::before { content: '+ '; color: var(--text-faint); }
.learn-entry[open] > summary::before { content: '– '; }
.learn-body { padding: 0 2px 12px; }
.learn-body p { font-size: 11.5px; color: var(--text-dim); line-height: 1.55; margin: 0 0 8px; }
.learn-try { color: var(--text) !important; background: var(--bg-panel-2); border-left: 2px solid var(--accent); padding: 7px 9px; border-radius: 0 6px 6px 0; }

/* ---------- Template gallery ---------- */
.template-card-wrap { width: 720px; max-width: 92vw; }
.template-head { display: flex; align-items: center; justify-content: space-between; }
.template-head h2 { margin: 0; }
.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.template-item {
  text-align: left; background: var(--bg-panel-2); border: 1px solid var(--border-soft);
  border-radius: 10px; padding: 12px; cursor: pointer; color: var(--text); font: inherit;
}
.template-item:hover { border-color: var(--accent); background: var(--bg-elevated); }
.template-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.template-name { font-weight: 700; font-size: 13px; }
.diff-tag { font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 6px; border-radius: 20px; flex-shrink: 0; }
.diff-beginner { background: rgba(34,197,94,0.18); color: #4ade80; }
.diff-intermediate { background: rgba(234,179,8,0.18); color: #fde047; }
.diff-advanced { background: rgba(239,68,68,0.18); color: #f87171; }
.template-desc { font-size: 11px; color: var(--text-dim); line-height: 1.45; margin: 0 0 6px; }
.template-teaches { margin: 0 0 8px; padding-left: 16px; }
.template-teaches li { font-size: 10.5px; color: var(--text-faint); line-height: 1.4; }
.template-count { font-size: 10px; color: var(--text-faint); }

/* ---------- Welcome modal ---------- */
.welcome-card { max-width: 460px; }
.welcome-card p { line-height: 1.6; }
.welcome-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.welcome-actions .btn { width: 100%; padding: 10px; }
.help-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

/* ---------- Guided tour ---------- */
.tour-root { position: fixed; inset: 0; z-index: 80; pointer-events: none; }
.tour-root.hidden { display: none; }
.tour-spot {
  position: fixed; border-radius: 10px;
  box-shadow: 0 0 0 4px var(--accent), 0 0 0 9999px rgba(6,10,20,0.66);
  transition: all 0.25s ease; pointer-events: none;
}
.tour-pop {
  position: fixed; width: 320px; max-width: 92vw;
  background: var(--bg-panel); border: 1px solid var(--accent); border-radius: 12px;
  padding: 14px 16px; box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  pointer-events: auto; transition: left 0.25s ease, top 0.25s ease;
}
.tour-step { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.tour-pop h3 { margin: 4px 0 6px; font-size: 14px; }
.tour-pop p { margin: 0 0 12px; font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.tour-actions { display: flex; align-items: center; gap: 6px; }
.tour-actions .btn { padding: 5px 10px; }

/* ---------- Empty hint ---------- */
.empty-title { font-size: 16px; font-weight: 700; color: var(--text-dim); margin-bottom: 4px; }
.empty-actions { display: flex; gap: 8px; margin-top: 14px; pointer-events: auto; flex-wrap: wrap; justify-content: center; }

/* ---------- Mobile: FAB + drawers ---------- */
.fab {
  display: none;
  position: absolute; right: 16px; bottom: 16px; z-index: 20;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #06122b; border: none;
  font-size: 26px; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,0.45);
}
#drawer-scrim { position: fixed; inset: 0; background: rgba(6,10,20,0.5); z-index: 24; }

@media (pointer: coarse) {
  .node-handle { width: 18px; height: 18px; }
  .node-handle.in { left: -10px; }
  .node-handle.out { right: -10px; }
  .zone-resize { width: 22px; height: 22px; }
}

@media (max-width: 900px) {
  #toolbar { gap: 10px; padding: 8px 10px; }
  .toolbar-group[data-label] { flex-direction: row; align-items: center; gap: 8px; }
  .toolbar-group[data-label]::before { display: none; }
  .toolbar-group[data-label] + .toolbar-group[data-label] { border-left: none; padding-left: 0; }
  .brand-name { display: none; }
  #toolbar-design { display: none; }
  .drawer-toggle { display: flex; }
  .speed-label { font-size: 11px; }

  #palette, #side-panel {
    position: absolute; top: 0; bottom: 0; z-index: 25;
    width: 82vw; max-width: 340px;
    transition: transform 0.22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  #palette { left: 0; transform: translateX(-102%); }
  #side-panel { right: 0; transform: translateX(102%); }
  #palette.drawer-open, #side-panel.drawer-open { transform: translateX(0); }

  .fab { display: block; }
  .fab { bottom: calc(16px + env(safe-area-inset-bottom)); }

  #statusbar { gap: 10px 14px; flex-wrap: wrap; font-size: 10.5px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  #canvas-toolbar .hint { display: none; }
  .template-grid { grid-template-columns: 1fr; }
  .modal-card { padding: 18px; }
}
