/* Global prevention of system interactions for the entire module */
.module-root,
.module-root * {
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
  -webkit-tap-highlight-color: transparent !important;
  -webkit-user-drag: none !important;
  -khtml-user-drag: none !important;
  -moz-user-drag: none !important;
  -o-user-drag: none !important;
  user-drag: none !important;
  touch-action: none !important;
}

/* Allow text selection only for input fields and textareas if needed */
.module-root input[type="text"],
.module-root input[type="email"],
.module-root input[type="password"],
.module-root input[type="search"],
.module-root input[type="url"],
.module-root textarea {
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
  touch-action: auto !important;
}

.module-root,
.canvas-wrapper {
  --ff-ui-surface: rgba(255, 255, 255, 0.95);
  --ff-ui-surface-soft: rgba(255, 255, 255, 0.96);
  --ff-ui-surface-strong: rgba(255, 255, 255, 0.98);
  --ff-ui-border: rgba(0, 0, 0, 0.12);
  --ff-ui-border-strong: rgba(0, 0, 0, 0.22);
  --ff-ui-text: #1a1a1a;
  --ff-ui-text-muted: rgba(0, 0, 0, 0.62);
  --ff-ui-text-soft: rgba(0, 0, 0, 0.42);
  --ff-ui-hover: rgba(0, 0, 0, 0.06);
  --ff-ui-hover-strong: rgba(0, 0, 0, 0.12);
  --ff-ui-active: rgba(38, 38, 44, 0.95);
  --ff-ui-active-text: #ffffff;
  --ff-ui-shadow:
    0 8px 32px rgba(0, 0, 0, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.08);
  --ff-ui-float-shadow:
    0 8px 32px rgba(0, 0, 0, 0.15),
    0 0 0 1px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  --ff-ui-icon-filter: brightness(0);
  --ff-ui-slider-track: rgba(0, 0, 0, 0.18);
  --ff-ui-slider-thumb: #555560;
  --ff-ui-slider-thumb-border: rgba(255, 255, 255, 0.9);
  --ff-ui-slider-thumb-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  --ff-ui-slider-thumb-size: 16px;
  --ff-ui-slider-thumb-size-touch: 20px;
  --ff-ui-kbd-bg: linear-gradient(to bottom, rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.02));
  --ff-ui-kbd-border: rgba(0, 0, 0, 0.1);
  --ff-ui-kbd-shadow:
    0 1px 2px rgba(0, 0, 0, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    inset 0 -1px 0 rgba(0, 0, 0, 0.05);
  --ff-ui-resize: #888888;
  --ff-ui-resize-strong: #333333;
  --ff-ui-selection-bg: rgba(0, 0, 0, 0.15);
  --ff-ui-selection-text: #000000;
}

.module-root[data-freeform-theme="dark"],
.canvas-wrapper[data-freeform-theme="dark"] {
  --ff-ui-surface: rgba(18, 18, 22, 0.94);
  --ff-ui-surface-soft: rgba(24, 24, 30, 0.95);
  --ff-ui-surface-strong: rgba(16, 16, 20, 0.98);
  --ff-ui-border: rgba(255, 255, 255, 0.18);
  --ff-ui-border-strong: rgba(255, 255, 255, 0.28);
  --ff-ui-text: #eef1f7;
  --ff-ui-text-muted: rgba(238, 241, 247, 0.72);
  --ff-ui-text-soft: rgba(238, 241, 247, 0.5);
  --ff-ui-hover: rgba(255, 255, 255, 0.08);
  --ff-ui-hover-strong: rgba(255, 255, 255, 0.14);
  --ff-ui-active: rgba(238, 241, 247, 0.2);
  --ff-ui-active-text: #eef1f7;
  --ff-ui-shadow:
    0 12px 34px rgba(0, 0, 0, 0.45),
    0 2px 8px rgba(0, 0, 0, 0.24);
  --ff-ui-float-shadow:
    0 10px 36px rgba(0, 0, 0, 0.52),
    0 0 0 1px rgba(255, 255, 255, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  --ff-ui-icon-filter: brightness(0) invert(1);
  --ff-ui-slider-track: rgba(255, 255, 255, 0.22);
  --ff-ui-slider-thumb: #c0c4cc;
  --ff-ui-slider-thumb-border: rgba(255, 255, 255, 0.3);
  --ff-ui-slider-thumb-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  --ff-ui-slider-thumb-size: 16px;
  --ff-ui-slider-thumb-size-touch: 20px;
  --ff-ui-kbd-bg: linear-gradient(to bottom, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
  --ff-ui-kbd-border: rgba(255, 255, 255, 0.2);
  --ff-ui-kbd-shadow:
    0 1px 3px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
  --ff-ui-resize: rgba(238, 241, 247, 0.62);
  --ff-ui-resize-strong: #eef1f7;
  --ff-ui-selection-bg: rgba(255, 255, 255, 0.22);
  --ff-ui-selection-text: #eef1f7;
}

/* Prevent text selection and system interactions */
.module-root,
.canvas-wrapper,
.canvas-wrapper canvas,
.result-image-container,
.result-image,
.canvas-controls,
.canvas-controls button,
#iconBar,
.barIconContainer,
.barIcon,
.tooltip,
#color-picker-container,
#color-picker,
#color-swatch,
.crop-overlay,
.crop-rect,
.crop-rect .handle {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
}

/* Prevent context menu on long press */
.module-root,
.canvas-wrapper,
.canvas-wrapper canvas,
.result-image-container,
.result-image,
.canvas-controls,
.canvas-controls button,
#iconBar,
.barIconContainer,
.barIcon,
.tooltip,
#color-picker-container,
#color-picker,
#color-swatch,
.crop-overlay,
.crop-rect,
.crop-rect .handle {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Prevent text selection globally for this module */
.module-root * {
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
  -webkit-tap-highlight-color: transparent !important;
}

/* Prevent context menu on right click */
.module-root,
.canvas-wrapper,
.canvas-wrapper canvas,
.result-image-container,
.result-image,
.canvas-controls,
.canvas-controls button,
#iconBar,
.barIconContainer,
.barIcon,
.tooltip,
#color-picker-container,
#color-picker,
#color-swatch,
.crop-overlay,
.crop-rect,
.crop-rect .handle {
  -webkit-context-menu: none;
  -moz-context-menu: none;
  -ms-context-menu: none;
  context-menu: none;
}

/* Prevent system text selection on mobile */
@media (max-width: 768px) {
  .module-root,
  .module-root * {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
    -webkit-tap-highlight-color: transparent !important;
    -webkit-touch-callout: none !important;
    -webkit-user-drag: none !important;
    -khtml-user-drag: none !important;
    -moz-user-drag: none !important;
    -o-user-drag: none !important;
    user-drag: none !important;
  }
  
  /* Additional mobile-specific touch prevention */
  .canvas-wrapper canvas {
    touch-action: none !important;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    -webkit-tap-highlight-color: transparent !important;
  }
  
  /* Prevent any system gestures */
  .module-root {
    touch-action: none !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
  }
  
  /* Prevent text selection on all interactive elements */
  .barIconContainer,
  .barIcon,
  .tooltip,
  .canvas-controls button {
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
  }
  
  /* Hide regular text tool on mobile (complex keyboard interaction) */
  .barIconContainer[data-tool="text"],
  .barIconContainer[data-group="text"] {
    display: none !important;
  }
}

/* Allow native DnD for explicit drag sources (catalog cards, capsules, etc.). */
.module-root [draggable="true"],
.module-root [data-allow-native-drag="true"] {
  -webkit-user-drag: element !important;
  -khtml-user-drag: element !important;
  -moz-user-drag: element !important;
  -o-user-drag: element !important;
  user-drag: element !important;
  touch-action: auto !important;
}

/* Thinking text input overlay - cloud-like styling */
.text-input-overlay.thinking-mode {
  border-radius: 24px !important;
  border: 2px solid rgba(100, 100, 100, 0.6) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2) !important;
  background: rgba(30, 41, 59, 0.95) !important;
}

.text-input-overlay.thinking-mode .text-tool-input {
  font-style: italic !important;
}

/* Text tool input overlay - MONOCHROME style (white frosted glass) */
.text-input-overlay {
  position: absolute;
  z-index: 10001;
  background: var(--ff-ui-surface);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--ff-ui-border);
  border-radius: 16px;
  padding: 0;
  box-shadow: var(--ff-ui-shadow);
  min-width: 200px;
  min-height: 120px;
  width: 300px;
  height: 150px;
  overflow: hidden;
  box-sizing: border-box;
}

/* Textarea for multiline text input - MONOCHROME */
.text-tool-input {
  display: block;
  background: transparent;
  border: none;
  outline: none;
  color: var(--ff-ui-text);
  font: bold 24px Arial, sans-serif;
  width: 100%;
  height: calc(100% - 36px);
  padding: 14px 16px 8px 16px;
  caret-color: var(--ff-ui-text);
  resize: none;
  overflow: auto;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-sizing: border-box;
}

/* Text selection - medium grey */
.text-tool-input::selection {
  background: var(--ff-ui-selection-bg);
  color: var(--ff-ui-selection-text);
}

.text-tool-input::-moz-selection {
  background: var(--ff-ui-selection-bg);
  color: var(--ff-ui-selection-text);
}

.text-tool-input::placeholder {
  color: var(--ff-ui-text-soft);
  font-size: 14px;
  font-weight: normal;
  white-space: pre-wrap;
}

.text-tool-input:focus {
  outline: none;
}

/* Action buttons in text overlay */
.text-overlay-btn {
  -webkit-appearance: none;
  appearance: none;
}

.text-overlay-btn:focus {
  outline: none;
}

.module-root { display: flex; flex-direction: column; height: 100%; }
.canvas-wrapper { position: relative; flex-grow: 1; overflow: hidden; border-radius: 8px; background-color: #eee; }
.canvas-wrapper canvas { display: block; }
.result-image-container { 
  position: absolute; 
  top: 0; 
  left: 0; 
  width: 100%; 
  height: 100%; 
  border-radius: 8px; 
  z-index: 2; 
  /* Critical: don't block drawing/interaction on the WebGL canvas */
  pointer-events: none; 
}
.result-image { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 1s ease-in-out; display: none; }
.canvas-controls { position: absolute; top: 8px; right: 8px; z-index: 20; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.canvas-actions { display: flex; flex-direction: column; gap: 8px; }
.canvas-controls button { padding: 6px 12px; border: 1px solid var(--border-color); background-color: var(--tertiary-bg); color: var(--text-primary); border-radius: 6px; cursor: pointer; transition: background-color 0.2s; }
.canvas-controls button:hover:not(:disabled) { background-color: var(--hover-bg); }
.canvas-controls button:disabled { opacity: 0.5; cursor: not-allowed; }
#iconBar { 
  position: absolute; 
  z-index: 100000; /* CRITICAL FIX: Ensure iconbar is always above all overlays */
  left: 16px; 
  top: 50%; 
  transform: translateY(calc(-50% - var(--ff-toolbar-offset, 0px))); 
  display: flex; 
  flex-direction: column; 
  gap: calc(8px * var(--ff-toolbar-scale, 1)); 
  background: rgba(255, 255, 255, 0.85); /* Light mode: white base with high opacity */
  backdrop-filter: blur(20px) saturate(180%); 
  -webkit-backdrop-filter: blur(20px) saturate(180%); 
  border: 1px solid rgba(255, 255, 255, 0.6); /* Subtle white border */
  border-radius: calc(25px * var(--ff-toolbar-scale, 1)); 
  padding: calc(8px * var(--ff-toolbar-scale, 1)); 
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.12), /* Softer shadow for light mode */
    0 0 0 1px rgba(255, 255, 255, 0.8),
    inset 0 2px 4px rgba(255, 255, 255, 0.5), /* Inner highlight */
    inset 0 -1px 2px rgba(0, 0, 0, 0.05); /* Subtle inner shadow */
  transition: background-color 0.3s, opacity 0.2s ease-out, box-shadow 0.3s ease;
  opacity: 1;
  cursor: grab; /* Show grab cursor on toolbar edge to indicate it's draggable */
  --ff-toolbar-scale: 0.8;
  --ff-toolbar-offset: 24px;
}

#canvasPills {
  position: absolute !important;
  top: calc(16px + env(safe-area-inset-top, 0px)) !important;
  right: calc(16px + env(safe-area-inset-right, 0px)) !important;
  display: flex !important;
  flex-direction: row-reverse !important;
  align-items: center !important;
  gap: 8px !important;
  z-index: 100000 !important;
  pointer-events: auto !important;
  transition: top 0.22s cubic-bezier(0.32, 0.72, 0, 1) !important;
}

#canvasHeaderToggleBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  opacity: 0.88;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

#canvasHeaderToggleBtn .ff-header-toggle-icon {
  transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

body.workspace-mode[data-active-module="freeform"]:not(.ff-freeform-header-collapsed) #canvasHeaderToggleBtn .ff-header-toggle-icon {
  transform: rotate(180deg);
}

#canvasHeaderToggleBtn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18) !important;
}

body.freeform-view-only #canvasHeaderToggleBtn,
body.freeform-view-only-guest #canvasHeaderToggleBtn {
  display: none !important;
}

body.workspace-mode[data-active-module="freeform"] .chat-container.workspace-active {
  height: 100% !important;
  min-height: 0 !important;
}

#canvasTopMenuToggle {
  display: none;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#canvasTopMenuToggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18) !important;
}

#canvasPillsLeft {
  top: calc(16px + env(safe-area-inset-top, 0px)) !important;
  left: calc(16px + env(safe-area-inset-left, 0px)) !important;
  gap: 0 !important;
  align-items: center !important;
  transition: left 0.3s ease, top 0.22s cubic-bezier(0.32, 0.72, 0, 1) !important;
  z-index: 100002 !important;
  pointer-events: auto !important;
}

body.workspace-mode[data-active-module="freeform"]:not(.ff-freeform-header-collapsed) #canvasPills {
  top: calc(var(--topbar-height, 60px) + 12px + env(safe-area-inset-top, 0px)) !important;
}

body.workspace-mode[data-active-module="freeform"]:not(.ff-freeform-header-collapsed) #canvasPillsLeft {
  top: calc(var(--topbar-height, 60px) + 12px + env(safe-area-inset-top, 0px)) !important;
}

#canvasSidebarToggleBtn {
  overflow: hidden !important;
  width: 0 !important;
  height: 36px !important;
  min-width: 0 !important;
  min-height: 36px !important;
  margin-right: 0 !important;
  padding: 0 !important;
  border-width: 1px !important;
  opacity: 0 !important;
  transform: translateX(-14px) !important;
  pointer-events: none !important;
  flex-shrink: 0 !important;
  transition:
    width 0.28s cubic-bezier(0.32, 0.72, 0, 1),
    min-width 0.28s cubic-bezier(0.32, 0.72, 0, 1),
    margin-right 0.28s cubic-bezier(0.32, 0.72, 0, 1),
    opacity 0.2s ease,
    transform 0.28s cubic-bezier(0.32, 0.72, 0, 1),
    box-shadow 0.2s ease,
    border-color 0.2s ease,
    background 0.2s ease !important;
}

body.workspace-mode[data-active-module="freeform"].ff-freeform-header-collapsed #canvasSidebarToggleBtn {
  width: 36px !important;
  min-width: 36px !important;
  margin-right: 14px !important;
  opacity: 1 !important;
  transform: translateX(0) !important;
  pointer-events: auto !important;
}

#canvasSidebarToggleBtn:hover {
  transform: translateX(0) translateY(-1px) !important;
}

#canvasTitlePill,
#canvasMenuBtn,
#canvasSidebarToggleBtn,
#managerDropdown {
  pointer-events: auto !important;
}

#canvasTitlePill {
  box-sizing: border-box !important;
}

#canvasTitlePill .canvas-title-label,
#canvasTitlePill .canvas-title-text {
  display: flex !important;
  align-items: center !important;
  line-height: 1 !important;
}

#canvasTitlePill .canvas-title-text {
  min-width: 0 !important;
}

#managerDropdown {
  z-index: 100003 !important;
}

/* Hidden modal layers must not intercept canvas-manager interactions. */
.freeform-action-modal:not(.visible),
.freeform-save-modal:not(.visible),
.delete-confirmation-pill:not(.active),
.canvas-share-modal:not(.active),
.cm-pro-gate-modal:not(.active),
.freeform-autosave-recovery:not(.visible) {
  pointer-events: none !important;
}

.freeform-action-modal.visible,
.freeform-save-modal.visible,
.delete-confirmation-pill.active,
.canvas-share-modal.active,
.cm-pro-gate-modal.active,
.freeform-autosave-recovery.visible {
  pointer-events: auto !important;
}

.module-root.ff-top-ui-tablet #canvasTopMenuToggle {
  display: inline-flex !important;
}

.module-root.ff-top-ui-tablet:not(.ff-top-ui-expanded) #canvasPills .ff-top-pill:not(#canvasTopMenuToggle):not(#canvasHeaderToggleBtn),
.module-root.ff-top-ui-tablet:not(.ff-top-ui-expanded) #canvasPills #autosavePill {
  display: none !important;
}

/* Keep the board menu toggle visible while tablet controls are collapsed. */
.module-root.ff-top-ui-tablet:not(.ff-top-ui-expanded) #canvasPills #canvasTopMenuToggle {
  display: inline-flex !important;
}

.module-root.ff-top-ui-tablet:not(.ff-top-ui-expanded) #canvasPillsLeft {
  display: none !important;
}

/* Push manager pill (canvasPillsLeft) when sidebar is open - same as instant narratives */
@media (min-width: 769px) {
  .sidebar.open ~ .main-content #canvasPillsLeft,
  .sidebar.open ~ .main-content .canvas-wrapper #canvasPillsLeft {
    left: calc(var(--sidebar-width, 330px) + 20px) !important;
  }
}

/* CSS-driven sidebar push for non-dragged toolbar — fires in same frame as sidebar animation */
.sidebar.open ~ .main-content #iconBar:not(.dragged):not(.dragging) {
  left: calc(var(--sidebar-width, 330px) + 16px) !important;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#qualityPill {
  height: 36px;
  align-items: center;
}

#canvasTitlePill {
  min-height: 36px !important;
  border-radius: 16px !important;
}

#canvasMenuBtn {
  width: 28px !important;
  height: 28px !important;
  min-width: 28px !important;
  min-height: 28px !important;
  border-radius: 12px !important;
  align-self: center !important;
}

#iconBar .toolbar-expand-toggle {
  width: 100%;
  height: auto;
  border-radius: 0;
  border: none;
  background: transparent;
  display: none;
  align-items: center;
  justify-content: center;
  margin-top: calc(4px * var(--ff-toolbar-scale, 1));
  padding: calc(6px * var(--ff-toolbar-scale, 1)) 0;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

#iconBar .toolbar-expand-toggle:hover {
  background: transparent;
  box-shadow: none;
}

#iconBar .toolbar-expand-arrow {
  width: calc(8px * var(--ff-toolbar-scale, 1));
  height: calc(8px * var(--ff-toolbar-scale, 1));
  border-right: 2px solid rgba(0, 0, 0, 0.6);
  border-bottom: 2px solid rgba(0, 0, 0, 0.6);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  margin: 0 auto;
}

#iconBar.ff-toolbar-expanded .toolbar-expand-arrow {
  transform: rotate(-135deg);
}

/* Separator between tools and undo/redo */
.iconbar-separator {
  width: calc(26px * var(--ff-toolbar-scale, 1));
  height: 1px;
  background: rgba(0, 0, 0, 0.12); /* Dark separator for light mode */
  margin: 2px auto;
  border-radius: 1px;
}

/* Smooth fade transition for drag operations - MUST be on base selector for smooth fade-in AND fade-out */
#iconBar {
  transition: opacity 0.2s ease-out;
}

/* Fade out during drag operations for cleaner visual experience */
#iconBar.dragging-fade {
  opacity: 0.15;
  pointer-events: auto !important; /* CRITICAL FIX: Force iconbar to always be clickable */
  isolation: isolate; /* CRITICAL FIX: Create new stacking context */
  cursor: grab;
}

/* Also fade the prompt bar (images action bar) during drag */
/* Transition MUST be on base selector for smooth fade-in AND fade-out */
body[data-active-module="freeform"] .input-section {
  transition: opacity 0.2s ease-out !important;
}

/* ── Fix invisible blocking area at bottom of canvas ───────────────── */
/* The .input-container has pointer-events:auto covering a wide band at the bottom.
   In freeform, only the visible prompt pill should be interactive, not the container. */
body[data-active-module="freeform"] .input-section,
body[data-active-module="freeform"] .input-container {
  pointer-events: none !important;
}
body[data-active-module="freeform"] .message-input-container,
body[data-active-module="freeform"] .thumb-strip,
body[data-active-module="freeform"] .input-section .plus-menu-container {
  pointer-events: auto !important;
}

body[data-active-module="freeform"] .input-section.dragging-fade {
  opacity: 0.15 !important;
  pointer-events: none !important;
}

#iconBar.dragging {
  cursor: grabbing;
}

/* ── Drag handles (top + bottom grab pills) ─────────────────────────── */
.ff-drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 5px 0;
  cursor: grab;
  -webkit-touch-callout: none;
  touch-action: none;
}
.ff-drag-handle-pill {
  width: calc(28px * var(--ff-toolbar-scale, 1));
  height: calc(4px * var(--ff-toolbar-scale, 1));
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.18);
  transition: background 0.2s ease, width 0.2s ease;
}
.ff-drag-handle:active .ff-drag-handle-pill,
#iconBar.ff-toolbar-dragging .ff-drag-handle-pill {
  background: rgba(0, 0, 0, 0.35);
  width: calc(32px * var(--ff-toolbar-scale, 1));
}

/* ── Collapsed: tighten gap since hidden items still occupy flex gap ── */
#iconBar.ff-toolbar-collapsed {
  gap: calc(4px * var(--ff-toolbar-scale, 1));
}

/* ── Fully round edges (half-circle caps) ────────────────────────────── */
#iconBar {
  border-radius: 999px !important;
}

/* ── Sidebar overlay must not block freeform toolbar or canvas ──────── */
/* The sidebar-overlay is position:fixed z-index:1200 and #iconBar is position:absolute,
   so iconBar's z-index only applies within its parent stacking context.
   Fix: pass pointer events through overlay when freeform is active. */
body[data-active-module="freeform"] .sidebar-overlay,
body[data-active-module="freeform"] .sidebar-overlay.active {
  pointer-events: none !important;
}

/* ── Suppress tooltips and hover effects during drag ────────────────── */
#iconBar.dragging .tooltip,
#iconBar.ff-toolbar-dragging .tooltip,
#iconBar.dragging .barIconContainer .tooltip,
#iconBar.ff-toolbar-dragging .barIconContainer .tooltip {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
#iconBar.dragging .barIconContainer:hover,
#iconBar.ff-toolbar-dragging .barIconContainer:hover {
  background: transparent !important;
  transform: none !important;
  box-shadow: none !important;
}

/* ── iPad Notes-style drag elevation ────────────────────────────────── */
#iconBar.ff-toolbar-dragging {
  cursor: grabbing !important;
  /* No transform here — position is fully managed by JS during drag */
  box-shadow:
    0 22px 70px rgba(0, 0, 0, 0.22),
    0 10px 30px rgba(0, 0, 0, 0.14),
    0 0 0 1px rgba(0, 0, 0, 0.06) !important;
  /* Only transition box-shadow — transform/left/top must be instant during drag */
  transition: box-shadow 0.18s ease !important;
  opacity: 0.95 !important;
  z-index: 100010 !important;
}

#iconBar .barIconContainer {
  cursor: pointer;
}
.barIconContainer { 
  width: calc(38px * var(--ff-toolbar-scale, 1)); 
  height: calc(38px * var(--ff-toolbar-scale, 1)); 
  border-radius: 50%; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  transition: all 0.3s ease; 
  position: relative; 
  cursor: pointer;
  pointer-events: auto !important; /* CRITICAL FIX: Ensure individual icons are always clickable */
  z-index: 1; /* CRITICAL FIX: Ensure icons are above any potential overlays within iconbar */
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  appearance: none;
  -webkit-appearance: none;
}
.barIconContainer.disabled,
.barIconContainer:disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }
.barIconContainer:hover:not(.disabled):not(:disabled) { 
    background: rgba(0, 0, 0, 0.08); /* Dark hover for light mode */
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
}
.barIconContainer.active {
    background: #000;
    transform: scale(1.15);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    border-radius: 50%;
}
.barIconContainer.active .barIcon {
    filter: brightness(0) invert(1);
}
.barIconContainer.toolbar-variant {
  position: relative;
  /* Smooth transition for border-radius and background when opening */
  transition: border-radius 0.25s cubic-bezier(0.4, 0, 0.2, 1), 
              background 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.barIconContainer.toolbar-variant::after {
  content: '';
  position: absolute;
  bottom: calc(5px * var(--ff-toolbar-scale, 1));
  right: calc(4px * var(--ff-toolbar-scale, 1));
  width: 0;
  height: 0;
  border-radius: 0;
  /* Triangle pointing right - dark grey for light mode */
  border-top: calc(3.5px * var(--ff-toolbar-scale, 1)) solid transparent;
  border-bottom: calc(3.5px * var(--ff-toolbar-scale, 1)) solid transparent;
  border-left: calc(5px * var(--ff-toolbar-scale, 1)) solid var(--ff-ui-text-muted);
  background: transparent;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
  opacity: 0.85;
  transition: opacity 0.2s ease, transform 0.2s ease, filter 0.2s ease;
}
/* First-time glow animation for variant indicator */
@keyframes variantTriangleGlow {
  0%, 100% { filter: drop-shadow(0 0 3px rgba(60, 60, 60, 0.6)); }
  50% { filter: drop-shadow(0 0 8px rgba(100, 100, 100, 0.8)) drop-shadow(0 0 12px rgba(60, 60, 60, 0.4)); }
}
.barIconContainer.toolbar-variant.first-time-glow::after {
  animation: variantTriangleGlow 1.5s ease-in-out 3;
}
.barIconContainer.toolbar-variant.variants-open::after,
.barIconContainer.toolbar-variant:hover::after {
  opacity: 1;
  border-left-color: var(--ff-ui-text);
  transform: scale(1.2);
  filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.3));
}
.barIconContainer.toolbar-variant.variants-open {
  background: var(--ff-ui-surface-soft);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--ff-ui-border);
  /* Left side rounded, right side connects to menu extension */
  border-radius: 999px 0 0 999px;
  overflow: visible;
  z-index: 100001;
  box-shadow: var(--ff-ui-float-shadow);
}

.toolbar-variant-menu {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 6px;
  /* Position flush with icon's right edge for seamless extension */
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background: var(--ff-ui-surface-soft);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--ff-ui-border);
  border-left: none; /* Seamless connection */
  border-radius: 0 999px 999px 0;
  height: 100%;
  padding: 0 0 0 4px;
  /* Clip hidden when collapsed, animate max-width */
  max-width: 0;
  overflow: hidden;
  opacity: 1;
  /* NO transition by default - instant close for snappy feel */
  transition: none;
  z-index: 100002;
  pointer-events: auto;
  /* Subtle shadow for depth */
  box-shadow: var(--ff-ui-float-shadow);
  margin-left: 0;
}
.toolbar-variant-menu.visible {
  max-width: 350px;
  padding: 0 12px 0 6px;
  /* Fast open animation only when visible - close is instant */
  transition: max-width 0.15s cubic-bezier(0.4, 0, 0.2, 1), 
              padding 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Ensure tooltips appear above variant menus for variant tools */
.barIconContainer.toolbar-variant .tooltip {
  z-index: 100003 !important;
}

/* When variant menu is open, hide tooltip by default - show only after 1s hover via JS */
.barIconContainer.toolbar-variant.variants-open .tooltip {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transition: opacity 0.15s ease-out, visibility 0.15s ease-out !important;
}
/* Show main tooltip after 1s hover when menu is open (JS adds tooltip-show class) */
/* Position is set dynamically by JS to be at the right edge of the menu */
.barIconContainer.toolbar-variant.variants-open.tooltip-show .tooltip {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: none !important;
  transition: opacity 0.2s ease-in, visibility 0.2s ease-in !important;
}
.toolbar-variant-option {
  width: calc(36px * var(--ff-toolbar-scale, 1));
  height: calc(36px * var(--ff-toolbar-scale, 1));
  border-radius: 50%;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  /* Snappy, responsive transitions */
  transition: transform 0.08s ease-out, background 0.08s ease-out, box-shadow 0.08s ease-out;
  position: relative;
}
.toolbar-variant-option img {
  width: calc(20px * var(--ff-toolbar-scale, 1));
  height: calc(20px * var(--ff-toolbar-scale, 1));
  pointer-events: none;
  filter: var(--ff-ui-icon-filter);
}
/* Keep variant menu icons dark even when the parent tool is active */
.barIconContainer.active .toolbar-variant-menu .toolbar-variant-option img {
  filter: var(--ff-ui-icon-filter) !important;
}
.toolbar-variant-option:hover,
.toolbar-variant-option.hover {
  background: var(--ff-ui-hover-strong);
  transform: scale(1.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.toolbar-variant-option.active {
  background: var(--ff-ui-active);
  box-shadow: 0 0 0 2px var(--ff-ui-border-strong);
}
.toolbar-variant-option:active {
  transform: scale(0.92);
}

/* Floating tooltip for variant options - full tooltip positioned to the right of menu */
.variant-floating-tooltip {
  padding: 0;
  background: var(--ff-ui-surface);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  color: var(--ff-ui-text);
  border-radius: 12px;
  box-shadow: var(--ff-ui-float-shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease-out;
  min-width: 140px;
  max-width: 220px;
  overflow: hidden;
}
.variant-floating-tooltip.visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease-in;
}

.toolbar-variant-menu .toolbar-menu {
  position: static;
  transform: none;
  opacity: 1 !important;
  display: flex !important;
  flex-direction: column;
  gap: 4px;
  margin-left: 10px;
  padding-left: 12px;
  border-left: 1px solid var(--ff-ui-border);
  background: transparent;
  box-shadow: none;
}
.toolbar-variant-menu .toolbar-menu .thickness-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ff-ui-text-muted);
}
.toolbar-variant-menu .toolbar-menu .thickness-slider-wrap {
  width: 150px;
}
.toolbar-variant-menu .toolbar-menu .thickness-slider {
  width: 100%;
}
.toolbar-variant-menu .toolbar-menu .thickness-value {
  font-size: 11px;
  color: var(--ff-ui-text-muted);
}

@media (max-width: 768px) {
  .toolbar-variant-menu {
    flex-wrap: wrap;
    padding: 8px;
    gap: 6px;
    max-width: 280px;
  }
  .toolbar-variant-menu.visible {
    max-width: 280px;
  }
  .toolbar-variant-menu .toolbar-menu {
    border-left: none;
    margin-left: 0;
    padding-left: 0;
    width: 100%;
  }
  .toolbar-variant-menu .toolbar-menu .thickness-slider-wrap {
    width: 100%;
  }
}
.barIcon { width: calc(22px * var(--ff-toolbar-scale, 1)); height: calc(22px * var(--ff-toolbar-scale, 1)); transition: all 0.2s ease; filter: var(--ff-ui-icon-filter); display: block; }
.barIconContainer:hover .barIcon { transform: scale(1.1); filter: var(--ff-ui-icon-filter); }
.tooltip { 
  visibility: hidden; 
  opacity: 0; 
  position: absolute; 
  background: var(--ff-ui-surface);
  backdrop-filter: blur(20px) saturate(180%); 
  -webkit-backdrop-filter: blur(20px) saturate(180%); 
  color: var(--ff-ui-text);
  padding: 0; 
  border-radius: 12px; 
  font-size: 11px; 
  white-space: normal; 
  z-index: 100003 !important; 
  left: calc(100% + 12px); 
  top: 50%; 
  transform: translateY(-50%);
  transition: opacity 0.15s ease-out, visibility 0.15s ease-out; 
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease; 
  pointer-events: none; 
  display: none;
  min-width: 160px;
  max-width: 220px;
  box-shadow: var(--ff-ui-float-shadow);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}
/* Tooltip hover is intentionally disabled; tooltips are shown only via `.tooltip-show` (JS-controlled). */
.barIconContainer.tooltip-show .tooltip,
.barIconContainer.toolbar-variant.tooltip-show .tooltip {
  visibility: visible !important; 
  opacity: 1 !important; 
  display: block !important;
  transform: translateY(-50%) translateX(4px);
  transition: opacity 0.2s ease-in, visibility 0.2s ease-in !important;
}
.tooltip-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--ff-ui-text);
  padding: 12px 14px 8px 14px;
  border-bottom: 1px solid var(--ff-ui-border);
  letter-spacing: 0.2px;
  background: linear-gradient(to bottom, var(--ff-ui-hover), transparent);
}
.tooltip-desc {
  font-weight: 400;
  font-size: 11px;
  color: var(--ff-ui-text-muted);
  padding: 8px 14px;
  line-height: 1.5;
  white-space: normal;
  max-width: 200px;
}
.tooltip-shortcut {
  padding: 10px 14px 12px 14px;
  border-top: 1px solid var(--ff-ui-border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--ff-ui-text-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
  background: linear-gradient(to top, var(--ff-ui-hover), transparent);
}
.tooltip-shortcut kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 10px;
  background: var(--ff-ui-kbd-bg);
  border: 1px solid var(--ff-ui-kbd-border);
  border-radius: 12px;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--ff-ui-text);
  box-shadow: var(--ff-ui-kbd-shadow);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.15s ease;
}
.tooltip-shortcut kbd:hover {
  background: linear-gradient(to bottom, var(--ff-ui-hover-strong), var(--ff-ui-hover));
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1), 
              inset 0 1px 0 rgba(255, 255, 255, 0.9);
  border-color: rgba(0, 0, 0, 0.15);
}
#color-picker-container { position: relative; }
#color-picker { opacity: 0; position: absolute; width: 100%; height: 100%; cursor: pointer; }
#color-swatch { width: calc(22px * var(--ff-toolbar-scale, 1)); height: calc(22px * var(--ff-toolbar-scale, 1)); border-radius: 50%; border: 2px solid #888; }
    .crop-overlay { 
      position:absolute; 
      inset:0; 
      z-index:15; 
      pointer-events:none;
      /* CRITICAL FIX: Ensure crop overlay doesn't extend beyond canvas bounds */
      overflow: hidden;
      /* CRITICAL FIX: Ensure crop overlay never blocks iconbar */
      max-width: 100%;
      max-height: 100%;
    }
      /* Crop rectangle - FULLY rendered by Three.js for precision */
      .crop-rect {
        position:absolute;
        /* NO box-shadow - darkening is now rendered by Three.js overlay planes */
        box-shadow: none !important;
        pointer-events:auto; /* Interactive - DOM still handles drag logic */
        cursor: grab; /* Default to grab cursor - JS will override for handles */
        /* Make DOM rect invisible - just for hit detection */
        background: transparent !important;
        border: none !important;
      }
      /* DOM handles are HIDDEN - Three.js handles are used instead */
      .crop-rect .handle {
        display: none !important; /* Hidden - Three.js handles take over */
        position: absolute;
        width: 12px;
        height: 12px;
        border-radius: 0;
        border: 1px solid #555;
        background: #2b2b2b;
        box-shadow: none;
        pointer-events: none;
      }
      .crop-rect .handle.tl { left:-6px; top:-6px; cursor:nwse-resize; }
      .crop-rect .handle.tr { right:-6px; top:-6px; cursor:nesw-resize; }
      .crop-rect .handle.bl { left:-6px; bottom:-6px; cursor:nesw-resize; }
      .crop-rect .handle.br { right:-6px; bottom:-6px; cursor:nwse-resize; }
        .crop-rect .guides::after {
    left:0; right:0; top:33.33%; bottom:33.33%;
    border: none;
    border-top:1px dashed rgba(255,255,255,0.35);
    border-bottom:1px dashed rgba(255,255,255,0.35);
  }

  /* Inactive (handled by Three.js opacity changes) */
  .crop-rect.faded {
    border-color: transparent;
    box-shadow: none !important;
    pointer-events: none !important;
    cursor: default !important;
  }
  .crop-rect.faded .handle { 
    display: none !important;
  }
  .crop-rect .handle.hidden {
    display: none !important;
  }

/* Enhanced Color Wheel Styles - v2 with higher z-index */
.formas-color-wheel-v2 {
  position: absolute !important;
  z-index: 99999 !important;
  display: none !important;
  opacity: 0 !important;
  transform: scale(0.95) translateY(-4px) !important;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
  pointer-events: none !important;
  isolation: isolate !important;
}

.formas-color-wheel-v2.formas-wheel-visible {
  display: block !important;
  opacity: 1 !important;
  transform: scale(1) translateY(0) !important;
  pointer-events: auto !important;
}

.formas-wheel-container-v2 {
  background: rgba(20, 24, 33, 0.45) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  border: 2px solid rgba(255, 255, 255, 0.15) !important;
  border-radius: 50% !important;
  padding: 8px !important;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5) !important;
  width: 200px !important;
  height: 200px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  pointer-events: auto !important;
  position: relative !important;
  z-index: 99999 !important;
}

.formas-wheel-svg-v2 {
  width: 100% !important;
  height: 100% !important;
  border-radius: 50% !important;
  overflow: visible !important;
  pointer-events: auto !important;
  position: relative !important;
  z-index: 99999 !important;
}

.formas-color-segment-v2 {
  cursor: pointer !important;
  transition: all 0.15s ease-out !important;
  stroke-linejoin: round !important;
  stroke-linecap: round !important;
  pointer-events: all !important;
  fill-opacity: 1 !important;
  stroke-opacity: 1 !important;
}

/* Enhanced Color Segment States - v2 */
.formas-color-segment-v2:active {
  transform: scale(0.98) !important;
  filter: brightness(1.25) drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5)) !important;
}

.formas-segment-compressed-v2 {
  filter: brightness(0.8) opacity(0.7) !important;
  transform: scale(0.95) !important;
}

.formas-segment-expanded-v2 {
  filter: brightness(1.2) drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4)) !important;
  transform: scale(1.05) !important;
}

/* iPad and touch optimizations */
@media (max-width: 1024px) {
  .color-wheel-container {
    width: 180px !important;
    height: 180px !important;
    padding: 6px !important;
  }
  
  .color-segment {
    stroke-width: 1 !important;
  }
  
  .color-segment:hover,
  .color-segment.expanded {
    transform: scale(1.08) !important;
  }
  
  .color-segment.compressed {
    transform: scale(0.92) !important;
  }

  /* Enhanced toolbar for touch - match global 20% scale */
  #iconBar {
    padding: calc(8px * var(--ff-toolbar-scale, 1)) !important;
    gap: calc(8px * var(--ff-toolbar-scale, 1)) !important;
  }

  .barIconContainer {
    width: calc(38px * var(--ff-toolbar-scale, 1)) !important;
    height: calc(38px * var(--ff-toolbar-scale, 1)) !important;
    border-radius: 50%;
  }

  .barIcon {
    width: calc(22px * var(--ff-toolbar-scale, 1)) !important;
    height: calc(22px * var(--ff-toolbar-scale, 1)) !important;
  }

  /* Hide tooltips on iPad/tablet - they block too much of the screen */
  .tooltip {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
  
  .barIconContainer.tooltip-show .tooltip,
  .barIconContainer:hover .tooltip {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  /* Enhanced sliders for touch - 20% smaller on mobile */
  .toolbar-menu {
    min-width: 176px !important; /* 20% smaller width */
    padding: 13px !important; /* 20% smaller padding */
    border-radius: 13px !important; /* 20% smaller border radius */
    /* Position closer to toolbar for seamless feel */
    margin-left: -6px !important; /* 20% smaller margin */
    /* Account for safe areas when positioning */
    left: calc(env(safe-area-inset-left, 0px)) !important;
  }

  .thickness-slider-wrap {
    gap: 10px !important; /* 20% smaller gap between elements */
    margin: 6px 0 !important; /* 20% smaller margin */
  }

  .thickness-slider {
    height: 6px !important; /* 20% smaller track height */
    border-radius: 3px !important; /* 20% smaller border radius */
    flex: 1;
    min-width: 112px !important; /* 20% smaller minimum width */
  }

  /* Thumb styling handled by ff-slider.css */

  .thickness-label {
    font-size: 11px !important; /* 20% smaller text */
    margin-bottom: 8px !important; /* 20% smaller margin */
  }

  .thickness-value {
    font-size: 11px !important; /* 20% smaller text */
    min-width: 26px !important; /* 20% smaller minimum width */
    padding: 3px 6px !important; /* 20% smaller padding */
  }
}

/* Mobile optimizations - 20% smaller */
@media (max-width: 768px) {
  .color-wheel-container {
    width: 128px !important; /* 20% smaller */
    height: 128px !important; /* 20% smaller */
    padding: 3px !important; /* 20% smaller */
  }
  
  .color-segment {
    stroke-width: 1.2px !important; /* 20% smaller */
  }

  /* iPhone safe area support for icon bar positioning */
  #iconBar:not(.dragged):not(.dragging) {
    /* Account for iPhone navigation bar and safe areas */
    left: calc(16px + env(safe-area-inset-left, 0px)) !important;
    top: calc(50% + env(safe-area-inset-top, 0px) / 2) !important;
    /* Adjust for bottom safe area to keep centered */
    transform: translateY(calc(-50% - var(--ff-toolbar-offset, 0px) - env(safe-area-inset-bottom, 0px) / 4)) !important;
  }

  #iconBar .barIconContainer:not([data-essential="true"]),
  #iconBar .iconbar-separator {
    max-height: 60px;
    opacity: 1;
    transform: scale(1);
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out, transform 0.3s ease-in-out, margin 0.3s ease-in-out;
    overflow: hidden;
  }

  #iconBar.ff-toolbar-collapsed .barIconContainer:not([data-essential="true"]),
  #iconBar.ff-toolbar-collapsed .iconbar-separator {
    max-height: 0;
    opacity: 0;
    transform: scale(0.9);
    margin: 0;
    pointer-events: none;
  }

  #iconBar.ff-toolbar-collapsed .toolbar-expand-toggle,
  #iconBar.ff-toolbar-expanded .toolbar-expand-toggle {
    display: flex !important;
  }

  /* Hide bottom drag handle when collapsed — removes blank gap */
  #iconBar.ff-toolbar-collapsed .ff-drag-handle-bottom {
    display: none;
  }

  #iconBar.ff-toolbar-collapsed .toolbar-expand-toggle {
    margin-top: 0;
    padding: calc(2px * var(--ff-toolbar-scale, 1)) 0;
  }
}

/* Tablet touch compact toolbar behavior (iPad incl. landscape widths) */
@media (max-width: 1366px) and (pointer: coarse) {
  #iconBar .barIconContainer:not([data-essential="true"]),
  #iconBar .iconbar-separator {
    max-height: 60px;
    opacity: 1;
    transform: scale(1);
    transition: max-height 0.35s cubic-bezier(0.34, 1.3, 0.64, 1),
                opacity 0.25s ease-out,
                transform 0.3s cubic-bezier(0.34, 1.3, 0.64, 1),
                margin 0.3s cubic-bezier(0.34, 1.3, 0.64, 1),
                padding 0.3s cubic-bezier(0.34, 1.3, 0.64, 1);
    overflow: hidden;
  }

  #iconBar.ff-toolbar-collapsed .barIconContainer:not([data-essential="true"]),
  #iconBar.ff-toolbar-collapsed .iconbar-separator {
    max-height: 0;
    opacity: 0;
    transform: scale(0.8);
    margin: 0;
    padding: 0;
    pointer-events: none;
  }

  #iconBar.ff-toolbar-collapsed .toolbar-expand-toggle,
  #iconBar.ff-toolbar-expanded .toolbar-expand-toggle {
    display: flex !important;
  }

  /* Hide bottom drag handle when collapsed — removes blank gap below last icon */
  #iconBar.ff-toolbar-collapsed .ff-drag-handle-bottom {
    display: none;
  }

  /* Tighten expand toggle spacing when collapsed */
  #iconBar.ff-toolbar-collapsed .toolbar-expand-toggle {
    margin-top: 0;
    padding: calc(2px * var(--ff-toolbar-scale, 1)) 0;
  }
}

/* Additional iPhone landscape support */
@media (max-width: 768px) and (orientation: landscape) {
  #iconBar:not(.dragged):not(.dragging) {
    /* In landscape, safe areas are more prominent on sides */
    left: calc(20px + env(safe-area-inset-left, 0px)) !important;
    /* Less top adjustment needed in landscape */
    top: calc(50% + env(safe-area-inset-top, 0px) / 4) !important;
    transform: translateY(calc(-50% - var(--ff-toolbar-offset, 0px) - env(safe-area-inset-bottom, 0px) / 6)) !important;
  }
}

/* Combined Brush Sliders Styles */
.toolbar-menu {
  background: rgba(20, 24, 33, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 
              0 0 0 1px rgba(255, 255, 255, 0.1),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: opacity 0.15s ease, visibility 0.15s ease;
  position: absolute;
  opacity: 0;
  visibility: hidden;
  transform: none;
  pointer-events: none;
  z-index: 10000; /* increased to sit above other UI */
  min-width: 180px;
}

/* ==========================================================================
   Freeform thickness popovers - match right-click context menu visual system
   (Keep .toolbar-menu behavior/positioning; only replace the look)
   ========================================================================== */

#brushSlidersContainer.ff-thickness-menu,
#lineThicknessSlider.ff-thickness-menu,
#eraserSlidersContainer.ff-thickness-menu {
  background: rgba(20,24,33,0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.30);
  padding: 8px 10px;
  min-width: 200px;
}

#brushSlidersContainer.ff-thickness-menu:hover,
#lineThicknessSlider.ff-thickness-menu:hover,
#eraserSlidersContainer.ff-thickness-menu:hover {
  background: rgba(20,24,33,0.45);
  border-color: rgba(255,255,255,0.10);
  box-shadow: 0 10px 24px rgba(0,0,0,0.30);
}

/* Eraser Slider Specific Styling */
#eraserSlidersContainer.ff-eraser-menu {
  min-width: 240px;
}

#eraserSlidersContainer.ff-eraser-menu .ff-eraser-icon {
  flex-shrink: 0;
  margin-right: 2px;
}

/* White icon circle for visibility */
#eraserSlidersContainer.ff-eraser-menu .ff-eraser-icon circle {
  stroke: rgba(255, 255, 255, 0.9);
}

/* White label text for visibility */
#eraserSlidersContainer.ff-eraser-menu .ff-slider-label--eraser {
  color: rgba(255, 255, 255, 0.9);
}

/* Thumb styling handled by ff-slider.css */

#eraserSlidersContainer.ff-eraser-menu .ff-slider-value--eraser {
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255, 255, 255, 0.20);
  color: rgba(255, 255, 255, 0.92);
}

.ff-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.ff-popover-title {
  color: rgba(255, 255, 255, 0.9);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0;
}

.ff-popover-close {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: rgba(255, 255, 255, 0.92);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.ff-popover-close:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.20);
  transform: translateY(-1px);
}

.ff-popover-close:active {
  transform: translateY(0);
}

.ff-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.ff-slider-row.ff-slider-row--pill {
  width: 100%;
}

.ff-slider-label {
  width: auto;
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 650;
  color: rgba(255, 255, 255, 0.9);
  text-transform: none;
  letter-spacing: 0.2px;
  margin: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.ff-slider-control {
  flex: 1;
  min-width: 100px;
}

#brushSlidersContainer.ff-thickness-menu .thickness-slider,
#lineThicknessSlider.ff-thickness-menu .thickness-slider,
#eraserSlidersContainer.ff-thickness-menu .thickness-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.25);
  outline: none;
  cursor: pointer;
}

#brushSlidersContainer.ff-thickness-menu .thickness-slider:hover,
#lineThicknessSlider.ff-thickness-menu .thickness-slider:hover,
#eraserSlidersContainer.ff-thickness-menu .thickness-slider:hover {
  background: rgba(255,255,255,0.35);
}

/* Thumb styling handled by ff-slider.css */

#brushSlidersContainer.ff-thickness-menu .thickness-value,
#lineThicknessSlider.ff-thickness-menu .thickness-value,
#eraserSlidersContainer.ff-thickness-menu .thickness-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.20);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Inline polyline actions — compact chips, hidden by default via JS when not relevant */
.ff-line-actions {
  display: none;
  align-items: center;
  gap: 6px;
  margin-left: 2px;
}

/* High-specificity styling so these never fall back to default browser buttons */
#lineThicknessSlider.ff-thickness-menu .ff-line-actions .ff-line-action-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.08);
  color: rgba(241, 245, 249, 0.92);
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

#lineThicknessSlider.ff-thickness-menu .ff-line-actions .ff-line-action-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.24);
  transform: translateY(-1px);
}

#lineThicknessSlider.ff-thickness-menu .ff-line-actions .ff-line-action-btn:active:not(:disabled) {
  transform: translateY(0);
}

#lineThicknessSlider.ff-thickness-menu .ff-line-actions .ff-line-action-btn.inactive {
  opacity: 0.55;
}

#lineThicknessSlider.ff-thickness-menu .ff-line-actions .ff-line-action-btn:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

.ff-line-action-ico {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.92;
  flex: 0 0 auto;
}

.ff-line-action-ico svg {
  display: block;
}

.ff-line-action-text {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.ff-popover-close.ff-popover-close--tiny {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  font-size: 12px;
}

.ff-popover-close.ff-popover-close--tiny svg {
  display: block;
}

/* Specific styling for combined brush sliders container */
#brushSlidersContainer {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 0;
  pointer-events: auto !important; /* Ensure sliders container is interactive */
}

#brushSlidersContainer .thickness-label {
  margin: 0 0 4px 0;
  font-size: 10px;
}

#brushSlidersContainer .thickness-slider-wrap {
  margin-bottom: 4px;
}

/* Ensure sliders are always interactive */
#brushSlidersContainer input[type="range"],
#brushSlidersContainer .thickness-slider {
  pointer-events: auto !important;
  cursor: pointer !important;
}

.toolbar-menu.visible {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
}

/* Cursor-positioned panels appear instantly without transform animation */
.toolbar-menu.cursor-positioned {
  transition: opacity 0.1s ease, visibility 0.1s ease;
  transform: none !important;
}

.toolbar-menu:hover {
  background: rgba(20, 24, 33, 0.45);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.thickness-label {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  margin: 0 0 8px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.thickness-slider-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.thickness-slider {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

/* Thumb styling handled by ff-slider.css */

.thickness-slider::-webkit-slider-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  height: 4px;
}

.thickness-slider::-moz-range-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  height: 4px;
  border: none;
}

.thickness-value {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  min-width: 24px;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}


/* Brush Preview Styles */
#brushPreview {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  pointer-events: none;
}

#brushPreview.visible {
  opacity: 1;
  visibility: visible;
}

.brush-preview-window {
  background: rgba(20, 24, 33, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.brush-preview-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.brush-preview-text {
  font-size: 10px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Delete Confirmation Pill - Pure Pill Style */
.delete-confirmation-pill {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.delete-confirmation-pill.active {
  opacity: 1;
}

.confirm-pill-container {
  background: linear-gradient(135deg, rgba(18, 22, 30, 0.88) 0%, rgba(24, 28, 36, 0.85) 100%);
  border: 1.5px solid rgba(255,255,255,0.18);
  border-radius: 999px; /* Pure pill - fully rounded */
  padding: 20px 32px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5), 0 2px 16px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  display: flex;
  align-items: center;
  gap: 20px;
  min-width: 420px;
  max-width: 90vw;
  animation: slideUpScale 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUpScale {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.confirm-pill-icon {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}

.confirm-pill-text {
  flex: 1;
  min-width: 0;
}

.confirm-pill-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.95);
  letter-spacing: 0.8px;
  margin-bottom: 4px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.confirm-pill-subtitle {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.confirm-pill-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.confirm-pill-btn {
  padding: 8px 20px;
  border-radius: 999px; /* Pure pill buttons */
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1.5px solid;
  outline: none;
  white-space: nowrap;
}

.confirm-no {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.9);
  border-color: rgba(255, 255, 255, 0.2);
}

.confirm-no:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.35);
  transform: scale(1.05);
}

.confirm-yes {
  background: linear-gradient(135deg, rgba(255, 80, 80, 0.25) 0%, rgba(220, 50, 50, 0.25) 100%);
  color: rgba(255, 120, 120, 1);
  border-color: rgba(255, 100, 100, 0.5);
  box-shadow: 0 4px 12px rgba(255, 70, 70, 0.2);
}

.confirm-yes:hover {
  background: linear-gradient(135deg, rgba(255, 90, 90, 0.35) 0%, rgba(235, 60, 60, 0.35) 100%);
  border-color: rgba(255, 120, 120, 0.7);
  color: rgba(255, 140, 140, 1);
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(255, 70, 70, 0.3);
}

.confirm-pill-btn:active {
  transform: scale(0.98);
}

/* ============================================================================
   PERFORMANCE OPTIMIZED STYLES - Moved from inline JS (v1.6.0)
   ============================================================================ */

/* Loading spinner animation */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes glowPulse {
  0%, 100% { 
    box-shadow: 0 0 8px rgba(100, 100, 255, 0.3), 
                0 0 16px rgba(100, 100, 255, 0.15),
                0 6px 20px rgba(0,0,0,0.4);
  }
  50% { 
    box-shadow: 0 0 12px rgba(100, 100, 255, 0.5), 
                0 0 24px rgba(100, 100, 255, 0.25),
                0 6px 20px rgba(0,0,0,0.4);
  }
}

/* Toolbar menu line slider specific styles */
.toolbar-menu.line-slider-floating {
  min-width: 200px !important;
}

.toolbar-menu.touch-pointer {
  min-width: 210px !important;
}

.toolbar-line-actions {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 6px !important;
  margin-top: 0 !important;
  width: auto !important;
}

.toolbar-line-actions button {
  flex: 0 0 auto !important;
  min-width: 0 !important;
  height: 22px !important;
  padding: 0 10px !important;
  font-size: 11px !important;
  border-radius: 999px !important;
  border: 1px solid rgba(255,255,255,0.16) !important;
  background: rgba(255,255,255,0.08) !important;
  color: rgba(241, 245, 249, 0.92) !important;
  font-weight: 600 !important;
  text-align: center !important;
  letter-spacing: 0.2px !important;
  cursor: pointer !important;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease !important;
}

.toolbar-line-actions button:hover:not(:disabled) {
  background: rgba(255,255,255,0.14) !important;
  border-color: rgba(255,255,255,0.24) !important;
  transform: translateY(-1px) !important;
}

.toolbar-line-actions button:disabled {
  opacity: 0.4 !important;
  cursor: default !important;
  transform: none !important;
}

.toolbar-line-actions button.inactive {
  opacity: 0.55 !important;
}

/* Brush thickness slider container styles */
#brushThicknessSlider {
  flex-direction: column !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 12px 8px !important;
  min-width: 180px !important;
}

/* Touch device enhancements (iPad, iPhone, touch devices) */
@media (pointer: coarse) {
  .thickness-slider {
    height: 8px !important;
  }
  /* Thumb styling handled by ff-slider.css */

  /* Hide ALL tooltips on touch devices - they block interaction */
  .tooltip,
  .toolbar-variant-option::after {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
  
  .barIconContainer.tooltip-show .tooltip,
  .barIconContainer:hover .tooltip,
  .barIconContainer.toolbar-variant.tooltip-show .tooltip,
  .barIconContainer.toolbar-variant:hover .tooltip,
  .toolbar-variant-option:hover::after {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  /* Touch-first target sizes (Apple Pencil + finger ergonomics). */
  #iconBar .barIconContainer {
    width: max(44px, calc(38px * var(--ff-toolbar-scale, 1))) !important;
    height: max(44px, calc(38px * var(--ff-toolbar-scale, 1))) !important;
  }

  #iconBar .barIcon {
    width: max(24px, calc(22px * var(--ff-toolbar-scale, 1))) !important;
    height: max(24px, calc(22px * var(--ff-toolbar-scale, 1))) !important;
  }

  .ff-top-pill {
    touch-action: manipulation !important;
    min-height: 44px !important;
  }

  #canvasTopMenuToggle,
  #canvasHeaderToggleBtn,
  #closeStudioBtn,
  #canvasMenuBtn {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  #canvasHeaderToggleBtn,
  #closeStudioBtn {
    width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
  }

  body.workspace-mode[data-active-module="freeform"].ff-freeform-header-collapsed #canvasSidebarToggleBtn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    margin-right: 10px !important;
  }

  #canvasPills {
    top: calc(12px + env(safe-area-inset-top, 0px)) !important;
    right: calc(12px + env(safe-area-inset-right, 0px)) !important;
  }

  #canvasPillsLeft {
    top: calc(12px + env(safe-area-inset-top, 0px)) !important;
    left: calc(12px + env(safe-area-inset-left, 0px)) !important;
  }
}

/* Additional check: devices that don't support hover (iOS, touch-only) */
@media (hover: none) {
  .tooltip,
  .toolbar-variant-option::after {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
  
  .barIconContainer.tooltip-show .tooltip,
  .barIconContainer:hover .tooltip,
  .barIconContainer.toolbar-variant.tooltip-show .tooltip,
  .barIconContainer.toolbar-variant:hover .tooltip,
  .toolbar-variant-option:hover::after {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
}

/* Zoom indicator hover state */
#zoomIndicator:hover {
  background: rgba(20,20,20,0.9) !important;
  transform: scale(1.05) !important;
}

/* Lock indicator hover state */
#lockIndicator:hover {
  transform: scale(1.05) !important;
}

#closeZoomSidebar:hover {
  background: rgba(255,255,255,0.1) !important;
}

#openInViewer:hover {
  transform: translateY(-1px) !important;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important;
}

#openInViewer:active {
  transform: translateY(0) !important;
}

/* Brush preview window additional styles */
.brush-preview-window {
  background: rgba(0, 0, 0, 0.3) !important;
}

.brush-preview-icon {
  display: block !important;
}

.brush-preview-text {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial !important;
}

/* Hide old top-right controls */
.canvas-controls { display: none !important; }

/* ── Light theme (explicit reset so dark→light never shows stale dark inline styles) ── */

.module-root[data-freeform-theme="light"] #canvasTopMenuToggle,
.module-root[data-freeform-theme="light"] #canvasHeaderToggleBtn,
.module-root[data-freeform-theme="light"] #closeStudioBtn,
.module-root[data-freeform-theme="light"] #qualityPill,
.module-root[data-freeform-theme="light"] #snapOrthoUnitsPill,
.module-root[data-freeform-theme="light"] #canvasTitlePill,
.module-root[data-freeform-theme="light"] #canvasMenuBtn,
.module-root[data-freeform-theme="light"] #autosavePill {
  background: rgba(255, 255, 255, 0.95) !important;
  border-color: rgba(0, 0, 0, 0.15) !important;
  color: #222 !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

.module-root[data-freeform-theme="light"] #snapOrthoUnitsPill {
  background: rgba(255, 255, 255, 0.5) !important;
}

.module-root[data-freeform-theme="light"] #autosavePill {
  background: transparent !important;
  box-shadow: none !important;
}

.module-root[data-freeform-theme="light"] #canvasMenuBtn {
  background: transparent !important;
  box-shadow: none !important;
}

.module-root[data-freeform-theme="light"] #canvasTopMenuToggle span:last-child {
  color: rgba(0, 0, 0, 0.55) !important;
}

.module-root[data-freeform-theme="light"] #closeStudioBtn svg,
.module-root[data-freeform-theme="light"] #qualityPill svg {
  stroke: #222 !important;
}

.module-root[data-freeform-theme="light"] #qualityPill .quality-label {
  color: rgba(0, 0, 0, 0.6) !important;
}

.module-root[data-freeform-theme="light"] #qualityPill #brainIcon,
.module-root[data-freeform-theme="light"] .dropdown-brain-icon {
  filter: brightness(0) !important;
}

.module-root[data-freeform-theme="light"] #snapOrthoUnitsPill .snap-ortho-section {
  color: #666 !important;
}

.module-root[data-freeform-theme="light"] #snapOrthoUnitsPill .snap-ortho-divider {
  background: rgba(0, 0, 0, 0.1) !important;
}

.module-root[data-freeform-theme="light"] #canvasMenuBtn svg {
  stroke: #222 !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown,
.module-root[data-freeform-theme="light"] #managerDropdown {
  background: rgba(255, 255, 255, 0.98) !important;
  border-color: rgba(0, 0, 0, 0.1) !important;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.2) !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option,
.module-root[data-freeform-theme="light"] #managerDropdown .manager-option {
  color: #222 !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown #draftLabel,
.module-root[data-freeform-theme="light"] #qualityDropdown #goodLabel,
.module-root[data-freeform-theme="light"] #qualityDropdown #highLabel,
.module-root[data-freeform-theme="light"] #qualityDropdown #maxLabel {
  color: #222 !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown #draftLabel span,
.module-root[data-freeform-theme="light"] #qualityDropdown #goodLabel span,
.module-root[data-freeform-theme="light"] #qualityDropdown #highLabel span,
.module-root[data-freeform-theme="light"] #qualityDropdown #maxLabel span {
  color: rgba(0, 0, 0, 0.4) !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown #draftLabel + div,
.module-root[data-freeform-theme="light"] #qualityDropdown #goodDescription,
.module-root[data-freeform-theme="light"] #qualityDropdown #highDescription,
.module-root[data-freeform-theme="light"] #qualityDropdown #maxDescription,
.module-root[data-freeform-theme="light"] #qualityDropdown #flux2Description {
  color: rgba(0, 0, 0, 0.5) !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown .quality-credit {
  color: rgba(0, 0, 0, 0.6) !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected > div,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #draftLabel,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #goodLabel,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #highLabel,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #maxLabel {
  color: #ffffff !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #draftLabel span,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #goodLabel span,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #highLabel span,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #maxLabel span {
  color: rgba(255, 255, 255, 0.74) !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #draftDescription,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #goodDescription,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #highDescription,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #maxDescription,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected #flux2Description,
.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected .quality-credit {
  color: rgba(255, 255, 255, 0.84) !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown .quality-option.is-selected img {
  filter: brightness(0) invert(1) !important;
  opacity: 0.9 !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown #flux2Separator {
  background: linear-gradient(90deg, transparent, rgba(100, 100, 100, 0.3), transparent) !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown #flux2ToggleRow {
  background: rgba(60, 60, 60, 0.1) !important;
  border-color: rgba(100, 100, 100, 0.2) !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown #flux2ToggleRow > div > div:first-child {
  color: #222 !important;
}

.module-root[data-freeform-theme="light"] #qualityDropdown #flux2ProBadge {
  color: rgba(80, 80, 80, 1) !important;
  background: rgba(100, 100, 100, 0.15) !important;
}

.module-root[data-freeform-theme="light"] #managerDropdown .manager-option > div > div > div:first-child {
  color: #222 !important;
}

.module-root[data-freeform-theme="light"] #managerDropdown .manager-option > div > div > div:last-child,
.module-root[data-freeform-theme="light"] #managerDropdown .manager-option span {
  color: rgba(0, 0, 0, 0.5) !important;
}

.module-root[data-freeform-theme="light"] #managerDropdown .manager-option svg {
  stroke: rgba(0, 0, 0, 0.7) !important;
}

.module-root[data-freeform-theme="light"] #managerDropdown > div[style*="height:1px"] {
  background: rgba(0, 0, 0, 0.08) !important;
}

.module-root[data-freeform-theme="light"] #iconBar {
  background: rgba(255, 255, 255, 0.95) !important;
  border: 1px solid rgba(0, 0, 0, 0.12) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12) !important;
}

.module-root[data-freeform-theme="light"] .barIcon {
  filter: brightness(0) !important;
}

.module-root[data-freeform-theme="light"] .barIconContainer.active {
  background: rgba(0, 0, 0, 0.08) !important;
}

.module-root[data-freeform-theme="light"] .barIconContainer.active .barIcon {
  filter: brightness(0) !important;
}

/* Dark theme integration (triggered by background mode = dark) */
.module-root[data-freeform-theme="dark"] #iconBar {
  background: rgba(18, 18, 22, 0.92) !important;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
  box-shadow:
    0 10px 34px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 0 rgba(0, 0, 0, 0.35) !important;
}

.module-root[data-freeform-theme="dark"] #iconBar .toolbar-expand-arrow {
  border-right: 2px solid rgba(238, 241, 247, 0.82);
  border-bottom: 2px solid rgba(238, 241, 247, 0.82);
}

.module-root[data-freeform-theme="dark"] .iconbar-separator {
  background: rgba(255, 255, 255, 0.16);
}

.module-root[data-freeform-theme="dark"] .ff-drag-handle-pill {
  background: rgba(255, 255, 255, 0.25);
}
.module-root[data-freeform-theme="dark"] .ff-drag-handle:active .ff-drag-handle-pill,
.module-root[data-freeform-theme="dark"] #iconBar.ff-toolbar-dragging .ff-drag-handle-pill {
  background: rgba(255, 255, 255, 0.45);
}

.module-root[data-freeform-theme="dark"] .barIcon {
  filter: brightness(0) invert(1) !important;
}

.module-root[data-freeform-theme="dark"] .barIconContainer:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.module-root[data-freeform-theme="dark"] .barIconContainer.active {
  background: rgba(238, 241, 247, 0.2);
}

.module-root[data-freeform-theme="dark"] .barIconContainer.active .barIcon {
  filter: brightness(0) invert(1) !important;
}

.module-root[data-freeform-theme="dark"] .barIconContainer.toolbar-variant::after {
  border-left-color: rgba(238, 241, 247, 0.75);
  filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.4));
}

.module-root[data-freeform-theme="dark"] .barIconContainer.toolbar-variant.variants-open::after,
.module-root[data-freeform-theme="dark"] .barIconContainer.toolbar-variant:hover::after {
  border-left-color: rgba(238, 241, 247, 0.95);
}

.module-root[data-freeform-theme="dark"] .barIconContainer.toolbar-variant.variants-open,
.module-root[data-freeform-theme="dark"] .toolbar-variant-menu {
  background: rgba(18, 18, 22, 0.92);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow:
    0 8px 26px rgba(0, 0, 0, 0.48),
    0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.module-root[data-freeform-theme="dark"] .toolbar-variant-option:hover,
.module-root[data-freeform-theme="dark"] .toolbar-variant-option.hover {
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.module-root[data-freeform-theme="dark"] .toolbar-variant-option.active {
  background: rgba(238, 241, 247, 0.2);
  box-shadow: 0 0 0 2px rgba(238, 241, 247, 0.3);
}

.module-root[data-freeform-theme="dark"] .toolbar-variant-option img,
.module-root[data-freeform-theme="dark"] .barIconContainer.active .toolbar-variant-menu .toolbar-variant-option img {
  filter: brightness(0) invert(1) !important;
}

.module-root[data-freeform-theme="dark"] .toolbar-variant-menu .toolbar-menu {
  border-left: 1px solid rgba(255, 255, 255, 0.14);
}

.module-root[data-freeform-theme="dark"] .toolbar-variant-menu .toolbar-menu .thickness-label {
  color: rgba(238, 241, 247, 0.72);
}

.module-root[data-freeform-theme="dark"] .toolbar-variant-menu .toolbar-menu .thickness-value {
  color: rgba(238, 241, 247, 0.78);
}

.module-root[data-freeform-theme="dark"] .tooltip,
.module-root[data-freeform-theme="dark"] .variant-floating-tooltip {
  background: rgba(18, 18, 22, 0.95);
  color: #eef1f7;
  box-shadow:
    0 10px 36px rgba(0, 0, 0, 0.52),
    0 0 0 1px rgba(255, 255, 255, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.module-root[data-freeform-theme="dark"] .tooltip-title {
  color: #eef1f7;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.06), transparent);
}

.module-root[data-freeform-theme="dark"] .tooltip-desc,
.module-root[data-freeform-theme="dark"] .tooltip-shortcut {
  color: rgba(238, 241, 247, 0.74);
}

.module-root[data-freeform-theme="dark"] .tooltip-shortcut {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(to top, rgba(255, 255, 255, 0.05), transparent);
}

.module-root[data-freeform-theme="dark"] .tooltip-shortcut kbd {
  color: #eef1f7;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.module-root[data-freeform-theme="dark"] #canvasTopMenuToggle,
.module-root[data-freeform-theme="dark"] #canvasHeaderToggleBtn,
.module-root[data-freeform-theme="dark"] #closeStudioBtn,
.module-root[data-freeform-theme="dark"] #qualityPill,
.module-root[data-freeform-theme="dark"] #snapOrthoUnitsPill,
.module-root[data-freeform-theme="dark"] #canvasTitlePill,
.module-root[data-freeform-theme="dark"] #canvasMenuBtn,
.module-root[data-freeform-theme="dark"] #autosavePill {
  background: rgba(18, 18, 22, 0.92) !important;
  border-color: rgba(255, 255, 255, 0.18) !important;
  color: #eef1f7 !important;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45) !important;
}

.module-root[data-freeform-theme="dark"] #canvasTopMenuToggle span:last-child {
  color: rgba(238, 241, 247, 0.68) !important;
}

.module-root[data-freeform-theme="dark"] #closeStudioBtn svg,
.module-root[data-freeform-theme="dark"] #qualityPill svg {
  stroke: #eef1f7 !important;
}

.module-root[data-freeform-theme="dark"] #qualityPill .quality-label {
  color: rgba(238, 241, 247, 0.68) !important;
}

.module-root[data-freeform-theme="dark"] #qualityPill #brainIcon,
.module-root[data-freeform-theme="dark"] .dropdown-brain-icon {
  filter: brightness(0) invert(1) !important;
}

.module-root[data-freeform-theme="dark"] #snapOrthoUnitsPill .snap-ortho-section {
  color: rgba(238, 241, 247, 0.65) !important;
}

.module-root[data-freeform-theme="dark"] #snapOrthoUnitsPill .snap-ortho-divider {
  background: rgba(255, 255, 255, 0.16) !important;
}

.module-root[data-freeform-theme="dark"] #canvasMenuBtn svg {
  stroke: #eef1f7 !important;
}

.module-root[data-freeform-theme="dark"] #qualityDropdown,
.module-root[data-freeform-theme="dark"] #managerDropdown {
  background: rgba(18, 18, 22, 0.97) !important;
  border-color: rgba(255, 255, 255, 0.18) !important;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45) !important;
}

.module-root[data-freeform-theme="dark"] #qualityDropdown .quality-option,
.module-root[data-freeform-theme="dark"] #managerDropdown .manager-option {
  color: #eef1f7 !important;
}

.module-root[data-freeform-theme="dark"] #qualityDropdown #draftLabel,
.module-root[data-freeform-theme="dark"] #qualityDropdown #goodLabel,
.module-root[data-freeform-theme="dark"] #qualityDropdown #highLabel,
.module-root[data-freeform-theme="dark"] #qualityDropdown #maxLabel {
  color: #eef1f7 !important;
}

.module-root[data-freeform-theme="dark"] #qualityDropdown #draftLabel span,
.module-root[data-freeform-theme="dark"] #qualityDropdown #goodLabel span,
.module-root[data-freeform-theme="dark"] #qualityDropdown #highLabel span,
.module-root[data-freeform-theme="dark"] #qualityDropdown #maxLabel span {
  color: rgba(238, 241, 247, 0.58) !important;
}

.module-root[data-freeform-theme="dark"] #qualityDropdown #draftLabel + div,
.module-root[data-freeform-theme="dark"] #qualityDropdown #goodDescription,
.module-root[data-freeform-theme="dark"] #qualityDropdown #highDescription,
.module-root[data-freeform-theme="dark"] #qualityDropdown #maxDescription,
.module-root[data-freeform-theme="dark"] #qualityDropdown #flux2Description {
  color: rgba(238, 241, 247, 0.68) !important;
}

.module-root[data-freeform-theme="dark"] #qualityDropdown .quality-credit {
  color: rgba(238, 241, 247, 0.68) !important;
}

.module-root[data-freeform-theme="dark"] #qualityDropdown #flux2Separator {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.24), transparent) !important;
}

.module-root[data-freeform-theme="dark"] #qualityDropdown #flux2ToggleRow {
  background: rgba(255, 255, 255, 0.08) !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
}

.module-root[data-freeform-theme="dark"] #qualityDropdown #flux2ToggleRow > div > div:first-child {
  color: #eef1f7 !important;
}

.module-root[data-freeform-theme="dark"] #qualityDropdown #flux2ProBadge {
  color: rgba(238, 241, 247, 0.8) !important;
  background: rgba(255, 255, 255, 0.14) !important;
}

.module-root[data-freeform-theme="dark"] #managerDropdown .manager-option > div > div > div:first-child {
  color: #eef1f7 !important;
}

.module-root[data-freeform-theme="dark"] #managerDropdown .manager-option > div > div > div:last-child,
.module-root[data-freeform-theme="dark"] #managerDropdown .manager-option span {
  color: rgba(238, 241, 247, 0.68) !important;
}

.module-root[data-freeform-theme="dark"] #managerDropdown .manager-option svg {
  stroke: rgba(238, 241, 247, 0.86) !important;
}

.module-root[data-freeform-theme="dark"] #managerDropdown > div[style*="height:1px"] {
  background: rgba(255, 255, 255, 0.14) !important;
}

/* Toolbar menu variant inline */
.toolbar-menu.variant-inline {
  position: static !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  width: 100% !important;
  opacity: 1 !important;
  transform: none !important;
  background: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  margin-top: 8px !important;
  gap: 8px !important;
}

/* Phone: reduce top pills by 25% */
@media (max-width: 768px) {
  body.workspace-mode[data-active-module="freeform"] .chat-container.workspace-active {
    height: 100vh !important;
    height: 100svh !important;
    min-height: 100vh !important;
    min-height: 100svh !important;
  }

  body.workspace-mode[data-active-module="freeform"]:not(.ff-freeform-header-collapsed) #canvasPills {
    top: calc(var(--topbar-height-mobile, 56px) + 10px + env(safe-area-inset-top, 0px)) !important;
  }

  body.workspace-mode[data-active-module="freeform"]:not(.ff-freeform-header-collapsed) #canvasPillsLeft {
    top: calc(var(--topbar-height-mobile, 56px) + 10px + env(safe-area-inset-top, 0px)) !important;
  }

  #canvasPills {
    gap: 6px !important;
    top: calc(12px + env(safe-area-inset-top, 0px)) !important;
    right: calc(12px + env(safe-area-inset-right, 0px)) !important;
  }

  #canvasPillsLeft {
    top: calc(12px + env(safe-area-inset-top, 0px)) !important;
    left: calc(12px + env(safe-area-inset-left, 0px)) !important;
    gap: 6px !important;
  }

  #closeStudioBtn {
    width: 27px !important;
    height: 27px !important;
  }

  #canvasHeaderToggleBtn {
    width: 27px !important;
    height: 27px !important;
  }

  #closeStudioBtn svg {
    width: 10px !important;
    height: 10px !important;
  }

  #canvasHeaderToggleBtn svg {
    width: 10px !important;
    height: 10px !important;
  }

  #qualityPill {
    padding: 6px 12px !important;
    border-radius: 12px !important;
    font-size: 9px !important;
    height: 27px !important;
    align-items: center !important;
  }

  #qualityPill #brainIcon {
    width: 10px !important;
    height: 10px !important;
  }

  #qualityPill svg {
    width: 7px !important;
    height: 7px !important;
  }

  #qualityPill .quality-label,
  #canvasTitlePill .canvas-title-label,
  #canvasTitlePill .canvas-title-icon {
    display: none !important;
  }

  #snapOrthoUnitsPill {
    display: none !important;
  }

  #snapOrthoUnitsPill .snap-ortho-section {
    padding: 6px 10px !important;
    font-size: 9px !important;
  }

  #canvasTitlePill {
    height: 27px !important;
    padding: 0 2px 0 12px !important;
    gap: 6px !important;
    font-size: 9px !important;
  }

  #canvasMenuBtn {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
  }

  #canvasMenuBtn svg {
    width: 10px !important;
    height: 10px !important;
  }

  #zoomIndicator,
  #lockIndicator {
    padding: 6px 10px !important;
    font-size: 9px !important;
  }

  #zoomIndicator svg,
  #lockIndicator svg {
    width: 10px !important;
    height: 10px !important;
  }

  #autosavePill {
    display: none !important;
  }
}
