/* Apply the Formula palette to the editor and its owned overlays. */
.formula-creative-surface[data-bs-theme="dark"] {
  --editor-line: color-mix(in srgb, var(--text) 15%, var(--surface));
  --editor-hover: color-mix(in srgb, var(--accent) 10%, var(--bg-card-2));
  --editor-motion: 180ms cubic-bezier(.2, .7, .2, 1);
  --editor-warning: #f2c979;
  --editor-warning-bg: color-mix(in srgb, var(--editor-warning) 14%, var(--surface));
  --editor-warning-line: color-mix(in srgb, var(--editor-warning) 40%, var(--surface));
  --editor-danger: color-mix(in srgb, var(--danger) 70%, var(--text));
  --bs-page-bg: var(--bg);
  --bs-body-bg: var(--surface);
  --bs-body-color: var(--text);
  --bs-body-font-family: var(--font-body);
  --bs-heading-color: var(--text);
  --bs-secondary-bg: var(--bg-card-2);
  --bs-tertiary-bg: var(--bg);
  --bs-secondary-color: var(--text-muted);
  --bs-tertiary-color: var(--text-muted);
  --bs-border-color: var(--editor-line);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent-2);
  --bs-code-color: var(--accent-2);
  --bs-gray-100: var(--bg-card-2);
  --bs-gray-200: var(--editor-line);
  --bs-gray-300: color-mix(in srgb, var(--text) 23%, var(--surface));
  --bs-gray-400: color-mix(in srgb, var(--text-muted) 82%, var(--surface));
  --bs-gray-500: var(--text-muted);
  --bs-gray-600: var(--text-muted);
  --bs-gray-700: var(--text);
  --bs-gray-800: var(--text);
  --bs-gray-900: var(--text);
  --bs-light: var(--bg-card-2);
  --bs-light-active: var(--editor-hover);
  --bs-light-inverse: var(--text);
  --bs-primary: var(--accent);
  --bs-primary-active: var(--accent-2);
  --bs-primary-inverse: var(--accent-foreground);
  --bs-primary-light: var(--accent-soft);
  --bs-light-primary: var(--accent-soft);
  --bs-primary-clarity: color-mix(in srgb, var(--accent) 18%, transparent);
  --bs-text-primary: var(--accent);
  --bs-primary-text-emphasis: var(--accent-2);
  --bs-primary-bg-subtle: var(--accent-soft);
  --bs-primary-border-subtle: var(--accent-line);
  --bs-info: var(--accent-2);
  --bs-info-light: var(--accent-soft);
  --bs-info-active: var(--accent);
  --bs-info-inverse: var(--accent-foreground);
  --bs-text-info: var(--accent-2);
  --bs-success: var(--success);
  --bs-danger: var(--danger);
  accent-color: var(--accent);
  scrollbar-color: var(--bs-gray-300) var(--bg);
}

.formula-creative-surface[data-creative-editor] {
  --creative-bottom: 0px;
  --creative-height: max(0px, calc(100dvh - var(--creative-top, 0px) - var(--creative-bottom)));
  box-sizing: border-box;
  width: 100%;
  min-height: var(--creative-height);
  padding-bottom: var(--creative-bottom);
}
@media (max-width: 768px) {
  .creative-tools:not(.creative-tools--expanded) [data-creative-editor] { --creative-bottom: calc(76px + env(safe-area-inset-bottom)); }
}

.formula-creative-surface[data-bs-theme="dark"] .neuro-app { background: transparent; color: var(--text); }
.formula-creative-surface .neuro-app { font-family: var(--font-body); font-size: 13px; }
.formula-creative-surface .neuro-app :is(button, input, select, textarea) { font-family: inherit; }
.formula-creative-surface [data-neuro-route-outlet] { min-height: var(--creative-height); min-width: 0; }
.formula-creative-surface .creative-tools__loading { padding: 20px; color: var(--text-muted); }
.formula-creative-surface .btn { width: auto; height: auto; z-index: auto; }
.neuro-app a:where(:any-link) { color: var(--bs-link-color); }
.neuro-app a:where(:hover) { color: var(--bs-link-hover-color); }
.neuro-app :is(.text-primary, .link-primary) { color: var(--accent) !important; }
.neuro-app :is(.border-primary, .border-info) { border-color: var(--accent-line) !important; }

.neuro-app :focus-visible {
  outline: 2px solid var(--accent) !important;
  outline-offset: 2px;
}

.neuro-app :is(.form-control, .form-select):focus { border-color: var(--accent-line); }
.neuro-app :is(.form-control, .form-select)::placeholder { color: var(--text-muted); }
.neuro-app .btn, .neuro-app .form-select, .neuro-app .form-control {
  transition: background-color var(--editor-motion), color var(--editor-motion), border-color var(--editor-motion);
}

.neuro-app .cult-pro-select-wrap { width: fit-content; max-width: 100%; }
.neuro-app .cult-pro-select-wrap[data-pro-theme="dark"] .cult-pro-select-trigger,
.neuro-app .cult-pro-select-panel[data-pro-theme="dark"] {
  background: var(--bg-card-2);
  border-color: var(--editor-line);
}
.neuro-app .cult-pro-select-wrap[data-pro-theme="dark"] .cult-pro-select-trigger[aria-invalid="true"] { border-color: var(--danger); }
.neuro-app .cult-pro-select-wrap[data-pro-theme="dark"] .cult-pro-select-indicator { background: var(--surface); }
.neuro-app .cult-pro-select-option[data-highlighted="true"] { background: var(--accent-soft); color: var(--accent); }

/* The work area fills the space below the Formula toolbar. */
.formula-creative-surface .neuro-design-app {
  --nd-bg: transparent;
  --nd-hover: var(--editor-hover);
  height: max(600px, var(--creative-height));
  border: 0;
  border-radius: 0;
}
.neuro-design-app .nd-dock { border-radius: var(--radius-lg); }
.neuro-design-app .nd-dock:focus-within { border-color: var(--accent-line); }
.neuro-design-app :is(.nd-btn.is-primary, .nd-dock-go, .nd-seg.is-active, .nd-toggle.is-active) {
  color: var(--accent-foreground);
}
.neuro-design-app :is(.nd-btn, .nd-tool, .nd-zbtn, .nd-dock-go, .nd-layer-row, .nd-input) {
  transition: background-color var(--editor-motion), color var(--editor-motion), border-color var(--editor-motion);
}
.neuro-design-app :is(.nd-input, .nd-dock-input)::placeholder { color: var(--text-muted); }

/* Workflow canvas, projects and character studio. */
.neuro-app .formula-studio-host :is(.wf-studio, .wf-projects, .influencer-studio-page) { font-family: var(--font-body); }
.formula-creative-surface .formula-studio-host .wf-studio { border-radius: 0; }
.formula-creative-surface .formula-studio-host .wf-studio:not(.wf-light) { --wf-bg: var(--bg); background: transparent; }
.formula-creative-surface .wf-studio .wf-stage { height: max(520px, var(--creative-height)); }
.formula-creative-surface .wf-studio:not(.wf-light) .wf-stage { background-color: transparent; }
.formula-creative-surface .ins-shell { height: max(600px, var(--creative-height)); max-height: none; }
.formula-creative-surface :is(.ins-builder, .ins-workspace) { border-radius: 0; }
.neuro-app .formula-studio-host .wf-studio.wf-light {
  --wf-bg: #eeeeef;
  --pd-surface: #fafafa;
  --pd-raised: #fff;
  --pd-inset: #f4f4f5;
  --pd-text: #262629;
  --pd-muted: #5d5d62;
  --pd-line: #00000022;
  --pd-accent: color-mix(in srgb, var(--accent) 37%, #000);
  --pd-accent-ink: #fff;
  --pd-accent-soft: color-mix(in srgb, var(--accent) 12%, var(--pd-raised));
  --wf-line: var(--pd-line);
  color-scheme: light;
}
.wf-studio:not(.wf-light) .wf-stage:where(:not(.no-grid)) {
  background-image: radial-gradient(color-mix(in srgb, var(--accent) 14%, transparent) 1px, transparent 1px);
}
.wf-studio .wf-stage.no-grid { background-image: none; }
.neuro-app .wf-light :focus-visible { outline-color: var(--pd-accent) !important; }
.wf-projects .wf-project-card:hover { border-color: var(--accent-line); }
.wf-variant-thumbnail[aria-pressed="true"] { border-color: var(--pd-accent); background: var(--pd-accent-soft); }
.wf-node[data-node]:not(.wf-note) textarea::placeholder { color: var(--wf-muted); }

.ins-heading h1 { font-family: var(--font-heading); }
.ins-tools .ins-random {
  border: 1px solid var(--editor-line);
  background: var(--bg-card-2);
  color: var(--text);
}
.ins-tools .ins-random:hover:enabled { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent); }
.ins-source-tabs button[aria-selected="true"],
.influencer-studio-layer .ins-library-tabs button[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}
.ins-mode-tabs button[aria-selected="true"],
.ins-workspace-tabs button[aria-selected="true"] { box-shadow: inset 0 0 0 1px var(--accent-line); }
.ins-type-grid .ins-option-name { font-size: 11px; }
.neuro-app .formula-studio-host .ins-type-grid .ins-option[aria-pressed="true"] { background: var(--accent-soft) !important; }
.neuro-app .formula-studio-host .ins-type-grid .ins-option[aria-pressed="true"] .ins-option-name { color: var(--accent); }

/* The 3D scene keeps its viewport and uses Formula colors for editor chrome. */
.formula-creative-surface .nf-scene {
  position: relative;
  inset: auto;
  z-index: auto;
  height: max(420px, var(--creative-height));
  background: transparent;
}
.nf-scene,
.nf-scene-dialog {
  --panel: var(--bs-body-bg);
  --surface: var(--bs-secondary-bg);
  --text: var(--bs-body-color);
  --muted: var(--bs-secondary-color);
  --line: var(--editor-line);
  --control: var(--bg-card-2);
  --hover: var(--editor-hover);
  --selected: var(--accent-soft);
  font-family: var(--font-body);
}

.nf-scene .nf-prompt-box { background: var(--control); border-color: var(--line); }
.nf-scene .nf-prompt-box:focus-within { border-color: var(--accent-line); }
.nf-scene .nf-context-prompt .nf-prompt-box { background: transparent; }
.nf-scene .nf-prompt-box textarea::placeholder { color: var(--muted); }
.nf-scene .nf-scene-mode {
  min-height: 32px;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.nf-scene .nf-scene-mode input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nf-scene :is(.nf-primary, .nf-prompt-actions .nf-send:enabled),
.nf-scene-dialog .nf-primary { background: var(--accent); color: var(--accent-foreground); }
.nf-scene :is(.nf-primary:hover, .nf-prompt-actions .nf-send:enabled:hover),
.nf-scene-dialog .nf-primary:hover { background: var(--accent-2); }

.nf-scene button,
.nf-scene-dialog button { transition: background-color var(--editor-motion), color var(--editor-motion); }
.nf-scene :is(button[aria-pressed="true"], button[aria-selected="true"], .nf-track-label[data-selected="true"], .nf-tree-row[data-selected="true"]) {
  color: var(--accent);
}
.nf-scene .nf-track-label[data-selected="true"] { background: var(--accent-soft); }
.nf-scene-dialog .nf-export-tabs button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.nf-scene .nf-tree-row[data-selected="true"] > svg { color: inherit; }
.nf-scene .nf-timeline-bar .nf-auto-key[aria-pressed="true"] { color: var(--text); }
.nf-scene .nf-reasoning-menu button[aria-checked="true"]::after,
.nf-scene :is(.nf-project-mark, .nf-agent-context, .nf-message-status),
.nf-scene-dialog :is(pre, .nf-video-job a) { color: var(--accent-2); }

.nf-scene :is(.nf-popup, .nf-model-menu) { background: var(--control); border-color: var(--line); }
.nf-scene-dialog { border-color: var(--line); }
:is(.nf-scene, .nf-scene-dialog) select :is(option, optgroup) {
  color-scheme: dark;
  background: var(--control);
  color: var(--text);
}
:is(.nf-scene, .nf-scene-dialog) :is(input[type="checkbox"], progress) { accent-color: var(--accent); }

.nf-scene .nf-key:not([data-outside="true"]) { background: var(--accent) !important; }
.nf-scene .nf-key[aria-pressed="true"] { outline-color: var(--text); }
.nf-scene .nf-playhead { background: var(--accent); }
.nf-scene .nf-playhead::before { border-top-color: var(--accent); }
.nf-scene :is(.nf-resize-left:hover, .nf-resize-right:hover) { background: var(--accent-line); }
.nf-scene .nf-key-row[data-selected="true"]:not([data-invalid="true"]) { background-color: color-mix(in srgb, var(--accent) 10%, transparent); }
.nf-scene :is(.nf-path-range, .nf-key-marquee, .nf-action-clip) {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--text);
}

@media (prefers-reduced-motion: reduce) {
  .formula-creative-surface[data-bs-theme="dark"] { --editor-motion: 0s; }
}
