/* Scratchpad floating styles */
.scratchpad-fab {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #f8fafc;
  border: 1.5px solid #334155;
  border-radius: 9999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.4), 0 8px 10px -6px rgba(15, 23, 42, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
}
.scratchpad-fab:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 14px 28px -4px rgba(15, 23, 42, 0.5);
  background: linear-gradient(135deg, #334155, #1e293b);
}
.scratchpad-fab:active {
  transform: translateY(0) scale(0.98);
}
.scratchpad-fab.has-drawing::after {
  content: '';
  width: 9px;
  height: 9px;
  background: #22c55e;
  border: 2px solid #0f172a;
  border-radius: 50%;
  margin-left: 2px;
}

/* Modal / Bottom sheet overlay */
.scratchpad-panel {
  position: fixed;
  z-index: 101;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid #334155;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: height 0.25s cubic-bezier(0.16, 1, 0.3, 1), width 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}

/* Desktop / Tablet floating window */
@media (min-width: 769px) {
  .scratchpad-panel {
    bottom: 24px;
    left: 24px;
    width: 640px;
    max-width: calc(100vw - 48px);
    height: 480px;
    max-height: calc(100vh - 48px);
    border-radius: 18px;
  }
  .scratchpad-panel.expanded {
    width: 940px;
    height: calc(100vh - 48px);
  }
}

/* Mobile bottom sheet */
@media (max-width: 768px) {
  .scratchpad-panel {
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 52vh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
  }
  .scratchpad-panel.expanded {
    height: calc(100vh - 30px);
  }
}

.scratchpad-panel[hidden] {
  display: none !important;
}

/* Header */
.scratchpad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  user-select: none;
}
.scratchpad-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  color: #e2e8f0;
}
.scratchpad-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.scratchpad-btn-icon {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  line-height: 1;
}
.scratchpad-btn-icon:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}
.scratchpad-btn-icon.active {
  background: #3b82f6;
  border-color: #60a5fa;
  color: #ffffff;
}

/* Canvas Area */
.scratchpad-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #090d16;
  touch-action: none;
}
.scratchpad-canvas-wrap.grid-bg {
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(to right, rgba(255, 255, 255, 0.14) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.14) 1px, transparent 1px);
  background-size: 20px 20px, 20px 20px, 100px 100px, 100px 100px;
}
.scratchpad-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* Bottom Toolbar */
.scratchpad-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #1e293b;
  border-top: 1px solid #334155;
  gap: 8px;
  flex-wrap: wrap;
}
.scratchpad-tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.scratchpad-color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
  padding: 0;
  outline: none;
}
.scratchpad-color-dot:hover {
  transform: scale(1.15);
}
.scratchpad-color-dot.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.4);
  transform: scale(1.15);
}
.scratchpad-size-pill {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.scratchpad-size-pill.active {
  background: #38bdf8;
  border-color: #7dd3fc;
  color: #0f172a;
  font-weight: 700;
}

/* on a phone the button sits bottom-left above the Previous / Next bar so it never covers it */
@media (max-width: 768px) {
  .scratchpad-fab { left: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); padding: 9px 14px; }
}
