// Hand-drawn-feeling SVG accents. Slightly wobbly paths, never geometric perfection.
// Each component is a span/svg you place absolutely or inline.

const Scribble = {};

// Rough oval circling a word. Two passes (slightly offset) for the "scribbled twice" look.
Scribble.Circle = ({ color = "#E63946", strokeWidth = 3, rough = 0.6, style = {} }) => (
  <svg viewBox="0 0 240 90" preserveAspectRatio="none"
       style={{ position: "absolute", inset: 0, width: "100%", height: "100%", overflow: "visible", pointerEvents: "none", ...style }}>
    <path d="M 18 46 Q 14 22, 60 14 Q 130 4, 200 12 Q 232 18, 224 50 Q 218 78, 150 82 Q 70 88, 28 76 Q 6 68, 18 46 Z"
          fill="none" stroke={color} strokeWidth={strokeWidth} strokeLinecap="round" strokeLinejoin="round" opacity="0.9" />
    <path d="M 22 50 Q 24 28, 70 18 Q 140 8, 196 16 Q 226 22, 220 48 Q 214 74, 146 80 Q 74 86, 32 74"
          fill="none" stroke={color} strokeWidth={strokeWidth * 0.7} strokeLinecap="round" opacity="0.55" />
  </svg>
);

// Wobbly underline that sits below text.
Scribble.Underline = ({ color = "#2867D5", strokeWidth = 4, style = {} }) => (
  <svg viewBox="0 0 220 30" preserveAspectRatio="none"
       style={{ position: "absolute", left: 0, right: 0, bottom: "-0.15em", width: "100%", height: "0.45em", overflow: "visible", pointerEvents: "none", ...style }}>
    <path d="M 4 18 Q 50 8, 110 14 Q 170 20, 216 10"
          fill="none" stroke={color} strokeWidth={strokeWidth} strokeLinecap="round" />
    <path d="M 8 24 Q 60 16, 120 22 Q 180 26, 214 18"
          fill="none" stroke={color} strokeWidth={strokeWidth * 0.6} strokeLinecap="round" opacity="0.5" />
  </svg>
);

// Highlighter swipe — fat translucent stroke behind text.
Scribble.Highlight = ({ color = "#FFE166", style = {} }) => (
  <svg viewBox="0 0 220 60" preserveAspectRatio="none"
       style={{ position: "absolute", left: "-4%", right: "-4%", top: "10%", width: "108%", height: "90%", zIndex: -1, pointerEvents: "none", ...style }}>
    <path d="M 6 30 Q 60 18, 120 26 Q 180 34, 214 22 L 212 44 Q 160 56, 96 50 Q 38 46, 8 52 Z"
          fill={color} opacity="0.85" />
  </svg>
);

// Strikethrough wobble.
Scribble.Strike = ({ color = "#1A1714", strokeWidth = 3, style = {} }) => (
  <svg viewBox="0 0 220 20" preserveAspectRatio="none"
       style={{ position: "absolute", left: 0, right: 0, top: "50%", width: "100%", height: "0.4em", overflow: "visible", pointerEvents: "none", transform: "translateY(-50%)", ...style }}>
    <path d="M 4 12 Q 60 4, 120 10 Q 180 16, 216 8"
          fill="none" stroke={color} strokeWidth={strokeWidth} strokeLinecap="round" />
  </svg>
);

// Curving arrow with arrowhead. direction: 'down-right' | 'down-left' | 'right' | 'down'
Scribble.Arrow = ({ color = "#1A1714", strokeWidth = 2.5, direction = "down-right", style = {} }) => {
  const paths = {
    "down-right": { vb: "0 0 140 120", d: "M 12 14 Q 8 60, 50 80 Q 92 96, 120 92", head: "M 110 84 L 124 92 L 116 106" },
    "down-left":  { vb: "0 0 140 120", d: "M 128 14 Q 132 60, 90 80 Q 48 96, 20 92", head: "M 30 84 L 16 92 L 24 106" },
    "right":      { vb: "0 0 160 60",  d: "M 8 30 Q 60 14, 120 30 Q 140 36, 152 32", head: "M 142 22 L 154 32 L 142 42" },
    "down":       { vb: "0 0 80 140",  d: "M 30 8 Q 70 50, 38 90 Q 30 110, 40 130",  head: "M 30 122 L 40 134 L 52 124" },
    "up-right":   { vb: "0 0 140 120", d: "M 12 106 Q 8 60, 50 40 Q 92 24, 120 28", head: "M 110 36 L 124 28 L 116 14" },
  };
  const p = paths[direction] || paths["down-right"];
  return (
    <svg viewBox={p.vb} preserveAspectRatio="none"
         style={{ overflow: "visible", pointerEvents: "none", ...style }}>
      <path d={p.d} fill="none" stroke={color} strokeWidth={strokeWidth} strokeLinecap="round" strokeLinejoin="round" />
      <path d={p.head} fill="none" stroke={color} strokeWidth={strokeWidth} strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
};

// Star/sparkle scribble for emphasis.
Scribble.Star = ({ color = "#E63946", strokeWidth = 2, size = 28, style = {} }) => (
  <svg viewBox="0 0 40 40" width={size} height={size}
       style={{ overflow: "visible", pointerEvents: "none", ...style }}>
    <path d="M 20 4 L 20 36 M 4 20 L 36 20 M 8 8 L 32 32 M 32 8 L 8 32"
          fill="none" stroke={color} strokeWidth={strokeWidth} strokeLinecap="round" />
  </svg>
);

// Rough numbered circle (for steps).
Scribble.NumberCircle = ({ n, color = "#1A1714", fill = "transparent", strokeWidth = 2.5, size = 64 }) => (
  <svg viewBox="0 0 80 80" width={size} height={size} style={{ overflow: "visible" }}>
    <path d="M 40 6 Q 70 8, 74 38 Q 76 70, 42 74 Q 10 76, 6 44 Q 4 12, 40 6 Z"
          fill={fill} stroke={color} strokeWidth={strokeWidth} strokeLinejoin="round" />
    <path d="M 40 10 Q 68 14, 72 40 Q 72 68, 42 70 Q 14 72, 10 44 Q 10 16, 40 10"
          fill="none" stroke={color} strokeWidth={strokeWidth * 0.5} opacity="0.4" />
    <text x="40" y="52" textAnchor="middle" fill={color}
          style={{ fontFamily: "'Caveat', cursive", fontSize: "44px", fontWeight: 700 }}>{n}</text>
  </svg>
);

// A coffee-cup ring stain (warm brown, semi-translucent).
Scribble.CoffeeStain = ({ color = "#8B6F47", style = {} }) => (
  <svg viewBox="0 0 200 200" style={{ overflow: "visible", pointerEvents: "none", ...style }}>
    <path d="M 100 14 Q 168 18, 184 88 Q 188 158, 116 184 Q 38 192, 18 124 Q 6 50, 100 14 Z
             M 100 30 Q 50 38, 38 96 Q 32 150, 92 168 Q 156 174, 170 110 Q 176 50, 100 30 Z"
          fill={color} opacity="0.25" fillRule="evenodd" />
    <path d="M 30 70 Q 22 58, 36 50" fill="none" stroke={color} strokeWidth="3" opacity="0.3" strokeLinecap="round" />
    <circle cx="160" cy="40" r="3" fill={color} opacity="0.3" />
    <circle cx="40" cy="160" r="2.5" fill={color} opacity="0.25" />
  </svg>
);

// Dashed/dotted hand-drawn divider line.
Scribble.Divider = ({ color = "#1A1714", style = {} }) => (
  <svg viewBox="0 0 800 24" preserveAspectRatio="none" style={{ width: "100%", height: 24, ...style }}>
    <path d="M 0 12 Q 100 4, 200 14 Q 300 22, 400 10 Q 500 2, 600 14 Q 700 22, 800 10"
          fill="none" stroke={color} strokeWidth="1.5" strokeLinecap="round" strokeDasharray="1 7" opacity="0.55" />
  </svg>
);

// A loose tape-strip background, like washi tape.
Scribble.Tape = ({ color = "#FFE166", style = {} }) => (
  <svg viewBox="0 0 200 40" preserveAspectRatio="none"
       style={{ position: "absolute", inset: 0, width: "100%", height: "100%", zIndex: -1, ...style }}>
    <path d="M 4 6 L 196 10 L 198 32 L 6 36 Z" fill={color} opacity="0.7" />
    <path d="M 4 6 L 196 10 L 198 32 L 6 36 Z" fill="none" stroke={color} strokeWidth="0.5" opacity="0.4" />
  </svg>
);

window.Scribble = Scribble;
