{
  "id": 105,
  "slug": "radial-thumb-fan-menu",
  "name": "Radial / Arc Thumb Fan Menu",
  "kind": "ui",
  "family": "Navigation & Docks",
  "sourceSite": {
    "name": "Procreate",
    "url": "https://procreate.com",
    "verifiedStatus": 200
  },
  "tagline": "Contextual 6-slice radial arc menu that fans out around the thumb for zero-travel tool switching over a live canvas.",
  "whyUnique": "Eliminates long pointer travel across creative canvases by placing equal-distance radial slices directly around the user's thumb or cursor.",
  "theme": "dark",
  "mobileStrength": "native-first",
  "tags": [
    "radial-menu",
    "pie-menu",
    "thumb-arc",
    "creative-tools",
    "canvas-ui"
  ],
  "bestFor": [
    "Drawing & annotation canvases",
    "Photo & video editors",
    "Spatial whiteboards",
    "Game & 3D viewport controls"
  ],
  "palette": [
    {
      "role": "canvas",
      "hex": "#121318",
      "name": "Studio Obsidian"
    },
    {
      "role": "surface",
      "hex": "#1D1F28",
      "name": "Graphite Panel"
    },
    {
      "role": "ink",
      "hex": "#F3F4F6",
      "name": "Chalk White"
    },
    {
      "role": "accent",
      "hex": "#FB7185",
      "name": "Luminous Coral"
    },
    {
      "role": "muted",
      "hex": "#9499AD",
      "name": "Slate Pencil"
    }
  ],
  "typography": {
    "display": "Sora",
    "body": "Inter",
    "mono": "JetBrains Mono",
    "googleFontsUrl": "https://fonts.googleapis.com/css2?family=Inter:wght@400;600&family=JetBrains+Mono:wght@500&family=Sora:wght@600;700&display=swap",
    "scaleNotes": "Compact 11-12px radial slice labels paired with crisp monospace brush size/opacity telemetry."
  },
  "layoutNotes": "Full-viewport interactive drawing canvas with a minimal top HUD and a corner/thumb-anchored radial trigger that stays clear of the primary work zone.",
  "interactionNotes": "Tapping or holding the trigger fans out 6 radial tool slices with staggered scale animation; users can tap a slice or drag-release toward an angle to select.",
  "mobileNotes": "Automatically constrains radial fan coordinates inside viewport safe bounds so slices never clip off the edges of a 390px screen.",
  "agentGuardrails": {
    "do": [
      "Clamp radial fan origin coordinates away from viewport edges so no slice clips off-screen",
      "Limit radial menus to 4-8 slices so angular targets remain forgiving and fast to build muscle memory",
      "Support both tap-to-open/tap-to-select and press-drag-release flick gestures"
    ],
    "dont": [
      "Do not cram text-heavy paragraphs inside radial wedges; pair a clear icon with a 1-2 word label",
      "Do not block canvas interaction when the radial menu is dismissed"
    ]
  },
  "demoFile": "demos/radial-thumb-fan-menu.html",
  "thumbDesktop": "thumbs/radial-thumb-fan-menu-desktop.webp",
  "thumbMobile": "thumbs/radial-thumb-fan-menu-mobile.webp",
  "urls": {
    "page": "https://templates.michaelpitts.net/t/radial-thumb-fan-menu",
    "markdown": "https://templates.michaelpitts.net/t/radial-thumb-fan-menu.md",
    "api": "https://templates.michaelpitts.net/api/templates/radial-thumb-fan-menu",
    "demo": "https://templates.michaelpitts.net/demos/radial-thumb-fan-menu.html",
    "thumbDesktop": "https://templates.michaelpitts.net/thumbs/radial-thumb-fan-menu-desktop.webp",
    "thumbMobile": "https://templates.michaelpitts.net/thumbs/radial-thumb-fan-menu-mobile.webp"
  },
  "agentPrompt": "Design & build using template #105 \"Radial / Arc Thumb Fan Menu\" (ui / Navigation & Docks, dark theme).\nFull AI blueprint & standalone starter code: https://templates.michaelpitts.net/t/radial-thumb-fan-menu.md\nLive demo: https://templates.michaelpitts.net/demos/radial-thumb-fan-menu.html\nReal-world inspiration: Procreate (https://procreate.com)\n\nCore aesthetic: Eliminates long pointer travel across creative canvases by placing equal-distance radial slices directly around the user's thumb or cursor.\nPalette: canvas: #121318 (Studio Obsidian), surface: #1D1F28 (Graphite Panel), ink: #F3F4F6 (Chalk White), accent: #FB7185 (Luminous Coral), muted: #9499AD (Slate Pencil)\nTypography: Display=\"Sora\", Body=\"Inter\", Mono=\"JetBrains Mono\"\nLayout: Full-viewport interactive drawing canvas with a minimal top HUD and a corner/thumb-anchored radial trigger that stays clear of the primary work zone.\nInteractions: Tapping or holding the trigger fans out 6 radial tool slices with staggered scale animation; users can tap a slice or drag-release toward an angle to select.\nMobile: Automatically constrains radial fan coordinates inside viewport safe bounds so slices never clip off the edges of a 390px screen.\n\nGuardrails:\n- DO: Clamp radial fan origin coordinates away from viewport edges so no slice clips off-screen\n- DO: Limit radial menus to 4-8 slices so angular targets remain forgiving and fast to build muscle memory\n- DO: Support both tap-to-open/tap-to-select and press-drag-release flick gestures\n- DON'T: Do not cram text-heavy paragraphs inside radial wedges; pair a clear icon with a 1-2 word label\n- DON'T: Do not block canvas interaction when the radial menu is dismissed",
  "sourceCode": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>ChromaArc — Radial Thumb Fan Menu Studio</title>\n<style>\n  :root {\n    --canvas: #121318;\n    --surface: #1D1F28;\n    --surface-2: #262936;\n    --ink: #F3F4F6;\n    --muted: #9499AD;\n    --accent: #FB7185;\n    --border: rgba(255, 255, 255, 0.1);\n  }\n\n  * {\n    box-sizing: border-box;\n    margin: 0;\n    padding: 0;\n    -webkit-tap-highlight-color: transparent;\n  }\n\n  html, body {\n    width: 100%;\n    height: 100%;\n    overflow: hidden;\n    background: var(--canvas);\n    color: var(--ink);\n    font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Inter, sans-serif;\n    user-select: none;\n  }\n\n  .studio {\n    position: relative;\n    width: 100%;\n    height: 100%;\n    display: flex;\n    flex-direction: column;\n  }\n\n  /* Top Compact Studio HUD */\n  .hud {\n    position: absolute;\n    top: 12px;\n    left: 12px;\n    right: 12px;\n    z-index: 20;\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    gap: 8px;\n    pointer-events: none;\n  }\n\n  .hud-pill {\n    pointer-events: auto;\n    background: rgba(29, 31, 40, 0.88);\n    backdrop-filter: blur(14px);\n    border: 1px solid var(--border);\n    border-radius: 16px;\n    padding: 6px 12px;\n    display: inline-flex;\n    align-items: center;\n    gap: 10px;\n    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);\n    min-height: 44px;\n  }\n\n  .tool-indicator {\n    display: inline-flex;\n    align-items: center;\n    gap: 7px;\n    font-size: 13px;\n    font-weight: 700;\n  }\n\n  .color-dot {\n    width: 14px;\n    height: 14px;\n    border-radius: 50%;\n    border: 2px solid #fff;\n    background: var(--accent);\n    flex-shrink: 0;\n  }\n\n  .sym-badge {\n    font-size: 11px;\n    font-weight: 700;\n    padding: 3px 7px;\n    border-radius: 6px;\n    background: rgba(251, 113, 133, 0.18);\n    color: var(--accent);\n    display: none;\n  }\n\n  .sym-badge.on {\n    display: inline-block;\n  }\n\n  .size-wrap {\n    display: inline-flex;\n    align-items: center;\n    gap: 6px;\n    font-size: 12px;\n    color: var(--muted);\n  }\n\n  .size-wrap input[type=\"range\"] {\n    width: 68px;\n    accent-color: var(--accent);\n    cursor: pointer;\n  }\n\n  .hud-btn {\n    min-height: 36px;\n    padding: 0 11px;\n    border-radius: 10px;\n    border: 1px solid var(--border);\n    background: rgba(255, 255, 255, 0.04);\n    color: var(--ink);\n    font-size: 12px;\n    font-weight: 600;\n    cursor: pointer;\n  }\n\n  .hud-btn:hover {\n    background: rgba(255, 255, 255, 0.1);\n  }\n\n  /* Drawing Canvas Surface */\n  .canvas-stage {\n    position: relative;\n    flex: 1;\n    width: 100%;\n    height: 100%;\n    overflow: hidden;\n    touch-action: none;\n    cursor: crosshair;\n  }\n\n  #drawCanvas {\n    position: absolute;\n    inset: 0;\n    width: 100%;\n    height: 100%;\n    display: block;\n    background: #171922;\n  }\n\n  /* Symmetry center guide line */\n  .symmetry-guide {\n    position: absolute;\n    top: 0;\n    bottom: 0;\n    left: 50%;\n    width: 1px;\n    border-left: 1.5px dashed rgba(251, 113, 133, 0.5);\n    pointer-events: none;\n    opacity: 0;\n    transition: opacity 0.2s ease;\n    z-index: 5;\n  }\n\n  .symmetry-guide.on {\n    opacity: 1;\n  }\n\n  /* Swatch Popover */\n  .palette-bar {\n    position: fixed;\n    left: 50%;\n    bottom: 24px;\n    transform: translate(-50%, 24px) scale(0.92);\n    background: rgba(29, 31, 40, 0.94);\n    backdrop-filter: blur(16px);\n    border: 1px solid var(--border);\n    border-radius: 999px;\n    padding: 8px 12px;\n    display: flex;\n    align-items: center;\n    gap: 10px;\n    opacity: 0;\n    pointer-events: none;\n    transition: transform 0.24s cubic-bezier(0.22, 1.2, 0.36, 1), opacity 0.18s ease;\n    z-index: 35;\n    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48);\n  }\n\n  .palette-bar.open {\n    opacity: 1;\n    pointer-events: auto;\n    transform: translate(-50%, 0) scale(1);\n  }\n\n  .swatch {\n    width: 34px;\n    height: 34px;\n    border-radius: 50%;\n    border: 2.5px solid transparent;\n    cursor: pointer;\n    transition: transform 0.15s ease, border-color 0.15s ease;\n  }\n\n  .swatch:hover {\n    transform: scale(1.12);\n  }\n\n  .swatch.active {\n    border-color: #FFFFFF;\n    transform: scale(1.14);\n  }\n\n  /* Radial Thumb Fan Menu */\n  .fan-anchor {\n    position: fixed;\n    right: 22px;\n    bottom: 22px;\n    width: 64px;\n    height: 64px;\n    z-index: 40;\n    touch-action: none;\n  }\n\n  .fan-ring {\n    position: absolute;\n    right: 32px;\n    bottom: 32px;\n    width: 0;\n    height: 0;\n    pointer-events: none;\n  }\n\n  .fan-slice {\n    position: absolute;\n    left: 0;\n    top: 0;\n    width: 56px;\n    height: 56px;\n    margin-left: -28px;\n    margin-top: -28px;\n    border-radius: 50%;\n    border: 1.5px solid rgba(255, 255, 255, 0.14);\n    background: rgba(29, 31, 40, 0.94);\n    backdrop-filter: blur(12px);\n    color: var(--ink);\n    display: flex;\n    flex-direction: column;\n    align-items: center;\n    justify-content: center;\n    gap: 2px;\n    font-size: 9.5px;\n    font-weight: 700;\n    letter-spacing: 0.01em;\n    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);\n    opacity: 0;\n    transform: translate3d(0, 0, 0) scale(0.35);\n    pointer-events: none;\n    cursor: pointer;\n    transition: transform 0.28s cubic-bezier(0.24, 1.28, 0.42, 1), opacity 0.2s ease, background 0.14s ease, border-color 0.14s ease;\n  }\n\n  .fan-anchor.open .fan-slice {\n    opacity: 1;\n    pointer-events: auto;\n    transform: translate3d(var(--tx), var(--ty), 0) scale(1);\n  }\n\n  .fan-slice.hovered,\n  .fan-slice.active-tool {\n    background: var(--accent);\n    border-color: #FFFFFF;\n    color: #121318;\n  }\n\n  .fan-anchor.open .fan-slice.hovered {\n    transform: translate3d(var(--tx), var(--ty), 0) scale(1.16);\n    box-shadow: 0 0 22px rgba(251, 113, 133, 0.55);\n  }\n\n  /* Thumb Trigger Hub */\n  .fan-trigger {\n    position: relative;\n    width: 64px;\n    height: 64px;\n    border-radius: 50%;\n    border: 2px solid rgba(255, 255, 255, 0.22);\n    background: radial-gradient(circle at 30% 30%, #FB7185, #E11D48);\n    color: #FFFFFF;\n    display: flex;\n    flex-direction: column;\n    align-items: center;\n    justify-content: center;\n    gap: 1px;\n    cursor: pointer;\n    box-shadow: 0 12px 30px rgba(225, 29, 72, 0.45);\n    transition: transform 0.2s cubic-bezier(0.22, 1.2, 0.36, 1), box-shadow 0.2s ease;\n    z-index: 2;\n  }\n\n  .fan-trigger:active,\n  .fan-anchor.open .fan-trigger {\n    transform: scale(0.93);\n    box-shadow: 0 6px 20px rgba(225, 29, 72, 0.55);\n  }\n\n  .fan-trigger span {\n    font-size: 9px;\n    font-weight: 800;\n    letter-spacing: 0.05em;\n    text-transform: uppercase;\n  }\n\n  .hint-chip {\n    position: fixed;\n    left: 16px;\n    bottom: 24px;\n    background: rgba(29, 31, 40, 0.8);\n    border: 1px solid var(--border);\n    color: var(--muted);\n    font-size: 12px;\n    padding: 8px 12px;\n    border-radius: 12px;\n    pointer-events: none;\n    z-index: 15;\n    max-width: calc(100vw - 120px);\n  }\n\n  @media (max-width: 520px) {\n    .size-wrap span {\n      display: none;\n    }\n    .size-wrap input[type=\"range\"] {\n      width: 54px;\n    }\n  }\n</style>\n</head>\n<body>\n<div class=\"studio\">\n  <header class=\"hud\">\n    <div class=\"hud-pill\">\n      <div class=\"tool-indicator\">\n        <span id=\"colorDot\" class=\"color-dot\"></span>\n        <span id=\"activeToolLabel\">Brush</span>\n      </div>\n      <span id=\"symBadge\" class=\"sym-badge\">Mirror</span>\n      <label class=\"size-wrap\">\n        <span>Size</span>\n        <input id=\"sizeRange\" type=\"range\" min=\"2\" max=\"28\" value=\"7\" aria-label=\"Brush size\">\n      </label>\n    </div>\n\n    <div class=\"hud-pill\">\n      <button id=\"clearBtn\" class=\"hud-btn\" type=\"button\">Clear</button>\n    </div>\n  </header>\n\n  <main id=\"canvasStage\" class=\"canvas-stage\" aria-label=\"Drawing canvas\">\n    <canvas id=\"drawCanvas\"></canvas>\n    <div id=\"symGuide\" class=\"symmetry-guide\" aria-hidden=\"true\"></div>\n  </main>\n\n  <div class=\"hint-chip\" id=\"hintChip\">Draw anywhere &middot; Tap or press-and-drag the pink hub to fan tools</div>\n\n  <!-- Color Swatch Bar -->\n  <div id=\"paletteBar\" class=\"palette-bar\" aria-label=\"Color palette\">\n    <button class=\"swatch active\" data-color=\"#FB7185\" style=\"background:#FB7185\" type=\"button\" aria-label=\"Rose\"></button>\n    <button class=\"swatch\" data-color=\"#38BDF8\" style=\"background:#38BDF8\" type=\"button\" aria-label=\"Sky\"></button>\n    <button class=\"swatch\" data-color=\"#FBBF24\" style=\"background:#FBBF24\" type=\"button\" aria-label=\"Amber\"></button>\n    <button class=\"swatch\" data-color=\"#34D399\" style=\"background:#34D399\" type=\"button\" aria-label=\"Mint\"></button>\n    <button class=\"swatch\" data-color=\"#A78BFA\" style=\"background:#A78BFA\" type=\"button\" aria-label=\"Violet\"></button>\n    <button class=\"swatch\" data-color=\"#F3F4F6\" style=\"background:#F3F4F6\" type=\"button\" aria-label=\"Ivory\"></button>\n  </div>\n\n  <!-- Radial Arc Thumb Fan Menu -->\n  <div id=\"fanAnchor\" class=\"fan-anchor\" aria-label=\"Radial tool fan menu\">\n    <div id=\"fanRing\" class=\"fan-ring\"></div>\n    <button id=\"fanTrigger\" class=\"fan-trigger\" type=\"button\" aria-expanded=\"false\" aria-label=\"Open radial tool menu\">\n      <svg width=\"22\" height=\"22\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"12\" cy=\"12\" r=\"3\"/><path d=\"M12 2v4m0 12v4M2 12h4m12 0h4m-2.9-7.1-2.8 2.8m-8.6 8.6-2.8 2.8m0-14.2 2.8 2.8m8.6 8.6 2.8 2.8\"/></svg>\n      <span>Tools</span>\n    </button>\n  </div>\n</div>\n\n<script>\n(() => {\n  const SLICES = [\n    { id: 'brush', label: 'Brush', icon: '<path d=\"M18 3a2.8 2.8 0 0 1 4 4L9 20l-5 1 1-5L18 3z\"/>' },\n    { id: 'airbrush', label: 'Spray', icon: '<circle cx=\"12\" cy=\"12\" r=\"2\"/><circle cx=\"7\" cy=\"8\" r=\"1.2\"/><circle cx=\"17\" cy=\"9\" r=\"1.2\"/><circle cx=\"9\" cy=\"17\" r=\"1.2\"/><circle cx=\"16\" cy=\"16\" r=\"1.2\"/>' },\n    { id: 'eraser', label: 'Erase', icon: '<path d=\"M20 20H7L3 16l9-9 8 8-4 5\"/>' },\n    { id: 'palette', label: 'Color', icon: '<circle cx=\"12\" cy=\"12\" r=\"8\"/><circle cx=\"9\" cy=\"10\" r=\"1.3\"/><circle cx=\"15\" cy=\"10\" r=\"1.3\"/><circle cx=\"12\" cy=\"15\" r=\"1.3\"/>' },\n    { id: 'symmetry', label: 'Mirror', icon: '<line x1=\"12\" y1=\"3\" x2=\"12\" y2=\"21\" stroke-dasharray=\"2 2\"/><polygon points=\"4 12 9 7 9 17\"/><polygon points=\"20 12 15 7 15 17\"/>' },\n    { id: 'undo', label: 'Undo', icon: '<path d=\"M3 7v6h6\"/><path d=\"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13\"/>' }\n  ];\n\n  const canvas = document.getElementById('drawCanvas');\n  const ctx = canvas.getContext('2d', { willReadFrequently: true });\n  const stage = document.getElementById('canvasStage');\n  const fanAnchor = document.getElementById('fanAnchor');\n  const fanRing = document.getElementById('fanRing');\n  const fanTrigger = document.getElementById('fanTrigger');\n  const paletteBar = document.getElementById('paletteBar');\n  const symGuide = document.getElementById('symGuide');\n  const symBadge = document.getElementById('symBadge');\n  const colorDot = document.getElementById('colorDot');\n  const activeToolLabel = document.getElementById('activeToolLabel');\n  const sizeRange = document.getElementById('sizeRange');\n  const hintChip = document.getElementById('hintChip');\n\n  let tool = 'brush'; // brush | airbrush | eraser\n  let color = '#FB7185';\n  let brushSize = 7;\n  let symmetry = false;\n  let undoStack = [];\n  let fanOpen = false;\n  let hoveredSliceId = null;\n\n  // Build 6-slice radial arc (spanning 185 deg -> 275 deg in upper-left quadrant from bottom-right hub)\n  const RADIUS = 122;\n  const START_DEG = 180;\n  const END_DEG = 270;\n  const sliceEls = [];\n\n  SLICES.forEach((s, i) => {\n    // Spread across 175° to 275° for generous thumb separation\n    const angleDeg = 172 + (i / (SLICES.length - 1)) * 106;\n    const rad = (angleDeg * Math.PI) / 180;\n    const tx = Math.cos(rad) * RADIUS;\n    const ty = Math.sin(rad) * RADIUS;\n\n    const btn = document.createElement('button');\n    btn.type = 'button';\n    btn.className = 'fan-slice';\n    btn.dataset.slice = s.id;\n    btn.style.setProperty('--tx', `${tx.toFixed(1)}px`);\n    btn.style.setProperty('--ty', `${ty.toFixed(1)}px`);\n    btn.style.transitionDelay = `${i * 22}ms`;\n    btn.innerHTML = `\n      <svg width=\"19\" height=\"19\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.1\" stroke-linecap=\"round\" stroke-linejoin=\"round\">${s.icon}</svg>\n      <span>${s.label}</span>\n    `;\n    btn.addEventListener('click', (e) => {\n      e.stopPropagation();\n      activateSlice(s.id);\n      setFanOpen(false);\n    });\n    fanRing.appendChild(btn);\n    sliceEls.push({ id: s.id, el: btn, tx, ty });\n  });\n\n  function updateSliceHighlights() {\n    sliceEls.forEach(({ id, el }) => {\n      const isCurrent = id === tool || (id === 'symmetry' && symmetry);\n      el.classList.toggle('active-tool', isCurrent);\n      el.classList.toggle('hovered', id === hoveredSliceId);\n    });\n    const labelMap = { brush: 'Brush', airbrush: 'Airbrush', eraser: 'Eraser' };\n    activeToolLabel.textContent = labelMap[tool];\n    colorDot.style.background = tool === 'eraser' ? '#171922' : color;\n    symGuide.classList.toggle('on', symmetry);\n    symBadge.classList.toggle('on', symmetry);\n  }\n\n  function setFanOpen(open) {\n    fanOpen = open;\n    fanAnchor.classList.toggle('open', open);\n    fanTrigger.setAttribute('aria-expanded', String(open));\n    if (!open) {\n      hoveredSliceId = null;\n      updateSliceHighlights();\n    }\n  }\n\n  function pushUndo() {\n    if (undoStack.length > 18) undoStack.shift();\n    undoStack.push(ctx.getImageData(0, 0, canvas.width, canvas.height));\n  }\n\n  function performUndo() {\n    if (!undoStack.length) {\n      hintChip.textContent = 'Nothing to undo';\n      return;\n    }\n    const snap = undoStack.pop();\n    ctx.putImageData(snap, 0, 0);\n    hintChip.textContent = 'Undid last stroke';\n  }\n\n  function activateSlice(id) {\n    if (id === 'brush' || id === 'airbrush' || id === 'eraser') {\n      tool = id;\n      paletteBar.classList.remove('open');\n      hintChip.textContent = `Switched to ${id === 'airbrush' ? 'Airbrush' : id[0].toUpperCase() + id.slice(1)}`;\n    } else if (id === 'palette') {\n      paletteBar.classList.toggle('open');\n      hintChip.textContent = 'Pick a stroke color';\n    } else if (id === 'symmetry') {\n      symmetry = !symmetry;\n      hintChip.textContent = symmetry ? 'Mirror symmetry ON' : 'Mirror symmetry OFF';\n    } else if (id === 'undo') {\n      performUndo();\n    }\n    updateSliceHighlights();\n  }\n\n  // Trigger supports BOTH tap-to-toggle AND press-hold-drag-to-slice\n  let triggerDown = false;\n  let draggedToSlice = false;\n  let downTime = 0;\n\n  fanTrigger.addEventListener('pointerdown', (e) => {\n    e.stopPropagation();\n    triggerDown = true;\n    draggedToSlice = false;\n    downTime = performance.now();\n    fanTrigger.setPointerCapture(e.pointerId);\n    if (!fanOpen) setFanOpen(true);\n  });\n\n  fanTrigger.addEventListener('pointermove', (e) => {\n    if (!triggerDown || !fanOpen) return;\n    const rect = fanTrigger.getBoundingClientRect();\n    const cx = rect.left + rect.width / 2;\n    const cy = rect.top + rect.height / 2;\n    const dx = e.clientX - cx;\n    const dy = e.clientY - cy;\n    const dist = Math.hypot(dx, dy);\n\n    if (dist > 44) {\n      draggedToSlice = true;\n      // Find nearest slice center\n      let closest = null;\n      let best = Infinity;\n      for (const s of sliceEls) {\n        const d = Math.hypot(dx - s.tx, dy - s.ty);\n        if (d < best) {\n          best = d;\n          closest = s.id;\n        }\n      }\n      hoveredSliceId = best < 64 ? closest : null;\n    } else {\n      hoveredSliceId = null;\n    }\n    updateSliceHighlights();\n  });\n\n  fanTrigger.addEventListener('pointerup', (e) => {\n    if (!triggerDown) return;\n    triggerDown = false;\n    const elapsed = performance.now() - downTime;\n\n    if (draggedToSlice && hoveredSliceId) {\n      activateSlice(hoveredSliceId);\n      setFanOpen(false);\n    } else if (elapsed > 260) {\n      // Released back on center after hold\n      setFanOpen(false);\n    }\n    // Quick tap leaves fan open so user can tap any slice\n  });\n\n  // Canvas resize & starter artwork\n  function initCanvas() {\n    const dpr = Math.min(window.devicePixelRatio || 1, 2);\n    const w = stage.clientWidth;\n    const h = stage.clientHeight;\n    let prev = null;\n    if (canvas.width > 0 && canvas.height > 0) {\n      prev = document.createElement('canvas');\n      prev.width = canvas.width;\n      prev.height = canvas.height;\n      prev.getContext('2d').drawImage(canvas, 0, 0);\n    }\n    canvas.width = Math.floor(w * dpr);\n    canvas.height = Math.floor(h * dpr);\n    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    ctx.fillStyle = '#171922';\n    ctx.fillRect(0, 0, w, h);\n\n    if (prev) {\n      ctx.drawImage(prev, 0, 0, w, h);\n    } else {\n      // Subtle starter botanical curve so the studio feels alive\n      ctx.save();\n      ctx.strokeStyle = 'rgba(251, 113, 133, 0.34)';\n      ctx.lineWidth = 4;\n      ctx.lineCap = 'round';\n      ctx.beginPath();\n      ctx.moveTo(w * 0.28, h * 0.58);\n      ctx.bezierCurveTo(w * 0.38, h * 0.32, w * 0.62, h * 0.32, w * 0.72, h * 0.58);\n      ctx.stroke();\n\n      ctx.strokeStyle = 'rgba(56, 189, 248, 0.28)';\n      ctx.lineWidth = 2.5;\n      ctx.beginPath();\n      ctx.moveTo(w * 0.33, h * 0.62);\n      ctx.bezierCurveTo(w * 0.44, h * 0.42, w * 0.56, h * 0.42, w * 0.67, h * 0.62);\n      ctx.stroke();\n      ctx.restore();\n    }\n  }\n\n  // Drawing engine\n  let drawing = false;\n  let lastPt = null;\n\n  function drawSegment(p0, p1) {\n    const drawOne = (a, b) => {\n      if (tool === 'airbrush') {\n        const dist = Math.hypot(b.x - a.x, b.y - a.y);\n        const steps = Math.max(1, Math.ceil(dist / 3));\n        ctx.fillStyle = color;\n        for (let i = 0; i < steps; i++) {\n          const t = i / steps;\n          const x = a.x + (b.x - a.x) * t;\n          const y = a.y + (b.y - a.y) * t;\n          for (let d = 0; d < 10; d++) {\n            const ang = Math.random() * Math.PI * 2;\n            const r = Math.random() * brushSize * 1.9;\n            ctx.globalAlpha = 0.08 + Math.random() * 0.14;\n            ctx.beginPath();\n            ctx.arc(x + Math.cos(ang) * r, y + Math.sin(ang) * r, 1.3, 0, Math.PI * 2);\n            ctx.fill();\n          }\n        }\n        ctx.globalAlpha = 1;\n      } else {\n        ctx.strokeStyle = tool === 'eraser' ? '#171922' : color;\n        ctx.lineWidth = tool === 'eraser' ? brushSize * 2.2 : brushSize;\n        ctx.lineCap = 'round';\n        ctx.lineJoin = 'round';\n        ctx.beginPath();\n        ctx.moveTo(a.x, a.y);\n        ctx.lineTo(b.x, b.y);\n        ctx.stroke();\n      }\n    };\n\n    drawOne(p0, p1);\n    if (symmetry) {\n      const w = stage.clientWidth;\n      drawOne({ x: w - p0.x, y: p0.y }, { x: w - p1.x, y: p1.y });\n    }\n  }\n\n  stage.addEventListener('pointerdown', (e) => {\n    if (fanOpen) setFanOpen(false);\n    paletteBar.classList.remove('open');\n    drawing = true;\n    pushUndo();\n    const rect = canvas.getBoundingClientRect();\n    lastPt = { x: e.clientX - rect.left, y: e.clientY - rect.top };\n    drawSegment(lastPt, { x: lastPt.x + 0.1, y: lastPt.y + 0.1 });\n    stage.setPointerCapture(e.pointerId);\n  });\n\n  stage.addEventListener('pointermove', (e) => {\n    if (!drawing || !lastPt) return;\n    const rect = canvas.getBoundingClientRect();\n    const pt = { x: e.clientX - rect.left, y: e.clientY - rect.top };\n    drawSegment(lastPt, pt);\n    lastPt = pt;\n  });\n\n  function stopDrawing() {\n    drawing = false;\n    lastPt = null;\n  }\n  stage.addEventListener('pointerup', stopDrawing);\n  stage.addEventListener('pointercancel', stopDrawing);\n\n  // Palette swatches\n  paletteBar.addEventListener('click', (e) => {\n    const sw = e.target.closest('.swatch');\n    if (!sw) return;\n    color = sw.dataset.color;\n    if (tool === 'eraser') tool = 'brush';\n    paletteBar.querySelectorAll('.swatch').forEach(s => s.classList.toggle('active', s === sw));\n    paletteBar.classList.remove('open');\n    updateSliceHighlights();\n  });\n\n  sizeRange.addEventListener('input', (e) => {\n    brushSize = Number(e.target.value);\n  });\n\n  document.getElementById('clearBtn').addEventListener('click', () => {\n    pushUndo();\n    ctx.fillStyle = '#171922';\n    ctx.fillRect(0, 0, stage.clientWidth, stage.clientHeight);\n    hintChip.textContent = 'Canvas cleared (Undo available)';\n  });\n\n  // Keyboard shortcuts\n  window.addEventListener('keydown', (e) => {\n    if (e.key.toLowerCase() === 'b') activateSlice('brush');\n    else if (e.key.toLowerCase() === 'a') activateSlice('airbrush');\n    else if (e.key.toLowerCase() === 'e') activateSlice('eraser');\n    else if (e.key.toLowerCase() === 'm') activateSlice('symmetry');\n    else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'z') {\n      e.preventDefault();\n      performUndo();\n    } else if (e.key === 'Escape') {\n      setFanOpen(false);\n      paletteBar.classList.remove('open');\n    }\n  });\n\n  window.addEventListener('resize', initCanvas);\n  initCanvas();\n  updateSliceHighlights();\n})();\n</script>\n</body>\n</html>\n"
}
