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

:root {
  --bg: #141414;
  --surface: #1e1e1e;
  --surface2: #272727;
  --surface3: #303030;
  --border: #383838;
  --text: #e8e8e8;
  --text-muted: #888;
  --text-dim: #555;
  --accent: #6c63ff;
  --accent-hover: #7d75ff;
  --danger: #e05555;
  --node-w: 200px;
  --toolbar-h: 44px;
  --boardbar-h: 40px;
  --panel-w: 280px;
}

/* Light theme override */
:root[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface2: #f0f0f3;
  --surface3: #e5e5ea;
  --border: #d6d6db;
  --text: #1a1a1f;
  --text-muted: #6c6c72;
  --text-dim: #a0a0a8;
  --accent: #5b54e6;
  --accent-hover: #6e66ff;
  --danger: #d63838;
}

/* Light theme: darker grid lines so they show on light background */
:root[data-theme="light"] #canvas-container {
  --grid-color: rgba(0, 0, 0, 0.06);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}

/* ── TOOLBAR ── */
#toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--toolbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  gap: 8px;
}

.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 4px; }
.toolbar-center {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: .02em;
}

.tb-btn {
  width: 30px; height: 30px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.tb-btn:hover { background: var(--surface3); color: var(--text); }
.tb-btn svg { width: 16px; height: 16px; fill: currentColor; }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

/* ── LEFT PANEL ── */
#left-panel {
  position: fixed;
  left: 0; top: var(--toolbar-h);
  width: var(--panel-w);
  bottom: var(--boardbar-h);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 90;
  display: flex;
  flex-direction: column;
  transition: transform .2s;
}
#left-panel.hidden { transform: translateX(calc(-100% - 1px)); }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.panel-section { display: flex; flex-direction: column; gap: 6px; }
.panel-section label {
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.panel-section label .required { color: var(--accent); }
.panel-section label small { text-transform: none; letter-spacing: 0; font-size: 10px; color: var(--text-dim); }

.image-slot {
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 14px 12px;
  display: flex; flex-direction: column; gap: 4px;
  cursor: pointer;
  transition: border-color .15s;
  min-height: 72px;
  position: relative;
  overflow: hidden;
}
.image-slot:hover { border-color: var(--accent); }
.image-slot.filled { border-style: solid; border-color: var(--accent); padding: 0; }
.image-slot.filled img { width: 100%; height: 100px; object-fit: cover; border-radius: 7px; }
.image-slot span { font-size: 12px; font-weight: 500; }
.image-slot small { font-size: 10px; color: var(--text-dim); }
.slot-clear {
  position: absolute; top: 4px; right: 4px;
  width: 20px; height: 20px;
  background: rgba(0,0,0,.6);
  border: none; border-radius: 50%;
  color: #fff; font-size: 10px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ── CANVAS ── */
#canvas-container {
  position: fixed;
  top: var(--toolbar-h);
  left: 0; right: 0;
  bottom: var(--boardbar-h);
  overflow: hidden;
  cursor: grab;
  touch-action: none;          /* let our JS own all touch gestures */
  -webkit-user-select: none;
  user-select: none;
  --grid-size: 40px;
  --grid-color: rgba(255, 255, 255, 0.035);
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
  background-position: 0 0;
}
#canvas-container.panning { cursor: grabbing; }
#canvas-container.connecting { cursor: crosshair; }

#connections-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

#canvas {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  z-index: 2;
}

/* ── NODE ── */
.node {
  position: absolute;
  width: var(--node-w);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: default;
  transition: border-color .15s, box-shadow .15s;
  overflow: visible;
}
.node:hover { border-color: #555; }
.node.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(108,99,255,.25); }
.node.generating { border-color: var(--accent); animation: pulse-border 1.5s infinite; }

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 2px rgba(108,99,255,.1); }
  50% { box-shadow: 0 0 0 4px rgba(108,99,255,.35); }
}

.node-header {
  padding: 7px 10px 5px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--text-muted);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: move;
}

.node-media {
  width: 100%;
  aspect-ratio: 1;
  background: var(--surface3);
  overflow: hidden;
  position: relative;
}
.node-media img, .node-media video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.node-media .placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: var(--text-dim);
}
.node-media .placeholder svg { width: 32px; height: 32px; fill: currentColor; }
.node-media .placeholder span { font-size: 11px; }

.node-spinner {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  gap: 8px;
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.node-spinner span { font-size: 11px; color: var(--text-muted); }

.node-error {
  position: absolute; inset: 0;
  background: rgba(80,20,20,.85);
  color: #ffb4b4;
  font-size: 10px;
  padding: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  text-align: center;
  overflow: hidden;
  word-break: break-word;
}
.node-retry-btn {
  background: rgba(108, 99, 255, .25);
  color: #c4c0ff;
  border: 1px solid rgba(108, 99, 255, .55);
  padding: 5px 12px;
  font-size: 10px;
  border-radius: 5px;
  cursor: pointer;
}
.node-retry-btn:hover { background: rgba(108, 99, 255, .4); }
.node-key-badge {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(0,0,0,.6);
  color: #aaa;
  font-size: 9px;
  font-family: monospace;
  padding: 2px 5px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 5;
}

.node-prompt {
  padding: 7px 10px 8px;
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: text;
  min-height: 42px;
}
.node-prompt:empty::before { content: 'Click to edit prompt…'; color: var(--text-dim); }
.node-prompt.editing {
  display: block;
  outline: none;
  -webkit-line-clamp: unset;
  border-top: 1px solid var(--border);
  background: var(--surface3);
  border-radius: 0 0 9px 9px;
}

/* Connect dots */
.node-dot {
  position: absolute;
  width: 10px; height: 10px;
  background: var(--surface3);
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: crosshair;
  transition: border-color .15s, background .15s;
  z-index: 5;
}
.node-dot:hover, .node-dot.active { border-color: var(--accent); background: var(--accent); }
.node-dot.output { right: -6px; top: 50%; transform: translateY(-50%); }
.node-dot.input  { left: -6px;  top: 50%; transform: translateY(-50%); }

/* Node action bar (on hover) */
.node-actions {
  position: absolute;
  bottom: -30px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
  white-space: nowrap;
  z-index: 10;
}
.node:hover .node-actions,
.node.selected .node-actions { opacity: 1; pointer-events: all; }

.node-act-btn {
  height: 22px; padding: 0 8px;
  background: transparent;
  border: none; border-radius: 5px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  transition: background .15s, color .15s;
}
.node-act-btn:hover { background: var(--surface3); color: var(--text); }
.node-act-btn svg { width: 11px; height: 11px; fill: currentColor; }

/* Connection path */
.connection-path {
  fill: none;
  stroke: rgba(180,180,180,.35);
  stroke-width: 1.5;
  pointer-events: none;
}
.connection-path.active { stroke: rgba(108,99,255,.6); stroke-width: 2; }
.connection-draft { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; pointer-events: none; }

/* ── BOARD BAR ── */
#board-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--boardbar-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 8px 0 12px;
  gap: 6px;
  z-index: 100;
  overflow-x: auto;
}
#board-bar::-webkit-scrollbar { height: 0; }
#boards-list { display: flex; gap: 4px; align-items: center; }
.bar-spacer { flex: 1; }

.model-picker-btn {
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, color .15s, background .15s;
  flex-shrink: 0;
}
.model-picker-btn:hover { border-color: var(--accent); color: var(--text); background: var(--surface3); }
.model-picker-btn svg { width: 13px; height: 13px; fill: currentColor; }
.model-picker-btn .chevron { opacity: .5; }

.board-tab {
  height: 26px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.board-tab:hover { background: var(--surface2); color: var(--text); }
.board-tab.active { background: var(--surface3); border-color: var(--border); color: var(--text); }
.board-tab .tab-del {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: transparent;
  border: none; color: var(--text-dim);
  font-size: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity .15s, background .15s;
}
.board-tab:hover .tab-del { opacity: 1; }
.board-tab .tab-del:hover { background: var(--danger); color: #fff; }

.add-board-btn {
  height: 26px; padding: 0 10px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, color .15s;
}
.add-board-btn:hover { border-color: var(--accent); color: var(--text); }

/* ── MODALS ── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50000;
  backdrop-filter: blur(4px);
}
.modal a { color: var(--accent, #6c63ff); text-decoration: none; }
.modal a:hover { text-decoration: underline; }
.modal.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 580px;
  max-width: 94vw;
  max-height: 85vh;
  display: flex; flex-direction: column;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-body {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.modal-footer {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: center;
  align-items: center; flex-wrap: nowrap;
}
.modal-footer button { white-space: nowrap; }

.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 11px; font-weight: 500; color: var(--text-muted); letter-spacing: .04em; text-transform: uppercase; }
.form-row small { font-size: 10px; color: var(--text-dim); text-transform: none; letter-spacing: 0; }

input[type="text"], input[type="password"], textarea, select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  transition: border-color .15s;
  width: 100%;
  font-family: inherit;
  resize: vertical;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
select option { background: var(--surface2); }

.generate-btn {
  height: 36px; padding: 0 18px;
  background: var(--accent);
  border: none; border-radius: 8px;
  color: #fff; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.generate-btn:hover { background: var(--accent-hover); }
.generate-btn:disabled { opacity: .5; cursor: not-allowed; }

.cancel-btn {
  height: 36px; padding: 0 18px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted); font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.cancel-btn:hover { background: var(--surface2); color: var(--text); }

.close-btn {
  width: 26px; height: 26px;
  background: transparent;
  border: none; border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.close-btn:hover { background: var(--surface3); color: var(--text); }

/* ── CONTEXT MENU ── */
#ctx-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  z-index: 300;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
#ctx-menu.hidden { display: none; }

.ctx-item {
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  transition: background .12s, color .12s;
}
.ctx-item:hover { background: var(--surface3); color: var(--text); }
.ctx-item.danger:hover { background: rgba(224,85,85,.15); color: var(--danger); }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ── PROMPT PREVIEW ── */
#prompt-preview {
  position: fixed;
  right: 16px; bottom: calc(var(--boardbar-h) + 16px);
  width: 320px;
  max-height: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  overflow-y: auto;
  z-index: 95;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-muted);
}
#prompt-preview.hidden { display: none; }
#prompt-preview .close-btn { position: absolute; top: 8px; right: 8px; }

.ref-images-list {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.ref-thumb {
  width: 56px; height: 56px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
}

/* ── TOASTS ── */
#toast-container {
  position: fixed;
  bottom: calc(var(--boardbar-h) + 16px);
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px;
  z-index: 400;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text);
  animation: toast-in .2s ease;
  white-space: nowrap;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: #4caf6e; color: #4caf6e; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── MODEL PICKER PANEL ── */
#model-picker-panel {
  position: fixed;
  left: 0; right: 0;
  bottom: var(--boardbar-h);
  height: 340px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 110;
  display: flex; flex-direction: column;
  animation: slide-up .2s ease;
}
#model-picker-panel.hidden { display: none; }

@keyframes slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.mp-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mp-title { font-size: 13px; font-weight: 600; color: var(--text); margin-right: 4px; }
.mp-tabs  { display: flex; gap: 2px; }
.mp-tab {
  height: 26px; padding: 0 12px;
  background: transparent;
  border: none; border-radius: 6px;
  color: var(--text-dim); font-size: 12px;
  cursor: pointer; transition: background .12s, color .12s;
}
.mp-tab:hover  { background: var(--surface2); color: var(--text-muted); }
.mp-tab.active { background: var(--surface3); color: var(--text); }

.mp-search-wrap {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.mp-search {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  transition: border-color .15s;
}
.mp-search:focus { border-color: var(--accent, #6366f1); }
.mp-search::placeholder { color: var(--text-dim); }

.mp-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.mp-body {
  flex: 1; overflow-y: auto;
  padding: 12px 16px 16px;
}
.mp-body::-webkit-scrollbar { width: 4px; }
.mp-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.mp-section { margin-bottom: 20px; }
.mp-section-title {
  font-size: 10px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.mp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px;
}

.mp-card {
  position: relative;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; gap: 3px;
}
.mp-card-fav {
  position: absolute; top: 6px; right: 8px;
  background: transparent; border: none; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 2px 4px;
  color: var(--text-dim); border-radius: 3px;
  opacity: 0; transition: opacity .12s, color .12s, background .12s;
}
.mp-card:hover .mp-card-fav { opacity: 1; }
.mp-card-fav:hover { background: var(--surface3); color: var(--text); }
.mp-card-fav.active { color: #f5b840; opacity: 1; }
.mp-card:hover  { border-color: #555; background: var(--surface3); }
.mp-card.active { border-color: var(--accent); background: rgba(108,99,255,.08); }

.mp-card-provider { font-size: 9px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-dim); }
.mp-card-name     { font-size: 12px; font-weight: 600; color: var(--text); }
.mp-card-desc     { font-size: 10px; color: var(--text-muted); margin-bottom: 4px; }
.mp-card-tags     { display: flex; flex-wrap: wrap; gap: 3px; }

.tag {
  height: 16px; padding: 0 6px;
  border-radius: 3px;
  font-size: 9px; font-weight: 600; letter-spacing: .04em;
  display: flex; align-items: center;
}
.tag-purple { background: rgba(108,99,255,.2); color: #a89eff; }
.tag-green  { background: rgba(76,175,110,.2); color: #6fcf89; }
.tag-blue   { background: rgba(64,156,255,.2); color: #7ab8ff; }
.tag-orange { background: rgba(255,160,64,.2); color: #ffc07a; }
.tag-pink   { background: rgba(255,100,180,.2); color: #ff8ed4; }
.tag-gray   { background: rgba(255,255,255,.08); color: var(--text-dim); }

/* ── SETTINGS extras ── */
.modal-box-wide { width: 640px; }
.settings-divider {
  font-size: 10px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-dim);
  padding: 4px 0 2px;
  border-bottom: 1px solid var(--border);
  margin-top: 4px;
  display: flex; align-items: center; gap: 8px;
}
.key-badge {
  font-size: 9px; font-weight: 600; letter-spacing: .04em;
  padding: 1px 6px; border-radius: 3px;
  text-transform: none;
}
.video-badge { background: rgba(108,99,255,.2); color: #a89eff; }
.img-badge   { background: rgba(76,175,110,.2);  color: #6fcf89; }

#key-pool-status {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 4px;
}
.key-pill {
  height: 20px; padding: 0 8px;
  border-radius: 10px; font-size: 10px;
  display: flex; align-items: center; gap: 4px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.key-pill.active  { border-color: #4caf6e; color: #4caf6e; }
.key-pill.spent   { border-color: var(--danger); color: var(--danger); opacity: .6; }

/* ── FRAME SLOTS (start/end) ── */
.frames-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-bottom: 4px;
}
.frame-col { display: flex; flex-direction: column; gap: 5px; }
.frame-col label { font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.frame-col label small { text-transform: none; letter-spacing: 0; font-size: 9px; color: var(--text-dim); }
.frame-slot {
  height: 90px;
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; overflow: hidden;
  font-size: 10px; color: var(--text-dim);
  transition: border-color .15s;
}
.frame-slot:hover { border-color: var(--accent); }
.frame-slot.drag-over { border-color: var(--accent); background: rgba(108,99,255,.08); }
.frame-slot-clear {
  position: absolute; top: 4px; right: 4px;
  width: 18px; height: 18px;
  background: rgba(0,0,0,.6); border: none; border-radius: 50%;
  color: #fff; font-size: 9px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ── REF DROP ZONE ── */
.ref-drop-zone {
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer; min-height: 56px;
  transition: border-color .15s, background .15s;
}
.ref-drop-zone:hover, .ref-drop-zone.drag-over {
  border-color: var(--accent); background: rgba(108,99,255,.06);
}
.rdz-hint {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-dim); font-size: 11px; padding: 4px 2px;
}
.ref-thumbs {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.ref-thumb-wrap {
  position: relative; width: 56px; height: 56px;
}
.ref-thumb {
  width: 56px; height: 56px;
  object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}
.ref-thumb-del {
  position: absolute; top: -4px; right: -4px;
  width: 16px; height: 16px;
  background: var(--danger); border: none; border-radius: 50%;
  color: #fff; font-size: 9px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}

/* ── MULTI-SHOT ── */
.multishot-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0 4px;
  border-top: 1px solid var(--border);
  margin-top: 2px;
}
.multishot-label { font-size: 11px; font-weight: 600; color: var(--text-muted); letter-spacing: .04em; text-transform: uppercase; }

.toggle-switch { display: inline-flex; align-items: center; cursor: pointer; }
.toggle-switch input { display: none; }
.toggle-track {
  width: 36px; height: 20px;
  background: var(--surface3);
  border-radius: 10px; position: relative;
  transition: background .2s;
  border: 1px solid var(--border);
}
.toggle-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: var(--text-dim); border-radius: 50%;
  transition: left .2s, background .2s;
}
.toggle-switch input:checked ~ .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-switch input:checked ~ .toggle-track .toggle-thumb { left: 18px; background: #fff; }

.shot-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
  margin-bottom: 6px;
}
.shot-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
}
.shot-del {
  background: transparent; border: none;
  color: var(--text-dim); cursor: pointer; font-size: 12px;
  transition: color .15s;
}
.shot-del:hover { color: var(--danger); }
.shot-prompt {
  width: 100%; background: var(--surface3);
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 12px; padding: 6px 8px;
  resize: none; outline: none; font-family: inherit;
  transition: border-color .15s;
}
.shot-prompt:focus { border-color: var(--accent); }
.shot-footer {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
  font-size: 11px; color: var(--text-dim);
}
.shot-dur {
  height: 24px; padding: 0 6px; font-size: 11px;
  background: var(--surface3); border: 1px solid var(--border);
  border-radius: 5px; color: var(--text); outline: none;
}
.add-shot-btn {
  width: 100%; height: 30px;
  background: transparent; border: 1px dashed var(--border);
  border-radius: 6px; color: var(--text-dim); font-size: 12px;
  cursor: pointer; transition: border-color .15s, color .15s;
  margin-top: 4px;
}
.add-shot-btn:hover { border-color: var(--accent); color: var(--text); }

/* ── MISC ── */
.hidden { display: none !important; }

/* ── MINI-MAP ── */
#minimap {
  position: absolute;
  right: 14px;
  bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 50;
  cursor: pointer;
  opacity: .85;
  transition: opacity .15s;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
#minimap:hover { opacity: 1; }
#minimap.hidden { display: none; }

/* ── VARIANTS PICKER ── */
.variants-picker { display: flex; gap: 6px; margin-top: 4px; }
.variant-btn {
  padding: 6px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all .15s;
}
.variant-btn:hover { color: var(--text); }
.variant-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ── HOVER MEDIA PREVIEW ── */
#hover-preview {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  max-width: 360px;
  max-height: 360px;
  overflow: hidden;
}
#hover-preview img, #hover-preview video {
  display: block;
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 6px;
}

/* ── GEN TIMER ── */
.node-timer {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-weight: 600;
  pointer-events: none;
}

/* ── TEMPLATES ── */
.templates-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 240px; overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  background: var(--surface2);
}
.templates-list:empty::after {
  content: "No saved templates yet";
  color: var(--text-dim);
  font-size: 12px;
  padding: 12px;
  text-align: center;
  display: block;
}
.tpl-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
}
.tpl-item .tpl-name { font-weight: 600; }
.tpl-item .tpl-body {
  color: var(--text-muted); font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 240px; margin-left: 12px; flex: 1;
}
.tpl-item button {
  background: var(--surface3); border: 1px solid var(--border);
  color: var(--text); padding: 4px 9px; border-radius: 4px;
  cursor: pointer; font-size: 11px; margin-left: 6px;
}
.tpl-item button.danger { color: var(--danger); }
.tpl-item button:hover { background: var(--accent); border-color: var(--accent); color: white; }

/* ── BATCH GROUP visual ── */
.node.batch-group { box-shadow: 0 0 0 2px rgba(108,99,255,.4); }

/* ── MARQUEE box-select ── */
.marquee-box {
  position: absolute;
  border: 1.5px dashed var(--accent, #6c63ff);
  background: rgba(108, 99, 255, 0.08);
  pointer-events: none;
  z-index: 9999;
  border-radius: 2px;
}

/* ═══════════ AUTH OVERLAY ═══════════ */
#auth-overlay {
  position: fixed; inset: 0; z-index: 100000;
  background: rgba(10, 10, 18, 0.92);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
}
#auth-overlay.hidden { display: none; }
.auth-card {
  width: 380px; max-width: 92vw;
  background: var(--bg, #1a1a24);
  border: 1px solid var(--border, #2a2a3a);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-logo-img {
  display: block;
  width: 180px; height: 180px;
  object-fit: contain;
  margin: 0 auto 10px;
  background: transparent;
  border-radius: 0;
  user-select: none; -webkit-user-drag: none;
  filter: drop-shadow(0 8px 24px rgba(124, 77, 255, 0.25));
}
.auth-tag  { font-size: 13px; color: var(--text-dim, #888); margin-top: 4px; }
@media (max-width: 768px) {
  .auth-logo-img { width: 140px; height: 140px; }
}
.auth-tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border, #2a2a3a);
  margin-bottom: 18px;
}
.auth-tab {
  flex: 1; padding: 10px; background: transparent; border: none;
  color: var(--text-dim, #888); cursor: pointer;
  font-size: 14px; border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.auth-tab.active { color: var(--text, #e8e8e8); border-bottom-color: var(--accent, #6c63ff); }
.auth-tab.hidden { display: none; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form.hidden { display: none; }
.auth-form label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; color: var(--text-dim, #888);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.auth-form input {
  background: var(--bg-2, #14141c);
  border: 1px solid var(--border, #2a2a3a);
  color: var(--text, #e8e8e8);
  padding: 10px 12px; border-radius: 8px;
  font-size: 14px; outline: none;
  transition: border-color 0.15s;
}
.auth-form input:focus { border-color: var(--accent, #6c63ff); }
.auth-submit {
  margin-top: 8px; padding: 11px;
  background: var(--accent, #6c63ff); color: white;
  border: none; border-radius: 8px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: opacity 0.15s;
}
.auth-submit:hover { opacity: 0.9; }
.auth-submit:disabled { opacity: 0.5; cursor: wait; }
.auth-error {
  padding: 10px 12px; margin-bottom: 14px;
  background: rgba(224, 85, 85, 0.12);
  border: 1px solid rgba(224, 85, 85, 0.3);
  border-radius: 6px;
  color: var(--danger, #e05555);
  font-size: 13px;
}
.auth-error.hidden { display: none; }
.auth-google {
  margin-top: 12px; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 10px; background: var(--bg-2, #14141c);
  border: 1px solid var(--border, #2a2a3a); color: var(--text, #e8e8e8);
  border-radius: 8px; cursor: pointer; font-size: 14px;
}
.auth-google:hover { border-color: var(--accent, #6c63ff); }
.auth-google.hidden { display: none; }

/* ═══════════ ACCOUNT BADGE ═══════════ */
#account-badge {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-2, #14141c);
  border: 1px solid var(--border, #2a2a3a);
  border-radius: 14px;
  padding: 3px 6px 3px 10px;
  font-size: 11px; color: var(--text-dim, #888);
  margin-right: 6px;
}
#account-badge #account-email {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px;
}
#account-badge.hidden { display: none; }
#account-badge button {
  background: transparent; border: none; color: var(--text-dim, #888);
  cursor: pointer; font-size: 14px; padding: 2px 6px; border-radius: 10px;
}
#account-badge button:hover { background: var(--danger, #e05555); color: white; }

/* ═══════════ SEARCH MODAL (Ctrl+K) ═══════════ */
#search-modal {
  position: fixed; inset: 0; z-index: 9998;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 15vh;
}
#search-modal.hidden { display: none; }
.search-card {
  width: 560px; max-width: 92vw;
  background: var(--bg, #1a1a24);
  border: 1px solid var(--border, #2a2a3a);
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
#search-input {
  width: 100%; padding: 16px 20px;
  background: transparent; border: none;
  border-bottom: 1px solid var(--border, #2a2a3a);
  color: var(--text, #e8e8e8); font-size: 15px;
  outline: none;
}
#search-results { max-height: 50vh; overflow-y: auto; }
.search-result {
  padding: 10px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border, #2a2a3a);
  display: flex; flex-direction: column; gap: 3px;
}
.search-result:hover, .search-result.active {
  background: rgba(108, 99, 255, 0.12);
}
.search-result .sr-title  { color: var(--text, #e8e8e8); font-size: 13px; }
.search-result .sr-meta   { color: var(--text-dim, #888); font-size: 11px; }
.search-hint {
  padding: 8px 16px; font-size: 11px;
  color: var(--text-dim, #888);
  background: var(--bg-2, #14141c);
}

/* ═══════════ DEMO MODE (P toggle) ═══════════ */
body.demo-mode #toolbar,
body.demo-mode #board-bar,
body.demo-mode #minimap,
body.demo-mode #account-badge {
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
body.demo-mode #canvas-container {
  inset: 0 !important;
}

/* ═══════════ COST ESTIMATE ═══════════ */
.cost-estimate {
  padding: 6px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 500;
  background: rgba(108, 99, 255, 0.08);
  color: var(--accent, #6c63ff);
  border: 1px solid rgba(108, 99, 255, 0.2);
  white-space: nowrap;
  user-select: none;
}
.cost-estimate.unknown {
  background: rgba(120, 120, 130, 0.08);
  color: var(--text-dim, #888);
  border-color: rgba(120, 120, 130, 0.2);
}
.cost-estimate.high {
  background: rgba(255, 165, 0, 0.10);
  color: #f0a040;
  border-color: rgba(255, 165, 0, 0.25);
}

/* ═══════════ MODEL SELECT + FAVORITE BUTTON ═══════════ */
.model-select-wrap { display: flex; gap: 6px; align-items: center; }
.model-select-wrap select { flex: 1; }
.fav-btn {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
  padding: 8px 12px; border-radius: 6px;
  font-size: 16px; line-height: 1; transition: all 0.15s;
}
.fav-btn:hover { color: var(--accent); border-color: var(--accent); }
.fav-btn.active { color: #f5b840; border-color: #f5b840; background: rgba(245, 184, 64, 0.08); }

/* ═══════════ INSPIRATION MODAL ═══════════ */
.insp-tabs {
  display: flex; gap: 4px; padding: 8px 16px 0;
  overflow-x: auto; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.insp-tabs::-webkit-scrollbar { height: 4px; }
.insp-tabs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.insp-tab {
  padding: 8px 14px; background: transparent; border: none;
  color: var(--text-dim); cursor: pointer; font-size: 13px;
  border-bottom: 2px solid transparent; white-space: nowrap;
  transition: all 0.15s;
}
.insp-tab:hover { color: var(--text); }
.insp-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.insp-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px; padding: 16px; overflow-y: auto; flex: 1;
}
.insp-grid::-webkit-scrollbar { width: 6px; }
.insp-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.insp-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
  transition: transform 0.15s, border-color 0.15s;
  display: flex; flex-direction: column; gap: 8px; padding: 10px;
}
.insp-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.insp-card-prompt {
  font-size: 11px; color: var(--text); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
  overflow: hidden;
}
.insp-card-media-row {
  display: grid; grid-template-columns: 1fr; gap: 6px;
}
.insp-card-media-row:has(.insp-media-slot + .insp-media-slot) {
  grid-template-columns: 1fr 1fr;
}
.insp-media-slot {
  display: flex; flex-direction: column; gap: 4px;
}
.insp-media-label {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim);
}
.insp-media-slot img, .insp-media-slot video {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  background: var(--surface3); border-radius: 6px; display: block;
}
.insp-media-empty {
  width: 100%; aspect-ratio: 1; background: var(--surface3);
  border-radius: 6px; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 18px;
}
.insp-card-actions { display: flex; gap: 6px; margin-top: auto; }
.insp-card-actions button {
  flex: 1; font-size: 10px; padding: 5px 8px;
  background: var(--surface3); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer; transition: all 0.15s;
}
.insp-card-actions button:hover { background: var(--accent); color: white; border-color: var(--accent); }
.insp-empty {
  grid-column: 1 / -1; text-align: center; color: var(--text-dim);
  padding: 60px 20px; font-size: 13px;
}
.insp-add-btn {
  margin-left: auto; color: var(--accent) !important;
  border: 1px dashed var(--accent) !important;
  border-radius: 6px !important; padding: 6px 10px !important;
}
.insp-add-form {
  position: absolute; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  border-radius: 14px; z-index: 5;
}
.insp-add-card {
  width: 480px; max-width: 92%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
  max-height: 90%; overflow-y: auto;
}
.insp-add-card h4 { margin: 0 0 4px; font-size: 14px; }
.insp-add-card label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em;
}
.insp-add-card label small { text-transform: none; color: var(--text-dim); letter-spacing: 0; }
.insp-add-card input, .insp-add-card textarea, .insp-add-card select {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 8px 10px; border-radius: 6px;
  font-size: 12px; outline: none; font-family: inherit;
}
.insp-add-card textarea { resize: vertical; min-height: 60px; }
.insp-f-status { font-size: 11px; color: var(--text-dim); min-height: 14px; }
.insp-add-actions { display: flex; gap: 8px; justify-content: flex-end; }
.insp-f-group {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 6px; margin: 0;
}
.insp-f-group legend {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim); padding: 0 4px;
}
#inspiration-modal .modal-box { position: relative; }

/* ═══════════ COMMENT NODE ═══════════ */
.node.comment-node {
  background: rgba(255, 220, 100, 0.1);
  border: 1px dashed rgba(255, 220, 100, 0.4);
}
.node.comment-node .node-header { display: none; }
.node.comment-node .node-media,
.node.comment-node .node-actions,
.node.comment-node .node-dot { display: none; }
.node.comment-node .node-prompt {
  font-size: 14px; padding: 14px;
  color: #f0e0a0; min-height: 60px;
  white-space: pre-wrap;
}

/* Mobile-only buttons hidden on desktop */
.mobile-only { display: none !important; }

/* ═══════════════════════════════════════════════════
   BALANCE BADGE — toolbar
   ═══════════════════════════════════════════════════ */
.balance-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, rgba(124,77,255,0.15), rgba(179,136,255,0.10));
  border: 1px solid rgba(124,77,255,0.35);
  color: var(--text, #eee);
  padding: 4px 8px 4px 10px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.12s, border-color 0.12s;
  margin-right: 4px;
  height: 32px;
}
.balance-badge:hover {
  background: linear-gradient(135deg, rgba(124,77,255,0.25), rgba(179,136,255,0.18));
  border-color: rgba(124,77,255,0.55);
}
.balance-badge svg { opacity: 0.85; }
.balance-badge .balance-plus {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
  background: rgba(124,77,255,0.5);
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  margin-left: 2px;
}
@media (max-width: 768px) {
  .balance-badge { font-size: 11px; padding: 3px 6px 3px 8px; height: 30px; }
  .balance-badge svg { display: none; }
}

/* ═══════════════════════════════════════════════════
   TOP UP MODAL
   ═══════════════════════════════════════════════════ */
/* Stronger backdrop overrides the default .modal opacity */
#topup-modal,
#history-modal {
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.topup-box {
  max-width: 460px;
  background: #1d1d1d;             /* fully opaque */
  border: 1px solid rgba(255,255,255,0.10);
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.topup-body { padding: 16px 20px 20px; }
.topup-current {
  font-size: 13px; color: var(--text-dim, #888);
  text-align: center;
  margin-bottom: 18px;
}
.topup-current b { color: var(--text, #eee); font-size: 18px; }
.topup-amounts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.topup-amount {
  background: #242424;
  border: 1px solid rgba(255,255,255,0.10);
  color: var(--text, #eee);
  padding: 14px 8px;
  border-radius: 10px;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.topup-amount:hover {
  background: rgba(124,77,255,0.18);
  border-color: rgba(124,77,255,0.50);
}
.topup-amount.active {
  background: linear-gradient(135deg, rgba(124,77,255,0.30), rgba(179,136,255,0.22));
  border-color: rgba(124,77,255,0.75);
}
.topup-amount:active { transform: scale(0.97); }
.topup-amount .bonus {
  display: block;
  font-size: 10px; font-weight: 500;
  color: #57e58c; margin-top: 2px;
}
.topup-amount-vip {
  background: linear-gradient(135deg, rgba(255,200,80,0.15), rgba(255,160,40,0.10));
  border-color: rgba(255,200,80,0.45);
}
.topup-amount-vip .bonus { color: #ffd56b; }
.topup-amount-vip:hover {
  background: linear-gradient(135deg, rgba(255,200,80,0.25), rgba(255,160,40,0.18));
  border-color: rgba(255,200,80,0.7);
}

.topup-custom { margin-bottom: 14px; }
.topup-custom input {
  width: 100%;
  background: #242424;
  border: 1px solid rgba(255,255,255,0.10);
  color: var(--text, #eee);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
}
.topup-custom input:focus { border-color: rgba(124,77,255,0.55); }

.topup-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim, #888);
  margin: 4px 0 8px;
}

.topup-methods {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 16px;
}
.topup-method {
  text-align: left;
  background: #242424;
  border: 1px solid rgba(255,255,255,0.10);
  color: var(--text, #eee);
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.topup-method:hover:not(.topup-method-disabled) {
  background: rgba(124,77,255,0.10);
  border-color: rgba(124,77,255,0.40);
}
.topup-method.active {
  background: linear-gradient(135deg, rgba(124,77,255,0.22), rgba(179,136,255,0.14));
  border-color: rgba(124,77,255,0.75);
}
.topup-method-title {
  font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.topup-method-sub {
  font-size: 12px; color: var(--text-dim, #888);
  margin-top: 3px;
}
.topup-method-badge {
  display: inline-block;
  font-size: 10px; font-weight: 600;
  background: rgba(87,229,140,0.18);
  color: #57e58c;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.02em;
}
.topup-method-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.topup-summary {
  background: #1a1a1a;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.topup-summary-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px;
  color: var(--text-dim, #aaa);
  padding: 3px 0;
}
.topup-summary-row b { color: var(--text, #eee); font-weight: 600; }
.topup-summary-final {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px dashed rgba(255,255,255,0.10);
  font-size: 14px;
}
.topup-summary-final b { font-size: 18px; color: #b388ff; }
.topup-summary-rate {
  font-size: 11px;
  color: var(--text-dim, #777);
  margin-top: 8px;
  text-align: right;
}

.topup-pay-btn {
  width: 100%;
  background: linear-gradient(135deg, #7c4dff 0%, #6c3ff7 100%);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.12s, opacity 0.12s;
  box-shadow: 0 4px 14px rgba(124,77,255,0.35);
}
.topup-pay-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(124,77,255,0.5); }
.topup-pay-btn:active { transform: translateY(0); }
.topup-pay-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.topup-error {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(255,90,90,0.12);
  border: 1px solid rgba(255,90,90,0.35);
  border-radius: 8px;
  color: #ff8a8a;
  font-size: 13px;
}

/* ═══════════════════════════════════════════════════
   HISTORY MODAL
   ═══════════════════════════════════════════════════ */
.history-box { max-width: 560px; }
.history-body { padding: 16px 20px 20px; }
.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-empty {
  text-align: center;
  color: var(--text-dim, #888);
  padding: 40px 20px;
  font-size: 13px;
}
.history-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface-2, #1a1a1a);
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  border-radius: 8px;
  font-size: 13px;
}
.history-row .h-meta { display: flex; flex-direction: column; gap: 2px; }
.history-row .h-time { font-size: 11px; color: var(--text-dim, #888); }
.history-row .h-amt.spend { color: #ff8a8a; }
.history-row .h-amt.topup { color: #57e58c; font-weight: 600; }

/* Account popover balance row */
.acct-pop-balance {
  font-size: 12px;
  color: var(--text-dim, #aaa);
  padding: 6px 8px 8px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,0.08));
  margin-bottom: 6px;
}
.acct-pop-balance b { color: var(--text, #eee); }

/* ═══════════════════════════════════════════════════
   SETTINGS HOSTED-MODE INFO CARD
   ═══════════════════════════════════════════════════ */
.settings-info-card {
  background: linear-gradient(135deg, rgba(124,77,255,0.08), rgba(179,136,255,0.04));
  border: 1px solid rgba(124,77,255,0.25);
  border-radius: 14px;
  padding: 18px 18px 16px;
}
.settings-info-card h4 {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--text, #eee);
}
.settings-info-card p {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-dim, #aaa);
  line-height: 1.5;
}
.settings-pricelist-mini {
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 4px;
}
.settings-pricelist-mini div {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px;
  color: var(--text-dim, #bbb);
  padding: 4px 0;
}
.settings-pricelist-mini b { color: var(--text, #eee); }

/* ═══════════════════════════════════════════════════
   MOBILE — phones (≤768px)
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root {
    --toolbar-h: 52px;
    --boardbar-h: 56px;
    --node-w: 240px;
  }

  body { -webkit-text-size-adjust: 100%; }

  /* Show mobile-only buttons */
  .mobile-only { display: inline-flex !important; }

  /* ── TOOLBAR: clean — only essentials ── */
  #toolbar {
    padding: 0 10px;
    padding-top: env(safe-area-inset-top, 0);
    height: calc(var(--toolbar-h) + env(safe-area-inset-top, 0));
    gap: 6px;
    overflow: hidden;
    justify-content: space-between;
  }
  .toolbar-left {
    flex: 0 0 auto;
    gap: 4px;
    flex-wrap: nowrap;
    overflow: visible;
  }
  .toolbar-center { display: none; }
  .toolbar-right { gap: 4px; flex-shrink: 0; flex-wrap: nowrap; }
  .tb-btn { width: 38px; height: 38px; flex-shrink: 0; padding: 0; }
  .tb-btn svg { width: 18px; height: 18px; }
  .tb-sep { display: none; }

  /* Hide non-essential buttons on mobile — they live in the More popover.
     KEPT in toolbar:
       Left:  undo, redo, upload, fit
       Right: inspiration, zoom-out, zoom-in, more, account, settings */
  #btn-export,
  #btn-export-json,
  #btn-import-json,
  #btn-tidy,
  #btn-search,
  #btn-comment,
  #btn-templates,
  #btn-theme,
  #btn-help { display: none !important; }

  /* Old wide account badge — hide on mobile, replaced by btn-account */
  #account-badge { display: none !important; }

  /* Compact icons so 10 buttons fit on a 360px screen */
  .tb-btn { width: 34px; height: 34px; }
  .tb-btn svg { width: 17px; height: 17px; }
  .toolbar-left, .toolbar-right { gap: 2px; }

  /* ── ACCOUNT POPOVER ── */
  #account-popover {
    position: fixed;
    top: calc(var(--toolbar-h) + env(safe-area-inset-top, 0) + 6px);
    right: 8px;
    z-index: 200;
    background: var(--surface, #1d1d1d);
    border: 1px solid var(--border, rgba(255,255,255,0.08));
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    padding: 10px;
    min-width: 240px;
    max-width: calc(100vw - 16px);
  }
  #acct-pop-email {
    font-size: 12px;
    color: var(--text-dim, #aaa);
    padding: 4px 8px 8px;
    overflow-wrap: anywhere;
    border-bottom: 1px solid var(--border, rgba(255,255,255,0.08));
    margin-bottom: 6px;
  }
  #account-popover button {
    background: transparent; border: none;
    color: var(--text, #eee);
    width: 100%; text-align: left;
    padding: 12px 14px; border-radius: 8px;
    font-size: 14px; cursor: pointer;
  }
  #account-popover button:active { background: rgba(255,80,80,0.15); color: #ff8a8a; }

  /* ── MORE POPOVER ── */
  #more-popover {
    position: fixed;
    top: calc(var(--toolbar-h) + env(safe-area-inset-top, 0) + 6px);
    right: 8px;
    z-index: 200;
    background: var(--surface, #1d1d1d);
    border: 1px solid var(--border, rgba(255,255,255,0.08));
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    padding: 6px;
    min-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  #more-popover button {
    background: transparent;
    border: none;
    color: var(--text, #eee);
    text-align: left;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
  }
  #more-popover button:active { background: rgba(255,255,255,0.08); }

  /* ── BOARDS POPOVER ── */
  #boards-popover {
    position: fixed;
    bottom: calc(var(--boardbar-h) + env(safe-area-inset-bottom, 0) + 6px);
    left: 8px;
    z-index: 200;
    background: var(--surface, #1d1d1d);
    border: 1px solid var(--border, rgba(255,255,255,0.08));
    border-radius: 12px;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.5);
    padding: 6px;
    min-width: 240px;
    max-height: 60vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  #boards-popover button {
    background: transparent;
    border: none;
    color: var(--text, #eee);
    text-align: left;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: space-between;
  }
  #boards-popover button.active { background: rgba(255,255,255,0.08); }
  #boards-popover button:active { background: rgba(255,255,255,0.12); }
  #boards-popover .add-row { color: var(--accent, #7c4dff); font-weight: 600; }

  /* ── BOARD BAR (bottom): single dropdown button + model picker ── */
  #board-bar {
    height: calc(var(--boardbar-h) + env(safe-area-inset-bottom, 0));
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-left: 8px; padding-right: 8px;
    gap: 6px;
    justify-content: space-between;
  }
  /* Hide the inline boards list + add-board button, replace with one dropdown */
  #boards-list, #btn-add-board { display: none !important; }

  /* Inject a single dropdown button via ::before on board-bar (driven by JS to update label) */
  #btn-boards-dropdown {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface-2, #1a1a1a);
    border: 1px solid var(--border, rgba(255,255,255,0.08));
    color: var(--text, #eee);
    padding: 8px 14px; border-radius: 10px;
    font-size: 14px; font-weight: 500;
    min-height: 40px;
    cursor: pointer;
  }

  /* ── BOARD BAR (bottom) ── */
  #board-bar {
    height: calc(var(--boardbar-h) + env(safe-area-inset-bottom, 0));
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-left: 8px; padding-right: 8px;
    gap: 6px;
  }

  /* ── LEFT PANEL: full width when open ── */
  #left-panel {
    width: 100%;
    z-index: 95;
  }

  /* ── MINIMAP: too small to use on phone ── */
  #minimap { display: none !important; }

  /* ── MODALS: full-screen on phone ── */
  .modal-overlay { padding: 0; }
  .modal-box,
  .modal-box-wide {
    width: 100%;
    max-width: 100%;
    height: 100dvh;       /* dynamic viewport — accounts for browser UI */
    max-height: 100dvh;
    border-radius: 0;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-header { position: sticky; top: 0; background: var(--surface); z-index: 2; padding: 12px 14px; }
  .modal-footer {
    position: sticky; bottom: 0; background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 12px 14px;
    margin-top: auto;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .modal-footer button { flex: 1 1 auto; min-height: 44px; font-size: 14px; }

  /* Generation modal: prompt textarea taller */
  #modal-prompt { min-height: 100px; font-size: 14px; }

  /* ── INSPIRATION: 1 column on phone ── */
  .insp-grid { grid-template-columns: 1fr !important; }
  .insp-tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .insp-tabs::-webkit-scrollbar { display: none; }
  .insp-tab { white-space: nowrap; flex-shrink: 0; }

  /* Inspiration add-form: full width */
  .insp-add-card { width: 100%; max-width: 100%; max-height: 92%; }

  /* ── MODEL PICKER (right bottom) ── */
  .mp-cards { grid-template-columns: 1fr 1fr !important; }

  /* ── NODE: bigger touch targets, no width override ── */
  .node-actions {
    opacity: 1; pointer-events: all;
    bottom: -38px;          /* a bit lower so it doesn't clip into prompt */
    padding: 6px;
  }
  .node-act-btn { height: 30px; padding: 0 10px; font-size: 12px; }
  .node-act-btn svg { width: 14px; height: 14px; }
  .node-dot { width: 18px; height: 18px; }

  /* Hide less-essential toolbar buttons on phone to reduce clutter */
  #btn-export-json,
  #btn-import-json,
  #btn-comment,
  #btn-tidy { display: none; }

  /* ── CONTEXT MENU (right click / long press) ── */
  .context-menu { min-width: 200px; font-size: 14px; }
  .context-menu button { padding: 12px 14px; }

  /* ── TOAST: not full-width ── */
  .toast { left: 12px; right: 12px; max-width: none; bottom: calc(var(--boardbar-h) + 16px); }

  /* ── AUTH OVERLAY ── */
  #auth-overlay .auth-card {
    width: 100%; max-width: 100%;
    height: 100dvh; border-radius: 0;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  /* Settings modal: ensure inputs are tappable */
  .modal-box input[type="text"],
  .modal-box input[type="password"],
  .modal-box textarea,
  .modal-box select {
    font-size: 16px;       /* prevents iOS zoom on focus */
    min-height: 44px;
  }
}

/* Extra-small phones */
@media (max-width: 380px) {
  .tb-btn { width: 32px; height: 32px; }
  .tb-btn svg { width: 16px; height: 16px; }
  .mp-cards { grid-template-columns: 1fr !important; }
}

/* ═══════════════════════════════════════════════════
   BOTTOM PROMPT BAR (always visible, desktop + mobile)
   ═══════════════════════════════════════════════════ */
#prompt-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--boardbar-h) + 14px);
  width: min(680px, calc(100% - 32px));
  display: flex; align-items: center; gap: 8px;
  background: var(--surface, #1d1d1d);
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  border-radius: 28px;
  padding: 6px 6px 6px 18px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.45);
  z-index: 60;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#prompt-bar-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text, #eee);
  font-size: 14px;
  height: 40px;
  outline: none;
  min-width: 0;
}
#prompt-bar-input::placeholder { color: var(--text-dim, #888); }
#prompt-bar-go {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c4dff 0%, #b388ff 100%);
  color: white;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.1s, box-shadow 0.1s;
}
#prompt-bar-go:hover { box-shadow: 0 6px 16px rgba(124,77,255,0.45); }
#prompt-bar-go:active { transform: scale(0.94); }
#prompt-bar.hidden { display: none; }

/* Mobile prompt bar: full-width, sits above safe-area */
@media (max-width: 768px) {
  #prompt-bar {
    width: calc(100% - 16px);
    bottom: calc(var(--boardbar-h) + env(safe-area-inset-bottom, 0) + 10px);
    padding: 4px 4px 4px 14px;
    border-radius: 24px;
  }
  #prompt-bar-input {
    font-size: 16px;        /* prevent iOS zoom */
    height: 38px;
  }
  #prompt-bar-go { width: 38px; height: 38px; }
}

/* ═══════════════════════════════════════════════════
   EMPTY STATE — shows when board has 0 nodes
   ═══════════════════════════════════════════════════ */
#empty-state {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;          /* let canvas drag through the empty area */
  z-index: 5;
  /* leave room for prompt-bar */
  padding-bottom: 120px;
}
#empty-state.hidden { display: none; }
#empty-state .es-card {
  pointer-events: auto;          /* but the card itself is interactive */
  width: min(440px, calc(100% - 32px));
  background: var(--surface, #1d1d1d);
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  border-radius: 18px;
  padding: 22px 18px 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.4);
}
#empty-state .es-title {
  font-size: 18px; font-weight: 600;
  color: var(--text, #eee);
  margin-bottom: 4px;
}
#empty-state .es-sub {
  font-size: 13px; color: var(--text-dim, #888);
  margin-bottom: 14px;
}
#empty-state .es-row {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text, #eee);
  display: flex; align-items: center; gap: 14px;
  padding: 12px 12px;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  margin-bottom: 4px;
  transition: background 0.12s, border-color 0.12s;
}
#empty-state .es-row:hover {
  background: rgba(255,255,255,0.04);
  border-color: var(--border, rgba(255,255,255,0.08));
}
#empty-state .es-row:active { background: rgba(255,255,255,0.08); }
#empty-state .es-icon {
  flex-shrink: 0;
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  font-size: 18px;
}
#empty-state .es-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#empty-state .es-row-title { font-size: 14px; font-weight: 500; }
#empty-state .es-row-sub { font-size: 12px; color: var(--text-dim, #888); }
#empty-state .es-row[data-act="key"] .es-icon { background: rgba(255,180,80,0.12); }
#empty-state .es-row[data-act="generate"] .es-icon {
  background: linear-gradient(135deg, rgba(124,77,255,0.2), rgba(179,136,255,0.2));
}

/* Light theme tweaks */
:root[data-theme="light"] #prompt-bar,
:root[data-theme="light"] #empty-state .es-card {
  background: rgba(255,255,255,0.95);
}

/* ═══════════════════════════════════════════════════
   SELECTION ACTION BAR — floating pill when 2+ nodes selected
   ═══════════════════════════════════════════════════ */
#selection-bar {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  z-index: 90;
  display: flex; align-items: center; gap: 4px;
  padding: 6px;
  background: rgba(20, 20, 28, 0.96);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 999px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 13px;
  color: #eee;
  animation: selBarIn 0.18s ease-out;
}
@keyframes selBarIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
#selection-bar.hidden { display: none; }

#selection-count {
  padding: 0 14px 0 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-right: 1px solid rgba(255,255,255,0.10);
  margin-right: 4px;
}
#selection-bar button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: transparent;
  border: none;
  color: #eee;
  font-size: 13px;
  font-weight: 500;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
#selection-bar button:hover {
  background: rgba(124, 77, 255, 0.20);
  color: #fff;
}
#selection-bar button:active { transform: scale(0.97); }
#selection-bar button svg { opacity: 0.85; }
#selection-bar button.sel-danger:hover {
  background: rgba(255, 90, 90, 0.18);
  color: #ff8a8a;
}
#btn-sel-close {
  padding: 8px 12px !important;
  opacity: 0.55;
  font-size: 12px !important;
  margin-left: 2px;
  border-left: 1px solid rgba(255,255,255,0.10);
  border-radius: 0 999px 999px 0 !important;
}
#btn-sel-close:hover { opacity: 1; background: transparent !important; }

@media (max-width: 720px) {
  #selection-bar {
    bottom: 100px;
    font-size: 12px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 92vw;
    border-radius: 16px;
  }
  #selection-count { padding: 2px 10px; border-right: none; width: 100%; text-align: center; }
  #selection-bar button { padding: 7px 11px; }
}
