================================================================================
PEN TOOLBAR - COPY PASTE CODE SECTIONS
================================================================================

OVERVIEW:
This is a complete pen toolbar that can be added to ANY HTML file.
It includes drawing on canvas with undo/clear functionality.

Three sections to copy:
1. CSS (put in <style> or external CSS)
2. HTML (put at top of <body>)
3. JavaScript (put in <script> or at end of file)

================================================================================
SECTION 1: CSS - PASTE THIS INTO YOUR <style> TAG
================================================================================

/* ── Drawing Canvas (Fixed Position - Covers Entire Screen) ── */
#draw-canvas { 
  position: fixed; 
  top: 0; 
  left: 0; 
  width: 100vw; 
  height: 100vh; 
  pointer-events: none; 
  z-index: 90; 
}
#draw-canvas.pen-active { 
  pointer-events: all; 
  cursor: crosshair; 
}

/* ── Top Bar (Sticky - Stays at Top) ── */
.top-bar { 
  position: sticky; 
  top: 0; 
  z-index: 100; 
  display: flex; 
  flex-wrap: wrap; 
  gap: 12px; 
  align-items: center; 
  padding: 10px 20px; 
  background: rgba(10, 14, 26, 0.95); 
  backdrop-filter: blur(12px); 
  border-bottom: 1px solid #1e2d45; 
}

/* ── Top Title ── */
.top-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  color: #e2e8f4;
}

/* ── Divider Line Between Title and Toolbar ── */
.divider { 
  width: 1px; 
  height: 28px; 
  background: #263550; 
  flex-shrink: 0; 
}

/* ── Pen Toolbar Container ── */
.pen-toolbar { 
  display: flex; 
  flex-wrap: wrap; 
  gap: 6px; 
  align-items: center; 
}

/* ── Pen Toolbar Button Styles ── */
.tool-btn { 
  font-family: 'IBM Plex Mono', monospace; 
  font-size: 11px; 
  padding: 6px 12px; 
  border-radius: 6px; 
  border: 1px solid #263550; 
  background: #1a2236; 
  color: #6b7a99; 
  cursor: pointer; 
  transition: all 0.15s; 
  display: inline-flex; 
  align-items: center; 
  gap: 6px; 
  white-space: nowrap; 
}

.tool-btn:hover { 
  border-color: #fbbf24; 
  color: #fbbf24; 
  background: rgba(251, 191, 36, 0.06); 
}

.tool-btn.active { 
  border-color: #fbbf24; 
  color: #fbbf24; 
  background: rgba(251, 191, 36, 0.12); 
}

/* ── Color Picker Input ── */
.pen-toolbar input[type="color"] { 
  width: 34px; 
  height: 34px; 
  padding: 0; 
  border-radius: 10px; 
  border: 1px solid #263550; 
  background: #1a2236; 
  cursor: pointer; 
}

/* ── Size Range Slider ── */
.pen-toolbar input[type="range"] { 
  width: 110px; 
}

/* ── Hide Toolbar Items Until Pen is Toggled ── */
.pen-toolbar > *:not(#pen-toggle) { 
  display: none; 
}

.pen-toolbar.active > *:not(#pen-toggle) { 
  display: inline-flex; 
}

/* ════════════════════════════════════════════════════════════════
   RESPONSIVE STYLES FOR DIFFERENT SCREEN SIZES
   ════════════════════════════════════════════════════════════════ */

/* ── Tablet & Medium Screens (860px and below) ── */
@media(max-width: 860px) {
  .top-bar { 
    padding: 10px 14px; 
    gap: 10px; 
    flex-direction: column; 
    align-items: flex-start; 
  }
  
  .top-title { 
    width: 100%; 
  }
  
  .divider { 
    display: none; 
  }
  
  .pen-toolbar { 
    width: 100%; 
  }
  
  .tool-btn { 
    padding: 6px 10px; 
    font-size: 10px; 
  }
  
  .pen-toolbar input[type="color"] { 
    width: 30px; 
    height: 30px; 
  }
  
  .pen-toolbar input[type="range"] { 
    width: 90px; 
  }
}

/* ── Tablets (768px and below) ── */
@media(max-width: 768px) {
  .top-bar { 
    padding: 10px 12px; 
    gap: 6px; 
  }
  
  .pen-toolbar { 
    gap: 4px; 
  }
  
  .tool-btn { 
    padding: 5px 10px; 
    font-size: 10px; 
  }
  
  .pen-toolbar input[type="color"] { 
    width: 28px; 
    height: 28px; 
  }
  
  .pen-toolbar input[type="range"] { 
    width: 70px; 
  }
}

/* ── Mobile Phones (480px and below) ── */
@media(max-width: 480px) {
  .top-bar { 
    padding: 8px 10px; 
  }
  
  .pen-toolbar { 
    gap: 4px; 
  }
  
  .tool-btn { 
    padding: 5px 8px; 
    font-size: 9px; 
  }
  
  .pen-toolbar input[type="color"] { 
    width: 26px; 
    height: 26px; 
  }
  
  .pen-toolbar input[type="range"] { 
    width: 60px; 
  }
}


================================================================================
SECTION 2: HTML - PASTE THIS AT THE TOP OF YOUR <body> TAG
================================================================================

<!-- Drawing Canvas (Hidden by default, shows on pen toggle) -->
<canvas id="draw-canvas"></canvas>

<!-- Top Bar with Pen Toolbar -->
<div class="top-bar">
  <span class="top-title">My App Name</span>
  <div class="divider"></div>
  <div class="pen-toolbar" id="pen-toolbar">
    <button class="tool-btn" id="pen-toggle" title="Toggle drawing mode">✏️ Pen</button>
    <button class="tool-btn" id="clear-canvas" title="Clear all drawings">🗑️ Clear</button>
    <button class="tool-btn" id="undo-btn" title="Undo last stroke">↶ Undo</button>
    <input type="color" id="pen-color" value="#fbbf24" title="Pen Color">
    <input type="range" id="pen-size" min="1" max="20" value="3" title="Pen Size">
  </div>
</div>


================================================================================
SECTION 3: JAVASCRIPT - PASTE THIS IN <script> TAG OR AT END OF <body>
================================================================================

<script>
// ══════════════════════════════════════════════════════════════
// PEN TOOLBAR - COMPLETE DRAWING FUNCTIONALITY
// ══════════════════════════════════════════════════════════════

const canvas = document.getElementById('draw-canvas');
const ctx = canvas.getContext('2d');
const penToggle = document.getElementById('pen-toggle');
const penToolbar = document.getElementById('pen-toolbar');
const penColor = document.getElementById('pen-color');
const penSize = document.getElementById('pen-size');
const clearBtn = document.getElementById('clear-canvas');
const undoBtn = document.getElementById('undo-btn');

let isPenActive = false;
let isDrawing = false;
let drawHistory = [];

// ── Initialize Canvas Size ──
function resizeCanvas() {
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
}
resizeCanvas();
window.addEventListener('resize', resizeCanvas);

// ── Toggle Pen Mode ──
penToggle.addEventListener('click', () => {
  isPenActive = !isPenActive;
  penToggle.classList.toggle('active');
  canvas.classList.toggle('pen-active');
  penToolbar.classList.toggle('active');
});

// ── Start Drawing ──
canvas.addEventListener('mousedown', (e) => {
  if (!isPenActive) return;
  isDrawing = true;
  saveDrawHistory();
  ctx.beginPath();
  ctx.moveTo(e.clientX, e.clientY);
});

// ── Draw While Moving Mouse ──
canvas.addEventListener('mousemove', (e) => {
  if (!isDrawing || !isPenActive) return;
  ctx.lineTo(e.clientX, e.clientY);
  ctx.strokeStyle = penColor.value;
  ctx.lineWidth = penSize.value;
  ctx.lineCap = 'round';
  ctx.lineJoin = 'round';
  ctx.stroke();
});

// ── Stop Drawing ──
canvas.addEventListener('mouseup', () => {
  isDrawing = false;
});

canvas.addEventListener('mouseleave', () => {
  isDrawing = false;
});

// ── Save Drawing State for Undo ──
function saveDrawHistory() {
  drawHistory.push(canvas.toDataURL());
}

// ── Clear All Drawings ──
clearBtn.addEventListener('click', () => {
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  drawHistory = [];
});

// ── Undo Last Stroke ──
undoBtn.addEventListener('click', () => {
  if (drawHistory.length > 1) {
    drawHistory.pop();
    const imageData = new Image();
    imageData.src = drawHistory[drawHistory.length - 1];
    imageData.onload = () => {
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      ctx.drawImage(imageData, 0, 0);
    };
  } else if (drawHistory.length === 1) {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    drawHistory = [];
  }
});
</script>


================================================================================
COMPLETE EXAMPLE - HOW TO USE
================================================================================

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Page with Pen Toolbar</title>
  <style>
    body { margin: 0; padding: 0; font-family: Arial, sans-serif; }
    
    /* ← PASTE CSS FROM SECTION 1 HERE → */
    
    .content { padding: 100px 20px; }
  </style>
</head>
<body>
  
  <!-- ← PASTE HTML FROM SECTION 2 HERE (at top of body) → -->
  
  <div class="content">
    <h1>Your Page Content</h1>
    <p>Draw on the page using the pen tool in the toolbar!</p>
  </div>
  
  <!-- ← PASTE JAVASCRIPT FROM SECTION 3 HERE (at end of body) → -->
  
</body>
</html>


================================================================================
FEATURES
================================================================================

✅ Draw anywhere on the page with smooth lines
✅ Choose pen color with color picker
✅ Adjust pen thickness with size slider
✅ Toggle pen mode on/off
✅ Undo last stroke
✅ Clear all drawings
✅ Sticky top bar (stays visible when scrolling)
✅ Fully responsive (desktop, tablet, mobile)
✅ Beautiful dark theme with smooth transitions
✅ Fixed canvas z-index so it floats above content


================================================================================
CUSTOMIZATION
================================================================================

1. Change Default Color:
   In HTML section, change value="#fbbf24" to any hex color
   Example: value="#ff0000" for red, value="#00ff00" for green

2. Change Top Title:
   Replace "My App Name" with your website/app name

3. Change Z-Index if needed:
   Canvas z-index: 90
   Top bar z-index: 100
   Adjust if other elements overlap

4. Change Button Emojis:
   ✏️ = Pen toggle
   🗑️ = Clear
   ↶ = Undo
   Replace with any emoji you like

5. Adjust Pen Size Range:
   min="1" max="20" value="3"
   Change max to allow thicker strokes

6. Change Colors:
   Replace #fbbf24 (yellow) with your brand color
   Replace #1a2236 (dark blue) with your theme color


================================================================================
BROWSER SUPPORT
================================================================================

✅ Chrome / Edge
✅ Firefox
✅ Safari
✅ Mobile browsers (iOS Safari, Chrome Mobile)

Requires:
- Canvas API support
- ES6 JavaScript (modern browsers)
- No external libraries needed


================================================================================
