#dexToolbarBtn {
  position: fixed;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--c-panel-2);
  color: var(--c-white);
  border: 1px solid color-mix(in srgb, var(--c-white) 08%, transparent);
  display: flex; align-items: center; justify-content: center;
  cursor: grab;
  z-index: 9997;
  
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  font-family: 'classy', sans-serif;
  padding: var(--btn-padding);
  box-sizing: border-box;
  transition: box-shadow 0.2s ease, transform 0.1s ease, border-color 0.2s ease;
}
#dexToolbarBtn:hover {
  border-color: color-mix(in srgb, var(--c-blue) 40%, transparent);
  
}
#dexToolbarBtn:active { cursor: grabbing; transform: scale(0.94); }
#dexToolbarBtn > * { pointer-events: none; }
#dexToolbarBtn.dragging {
  
  opacity: 0.85;
  border-color: var(--c-blue);
}

#dexCursorControls {
  position: fixed;
  z-index: 9996;
  width: 165px;
  height: 165px;
  border-radius: 50%;
  background: transparent;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
  padding: 0;
  transition: transform 0.15s ease, width 0.25s ease, height 0.25s ease;
}
body:has(.secondary-sidebar.open) #dexCursorControls,
body:has(#sidebar1.open) #dexCursorControls {
  display: none !important;
}
#dexCursorControls.dragging {
  cursor: grabbing;
  transform: scale(1.02);
}
#dexCursorControls > * { position: relative; z-index: 1; }

#dexCursorControls::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1.5px dashed color-mix(in srgb, var(--c-blue) 35%, transparent);
  background:
    radial-gradient(circle at 75% 25%,
      color-mix(in srgb, var(--c-blue) 18%, transparent) 0%,
      color-mix(in srgb, var(--c-blue) 06%, transparent) 35%,
      transparent 55%);
  pointer-events: none;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 0;
  
}
#dexCursorControls:not(.dpad-collapsed)::before {
  opacity: 1;
  transform: scale(1);
}
#dexCursorControls.dragging::before {
  border-color: color-mix(in srgb, var(--c-blue) 70%, transparent);
  
}

#dexCursorControls .dex-cursor-btn {
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--c-panel-2) 95%, transparent);
  border: none;
  color: var(--c-white);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
  margin: 0;
  transition: background 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), color 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  
}
#dexCursorControls .dex-cursor-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c-white) 12%, transparent), transparent);
  pointer-events: none;
}
#dexCursorControls .dex-cursor-btn:hover {
  background: var(--c-border);
  color: var(--c-white);
  transform: scale(1.15);
}
#dexCursorControls .dex-cursor-btn:active,
#dexCursorControls .dex-cursor-btn.holding {
  background: var(--c-border);
  color: var(--c-white);
  transform: scale(0.92);
}
/* This 26px radial D-pad control is too small to host the standard
   --icon-size/--btn-padding without breaking its octagon clip-path, so it
   keeps its own compact icon size as a deliberate exception. */
#dexCursorControls .dex-cursor-btn .ic-icon {
  width: 15px;
  height: 15px;
  margin: 0;
  padding: 0;
  user-select: none;
  pointer-events: none;
}

#dexCursorControls .cmp-n  { left: 69.5px; top: 28px;    }
#dexCursorControls .cmp-ne { left: 98px;   top: 39px;    }
#dexCursorControls .cmp-e  { left: 111px;  top: 69.5px;  }
#dexCursorControls .cmp-se { left: 98px;   top: 100px;   }
#dexCursorControls .cmp-s  { left: 69.5px; top: 111px;   }
#dexCursorControls .cmp-sw { left: 41px;   top: 100px;   }
#dexCursorControls .cmp-w  { left: 28px;   top: 69.5px;  }
#dexCursorControls .cmp-nw { left: 41px;   top: 39px;    }

#dexCursorControls .dex-center-drag {
  position: absolute;
  left: 68.5px;
  top:  68.5px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--c-panel-3) 0%, var(--c-black) 100%);
  border: 1.5px solid var(--c-border);
  color: var(--c-white);
  display: flex; align-items: center; justify-content: center;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  
  transition: transform 0.15s ease,
              border-color 0.15s ease,
              box-shadow 0.15s ease,
              left 0.25s ease,
              top 0.25s ease;
}
#dexCursorControls .dex-center-drag:hover {
  border-color: var(--c-text-faint);
  
  transform: scale(1.12);
}
#dexCursorControls .dex-center-drag.dragging {
  cursor: grabbing;
  border-color: var(--c-green);
  transform: scale(1.2);
  
}

#dexCursorControls .dex-center-drag::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1.5px solid transparent;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
  pointer-events: none;
}
#dexCursorControls .dex-center-drag.dragging-right::after {
  border-right-color: var(--c-green);
  
}
#dexCursorControls .dex-center-drag.dragging-left::after {
  border-left-color: var(--c-green);
  
}
#dexCursorControls .dex-center-drag.dragging-up::after {
  border-top-color: var(--c-green);
  
}
#dexCursorControls .dex-center-drag.dragging-down::after {
  border-bottom-color: var(--c-green);
  
}

#dexSelectionPreview {
  position: fixed;
  z-index: 9994;
  background: color-mix(in srgb, var(--c-panel-2) 75%, transparent);
  border: 1px solid color-mix(in srgb, var(--c-blue) 40%, transparent);
  border-radius: 10px;
  padding: 8px 14px;
  font-family: 'classy', monospace;
  font-size: 12px;
  color: var(--c-blue);
  
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  transition: opacity 0.15s ease, transform 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#dexSelectionPreview.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}
#dexSelectionPreview .dex-preview-count {
  color: var(--c-text-faint);
  font-size: 10px;
  margin-left: 6px;
}

#dexParticleCanvas {
  position: fixed;
  inset: 0;
  z-index: 9993;
  pointer-events: none;
}

.CodeMirror-selected { background: var(--c-border) !important; }
.CodeMirror-focused .CodeMirror-selected { background: var(--c-border) !important; }
.CodeMirror-line ::selection,
.CodeMirror-line > span ::selection,
.CodeMirror-line > span > span ::selection { background: var(--c-border) !important; color: var(--c-black) !important; }
.CodeMirror-line ::-moz-selection,
.CodeMirror-line > span ::-moz-selection,
.CodeMirror-line > span > span ::-moz-selection { background: var(--c-border) !important; color: var(--c-black) !important; }
.CodeMirror .CodeMirror-selectedtext { color: var(--c-black) !important; }

#dexCursorControls.dpad-collapsed {
  width: 40px;
  height: 40px;
}
#dexCursorControls.dpad-collapsed .dex-center-drag {
  left: 6px;
  top: 6px;
}
#dexCursorControls.dpad-collapsed .dex-cursor-btn {
  opacity: 0 !important;
  pointer-events: none !important;
  transition: opacity 0.25s ease !important;
}

#dexCursorControls.dpad-collapsed .dex-center-drag {
  opacity: 0.85;
  cursor: grab;
  border-color: color-mix(in srgb, var(--c-blue) 55%, transparent);
  
  transition: opacity 0.25s ease, transform 0.25s ease,
              border-color 0.15s ease, box-shadow 0.15s ease,
              left 0.25s ease, top 0.25s ease;
}
#dexCursorControls.dpad-collapsed .dex-center-drag:hover {
  opacity: 1;
  transform: scale(1.18) !important;
  border-color: var(--c-blue);
  
}
#dexCursorControls.dpad-collapsed .dex-center-drag.dragging {
  opacity: 1;
  cursor: grabbing;
}

@keyframes dexDpadBtnIn {
  from { opacity: 0; transform: scale(0.5); }
  to   { opacity: 1; transform: scale(1); }
}
#dexCursorControls:not(.dpad-collapsed) .dex-cursor-btn {
  animation: dexDpadBtnIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dexCenterGreenPulse {
  0%, 100% { opacity: 0.78; }
  50%       { opacity: 1;    }
}
  50% {
    
  }
}
#dexCursorControls.dpad-collapsed .dex-center-drag {
  animation: dexCenterGreenPulse 2.4s ease-in-out infinite;
}
#dexCursorControls.dpad-collapsed .dex-center-drag:hover,
#dexCursorControls.dpad-collapsed .dex-center-drag.dragging {
  animation: none;
}

#dexSnapIndicator {
  position: fixed;
  z-index: 9992;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--c-blue);
  
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
}
#dexSnapIndicator.visible { opacity: 1; }

.dex-sel-handle {
  position: fixed;
  display: none;
  width: 32px;
  height: 20px;
  margin-left: -16px;
  z-index: 9990;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.dex-sel-handle::before {
  content: '';
  position: absolute;
  left: 15px;
  top: 0;
  width: 2px;
  height: var(--dex-sel-stem-h, 20px);
  background: var(--c-accent);
}
.dex-sel-handle::after {
  content: '';
  position: absolute;
  left: 6px;
  top: var(--dex-sel-stem-h, 20px);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--c-accent);
  border: 2px solid var(--c-panel-2);
}
