#105 ui dark mobile: native-first Navigation & Docks

Radial / Arc Thumb Fan Menu

Contextual 6-slice radial arc menu that fans out around the thumb for zero-travel tool switching over a live canvas.

Inspired by Procreate ↗

Download .html
Fullscreen ↗

WHY THIS AESTHETIC IS UNIQUE

Eliminates long pointer travel across creative canvases by placing equal-distance radial slices directly around the user's thumb or cursor.

BEST FOR

Drawing & annotation canvasesPhoto & video editorsSpatial whiteboardsGame & 3D viewport controls

TAGS

COLOR PALETTE (CLICK TO COPY HEX)

TYPOGRAPHY

Display
Sora
Body
Inter
Mono
JetBrains Mono
Scale
Compact 11-12px radial slice labels paired with crisp monospace brush size/opacity telemetry.

Google Fonts Stylesheet ↗

ARCHITECTURE & MOBILE NOTES

LAYOUT

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.

INTERACTION

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.

MOBILE

Automatically constrains radial fan coordinates inside viewport safe bounds so slices never clip off the edges of a 390px screen.

AI AGENT GUARDRAILS

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

DON'T

  • 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
STANDALONE SOURCE · demos/radial-thumb-fan-menu.html (20.5 KB)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ChromaArc — Radial Thumb Fan Menu Studio</title>
<style>
  :root {
    --canvas: #121318;
    --surface: #1D1F28;
    --surface-2: #262936;
    --ink: #F3F4F6;
    --muted: #9499AD;
    --accent: #FB7185;
    --border: rgba(255, 255, 255, 0.1);
  }

  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
  }

  html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--canvas);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
    user-select: none;
  }

  .studio {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  /* Top Compact Studio HUD */
  .hud {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    pointer-events: none;
  }

  .hud-pill {
    pointer-events: auto;
    background: rgba(29, 31, 40, 0.88);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 6px 12px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    min-height: 44px;
  }

  .tool-indicator {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 700;
  }

  .color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: var(--accent);
    flex-shrink: 0;
  }

  .sym-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 6px;
    background: rgba(251, 113, 133, 0.18);
    color: var(--accent);
    display: none;
  }

  .sym-badge.on {
    display: inline-block;
  }

  .size-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
  }

  .size-wrap input[type="range"] {
    width: 68px;
    accent-color: var(--accent);
    cursor: pointer;
  }

  .hud-btn {
    min-height: 36px;
    padding: 0 11px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--ink);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
  }

  .hud-btn:hover {
    background: rgba(255, 255, 255, 0.1);
  }

  /* Drawing Canvas Surface */
  .canvas-stage {
    position: relative;
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    cursor: crosshair;
  }

  #drawCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    background: #171922;
  }

  /* Symmetry center guide line */
  .symmetry-guide {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    border-left: 1.5px dashed rgba(251, 113, 133, 0.5);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 5;
  }

  .symmetry-guide.on {
    opacity: 1;
  }

  /* Swatch Popover */
  .palette-bar {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 24px) scale(0.92);
    background: rgba(29, 31, 40, 0.94);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.24s cubic-bezier(0.22, 1.2, 0.36, 1), opacity 0.18s ease;
    z-index: 35;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48);
  }

  .palette-bar.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, 0) scale(1);
  }

  .swatch {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2.5px solid transparent;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
  }

  .swatch:hover {
    transform: scale(1.12);
  }

  .swatch.active {
    border-color: #FFFFFF;
    transform: scale(1.14);
  }

  /* Radial Thumb Fan Menu */
  .fan-anchor {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 64px;
    height: 64px;
    z-index: 40;
    touch-action: none;
  }

  .fan-ring {
    position: absolute;
    right: 32px;
    bottom: 32px;
    width: 0;
    height: 0;
    pointer-events: none;
  }

  .fan-slice {
    position: absolute;
    left: 0;
    top: 0;
    width: 56px;
    height: 56px;
    margin-left: -28px;
    margin-top: -28px;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.14);
    background: rgba(29, 31, 40, 0.94);
    backdrop-filter: blur(12px);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.01em;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(0.35);
    pointer-events: none;
    cursor: pointer;
    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;
  }

  .fan-anchor.open .fan-slice {
    opacity: 1;
    pointer-events: auto;
    transform: translate3d(var(--tx), var(--ty), 0) scale(1);
  }

  .fan-slice.hovered,
  .fan-slice.active-tool {
    background: var(--accent);
    border-color: #FFFFFF;
    color: #121318;
  }

  .fan-anchor.open .fan-slice.hovered {
    transform: translate3d(var(--tx), var(--ty), 0) scale(1.16);
    box-shadow: 0 0 22px rgba(251, 113, 133, 0.55);
  }

  /* Thumb Trigger Hub */
  .fan-trigger {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.22);
    background: radial-gradient(circle at 30% 30%, #FB7185, #E11D48);
    color: #FFFFFF;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    cursor: pointer;
    box-shadow: 0 12px 30px rgba(225, 29, 72, 0.45);
    transition: transform 0.2s cubic-bezier(0.22, 1.2, 0.36, 1), box-shadow 0.2s ease;
    z-index: 2;
  }

  .fan-trigger:active,
  .fan-anchor.open .fan-trigger {
    transform: scale(0.93);
    box-shadow: 0 6px 20px rgba(225, 29, 72, 0.55);
  }

  .fan-trigger span {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .hint-chip {
    position: fixed;
    left: 16px;
    bottom: 24px;
    background: rgba(29, 31, 40, 0.8);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    padding: 8px 12px;
    border-radius: 12px;
    pointer-events: none;
    z-index: 15;
    max-width: calc(100vw - 120px);
  }

  @media (max-width: 520px) {
    .size-wrap span {
      display: none;
    }
    .size-wrap input[type="range"] {
      width: 54px;
    }
  }
</style>
</head>
<body>
<div class="studio">
  <header class="hud">
    <div class="hud-pill">
      <div class="tool-indicator">
        <span id="colorDot" class="color-dot"></span>
        <span id="activeToolLabel">Brush</span>
      </div>
      <span id="symBadge" class="sym-badge">Mirror</span>
      <label class="size-wrap">
        <span>Size</span>
        <input id="sizeRange" type="range" min="2" max="28" value="7" aria-label="Brush size">
      </label>
    </div>

    <div class="hud-pill">
      <button id="clearBtn" class="hud-btn" type="button">Clear</button>
    </div>
  </header>

  <main id="canvasStage" class="canvas-stage" aria-label="Drawing canvas">
    <canvas id="drawCanvas"></canvas>
    <div id="symGuide" class="symmetry-guide" aria-hidden="true"></div>
  </main>

  <div class="hint-chip" id="hintChip">Draw anywhere &middot; Tap or press-and-drag the pink hub to fan tools</div>

  <!-- Color Swatch Bar -->
  <div id="paletteBar" class="palette-bar" aria-label="Color palette">
    <button class="swatch active" data-color="#FB7185" style="background:#FB7185" type="button" aria-label="Rose"></button>
    <button class="swatch" data-color="#38BDF8" style="background:#38BDF8" type="button" aria-label="Sky"></button>
    <button class="swatch" data-color="#FBBF24" style="background:#FBBF24" type="button" aria-label="Amber"></button>
    <button class="swatch" data-color="#34D399" style="background:#34D399" type="button" aria-label="Mint"></button>
    <button class="swatch" data-color="#A78BFA" style="background:#A78BFA" type="button" aria-label="Violet"></button>
    <button class="swatch" data-color="#F3F4F6" style="background:#F3F4F6" type="button" aria-label="Ivory"></button>
  </div>

  <!-- Radial Arc Thumb Fan Menu -->
  <div id="fanAnchor" class="fan-anchor" aria-label="Radial tool fan menu">
    <div id="fanRing" class="fan-ring"></div>
    <button id="fanTrigger" class="fan-trigger" type="button" aria-expanded="false" aria-label="Open radial tool menu">
      <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>
      <span>Tools</span>
    </button>
  </div>
</div>

<script>
(() => {
  const SLICES = [
    { id: 'brush', label: 'Brush', icon: '<path d="M18 3a2.8 2.8 0 0 1 4 4L9 20l-5 1 1-5L18 3z"/>' },
    { 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"/>' },
    { id: 'eraser', label: 'Erase', icon: '<path d="M20 20H7L3 16l9-9 8 8-4 5"/>' },
    { 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"/>' },
    { 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"/>' },
    { 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"/>' }
  ];

  const canvas = document.getElementById('drawCanvas');
  const ctx = canvas.getContext('2d', { willReadFrequently: true });
  const stage = document.getElementById('canvasStage');
  const fanAnchor = document.getElementById('fanAnchor');
  const fanRing = document.getElementById('fanRing');
  const fanTrigger = document.getElementById('fanTrigger');
  const paletteBar = document.getElementById('paletteBar');
  const symGuide = document.getElementById('symGuide');
  const symBadge = document.getElementById('symBadge');
  const colorDot = document.getElementById('colorDot');
  const activeToolLabel = document.getElementById('activeToolLabel');
  const sizeRange = document.getElementById('sizeRange');
  const hintChip = document.getElementById('hintChip');

  let tool = 'brush'; // brush | airbrush | eraser
  let color = '#FB7185';
  let brushSize = 7;
  let symmetry = false;
  let undoStack = [];
  let fanOpen = false;
  let hoveredSliceId = null;

  // Build 6-slice radial arc (spanning 185 deg -> 275 deg in upper-left quadrant from bottom-right hub)
  const RADIUS = 122;
  const START_DEG = 180;
  const END_DEG = 270;
  const sliceEls = [];

  SLICES.forEach((s, i) => {
    // Spread across 175° to 275° for generous thumb separation
    const angleDeg = 172 + (i / (SLICES.length - 1)) * 106;
    const rad = (angleDeg * Math.PI) / 180;
    const tx = Math.cos(rad) * RADIUS;
    const ty = Math.sin(rad) * RADIUS;

    const btn = document.createElement('button');
    btn.type = 'button';
    btn.className = 'fan-slice';
    btn.dataset.slice = s.id;
    btn.style.setProperty('--tx', `${tx.toFixed(1)}px`);
    btn.style.setProperty('--ty', `${ty.toFixed(1)}px`);
    btn.style.transitionDelay = `${i * 22}ms`;
    btn.innerHTML = `
      <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>
      <span>${s.label}</span>
    `;
    btn.addEventListener('click', (e) => {
      e.stopPropagation();
      activateSlice(s.id);
      setFanOpen(false);
    });
    fanRing.appendChild(btn);
    sliceEls.push({ id: s.id, el: btn, tx, ty });
  });

  function updateSliceHighlights() {
    sliceEls.forEach(({ id, el }) => {
      const isCurrent = id === tool || (id === 'symmetry' && symmetry);
      el.classList.toggle('active-tool', isCurrent);
      el.classList.toggle('hovered', id === hoveredSliceId);
    });
    const labelMap = { brush: 'Brush', airbrush: 'Airbrush', eraser: 'Eraser' };
    activeToolLabel.textContent = labelMap[tool];
    colorDot.style.background = tool === 'eraser' ? '#171922' : color;
    symGuide.classList.toggle('on', symmetry);
    symBadge.classList.toggle('on', symmetry);
  }

  function setFanOpen(open) {
    fanOpen = open;
    fanAnchor.classList.toggle('open', open);
    fanTrigger.setAttribute('aria-expanded', String(open));
    if (!open) {
      hoveredSliceId = null;
      updateSliceHighlights();
    }
  }

  function pushUndo() {
    if (undoStack.length > 18) undoStack.shift();
    undoStack.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
  }

  function performUndo() {
    if (!undoStack.length) {
      hintChip.textContent = 'Nothing to undo';
      return;
    }
    const snap = undoStack.pop();
    ctx.putImageData(snap, 0, 0);
    hintChip.textContent = 'Undid last stroke';
  }

  function activateSlice(id) {
    if (id === 'brush' || id === 'airbrush' || id === 'eraser') {
      tool = id;
      paletteBar.classList.remove('open');
      hintChip.textContent = `Switched to ${id === 'airbrush' ? 'Airbrush' : id[0].toUpperCase() + id.slice(1)}`;
    } else if (id === 'palette') {
      paletteBar.classList.toggle('open');
      hintChip.textContent = 'Pick a stroke color';
    } else if (id === 'symmetry') {
      symmetry = !symmetry;
      hintChip.textContent = symmetry ? 'Mirror symmetry ON' : 'Mirror symmetry OFF';
    } else if (id === 'undo') {
      performUndo();
    }
    updateSliceHighlights();
  }

  // Trigger supports BOTH tap-to-toggle AND press-hold-drag-to-slice
  let triggerDown = false;
  let draggedToSlice = false;
  let downTime = 0;

  fanTrigger.addEventListener('pointerdown', (e) => {
    e.stopPropagation();
    triggerDown = true;
    draggedToSlice = false;
    downTime = performance.now();
    fanTrigger.setPointerCapture(e.pointerId);
    if (!fanOpen) setFanOpen(true);
  });

  fanTrigger.addEventListener('pointermove', (e) => {
    if (!triggerDown || !fanOpen) return;
    const rect = fanTrigger.getBoundingClientRect();
    const cx = rect.left + rect.width / 2;
    const cy = rect.top + rect.height / 2;
    const dx = e.clientX - cx;
    const dy = e.clientY - cy;
    const dist = Math.hypot(dx, dy);

    if (dist > 44) {
      draggedToSlice = true;
      // Find nearest slice center
      let closest = null;
      let best = Infinity;
      for (const s of sliceEls) {
        const d = Math.hypot(dx - s.tx, dy - s.ty);
        if (d < best) {
          best = d;
          closest = s.id;
        }
      }
      hoveredSliceId = best < 64 ? closest : null;
    } else {
      hoveredSliceId = null;
    }
    updateSliceHighlights();
  });

  fanTrigger.addEventListener('pointerup', (e) => {
    if (!triggerDown) return;
    triggerDown = false;
    const elapsed = performance.now() - downTime;

    if (draggedToSlice && hoveredSliceId) {
      activateSlice(hoveredSliceId);
      setFanOpen(false);
    } else if (elapsed > 260) {
      // Released back on center after hold
      setFanOpen(false);
    }
    // Quick tap leaves fan open so user can tap any slice
  });

  // Canvas resize & starter artwork
  function initCanvas() {
    const dpr = Math.min(window.devicePixelRatio || 1, 2);
    const w = stage.clientWidth;
    const h = stage.clientHeight;
    let prev = null;
    if (canvas.width > 0 && canvas.height > 0) {
      prev = document.createElement('canvas');
      prev.width = canvas.width;
      prev.height = canvas.height;
      prev.getContext('2d').drawImage(canvas, 0, 0);
    }
    canvas.width = Math.floor(w * dpr);
    canvas.height = Math.floor(h * dpr);
    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
    ctx.fillStyle = '#171922';
    ctx.fillRect(0, 0, w, h);

    if (prev) {
      ctx.drawImage(prev, 0, 0, w, h);
    } else {
      // Subtle starter botanical curve so the studio feels alive
      ctx.save();
      ctx.strokeStyle = 'rgba(251, 113, 133, 0.34)';
      ctx.lineWidth = 4;
      ctx.lineCap = 'round';
      ctx.beginPath();
      ctx.moveTo(w * 0.28, h * 0.58);
      ctx.bezierCurveTo(w * 0.38, h * 0.32, w * 0.62, h * 0.32, w * 0.72, h * 0.58);
      ctx.stroke();

      ctx.strokeStyle = 'rgba(56, 189, 248, 0.28)';
      ctx.lineWidth = 2.5;
      ctx.beginPath();
      ctx.moveTo(w * 0.33, h * 0.62);
      ctx.bezierCurveTo(w * 0.44, h * 0.42, w * 0.56, h * 0.42, w * 0.67, h * 0.62);
      ctx.stroke();
      ctx.restore();
    }
  }

  // Drawing engine
  let drawing = false;
  let lastPt = null;

  function drawSegment(p0, p1) {
    const drawOne = (a, b) => {
      if (tool === 'airbrush') {
        const dist = Math.hypot(b.x - a.x, b.y - a.y);
        const steps = Math.max(1, Math.ceil(dist / 3));
        ctx.fillStyle = color;
        for (let i = 0; i < steps; i++) {
          const t = i / steps;
          const x = a.x + (b.x - a.x) * t;
          const y = a.y + (b.y - a.y) * t;
          for (let d = 0; d < 10; d++) {
            const ang = Math.random() * Math.PI * 2;
            const r = Math.random() * brushSize * 1.9;
            ctx.globalAlpha = 0.08 + Math.random() * 0.14;
            ctx.beginPath();
            ctx.arc(x + Math.cos(ang) * r, y + Math.sin(ang) * r, 1.3, 0, Math.PI * 2);
            ctx.fill();
          }
        }
        ctx.globalAlpha = 1;
      } else {
        ctx.strokeStyle = tool === 'eraser' ? '#171922' : color;
        ctx.lineWidth = tool === 'eraser' ? brushSize * 2.2 : brushSize;
        ctx.lineCap = 'round';
        ctx.lineJoin = 'round';
        ctx.beginPath();
        ctx.moveTo(a.x, a.y);
        ctx.lineTo(b.x, b.y);
        ctx.stroke();
      }
    };

    drawOne(p0, p1);
    if (symmetry) {
      const w = stage.clientWidth;
      drawOne({ x: w - p0.x, y: p0.y }, { x: w - p1.x, y: p1.y });
    }
  }

  stage.addEventListener('pointerdown', (e) => {
    if (fanOpen) setFanOpen(false);
    paletteBar.classList.remove('open');
    drawing = true;
    pushUndo();
    const rect = canvas.getBoundingClientRect();
    lastPt = { x: e.clientX - rect.left, y: e.clientY - rect.top };
    drawSegment(lastPt, { x: lastPt.x + 0.1, y: lastPt.y + 0.1 });
    stage.setPointerCapture(e.pointerId);
  });

  stage.addEventListener('pointermove', (e) => {
    if (!drawing || !lastPt) return;
    const rect = canvas.getBoundingClientRect();
    const pt = { x: e.clientX - rect.left, y: e.clientY - rect.top };
    drawSegment(lastPt, pt);
    lastPt = pt;
  });

  function stopDrawing() {
    drawing = false;
    lastPt = null;
  }
  stage.addEventListener('pointerup', stopDrawing);
  stage.addEventListener('pointercancel', stopDrawing);

  // Palette swatches
  paletteBar.addEventListener('click', (e) => {
    const sw = e.target.closest('.swatch');
    if (!sw) return;
    color = sw.dataset.color;
    if (tool === 'eraser') tool = 'brush';
    paletteBar.querySelectorAll('.swatch').forEach(s => s.classList.toggle('active', s === sw));
    paletteBar.classList.remove('open');
    updateSliceHighlights();
  });

  sizeRange.addEventListener('input', (e) => {
    brushSize = Number(e.target.value);
  });

  document.getElementById('clearBtn').addEventListener('click', () => {
    pushUndo();
    ctx.fillStyle = '#171922';
    ctx.fillRect(0, 0, stage.clientWidth, stage.clientHeight);
    hintChip.textContent = 'Canvas cleared (Undo available)';
  });

  // Keyboard shortcuts
  window.addEventListener('keydown', (e) => {
    if (e.key.toLowerCase() === 'b') activateSlice('brush');
    else if (e.key.toLowerCase() === 'a') activateSlice('airbrush');
    else if (e.key.toLowerCase() === 'e') activateSlice('eraser');
    else if (e.key.toLowerCase() === 'm') activateSlice('symmetry');
    else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'z') {
      e.preventDefault();
      performUndo();
    } else if (e.key === 'Escape') {
      setFanOpen(false);
      paletteBar.classList.remove('open');
    }
  });

  window.addEventListener('resize', initCanvas);
  initCanvas();
  updateSliceHighlights();
})();
</script>
</body>
</html>