* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: #333;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

header {
  text-align: center;
  margin-bottom: 40px;
  color: white;
}

header h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  font-weight: 700;
}

header p {
  font-size: 1.1rem;
  opacity: 0.9;
}

/* Upload Section */
.upload-section {
  margin-bottom: 40px;
}

.upload-area {
  background: white;
  border: 3px dashed #ddd;
  border-radius: 12px;
  padding: 60px 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}

.upload-area:hover {
  border-color: #667eea;
  background: #f8f9ff;
}

.upload-area.dragover {
  border-color: #667eea;
  background: #f0f4ff;
  transform: scale(1.02);
}

.upload-content svg {
  color: #667eea;
  margin-bottom: 20px;
}

.upload-content h3 {
  font-size: 1.3rem;
  margin-bottom: 8px;
  color: #333;
}

.upload-content p {
  color: #666;
  font-size: 0.95rem;
}

.loading-spinner {
  text-align: center;
  padding: 40px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.spinner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.processing-text {
  font-size: 1.1rem;
  color: #333;
  font-weight: 600;
}

.processing-steps {
  font-size: 0.9rem;
  color: #666;
  text-align: center;
  max-width: 300px;
}

.step {
  opacity: 0.3;
  transition: opacity 0.5s ease;
  margin: 5px 0;
}

.step.active {
  opacity: 1;
  color: #667eea;
  font-weight: 600;
}

/* Editor Section */
.editor-section {
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.toolbar {
  display: flex;
  flex-wrap: nowrap; /* keep one row */
  align-items: center;
  justify-content: center;
  gap: 12px; /* was 20px */
  padding: 10px 12px; /* was 20px */
  background: #f8f9fa;
  border-bottom: 1px solid #dee2e6;
  overflow-x: auto; /* keep; we'll hide the bar just in case */
  -ms-overflow-style: none; /* IE/Edge hides scrollbar */
  scrollbar-width: none; /* Firefox hides scrollbar */
}
.toolbar::-webkit-scrollbar {
  display: none;
} /* Chrome/Safari hides scrollbar */

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px; /* was 10px */
  padding: 4px; /* compact “pill” group */
  background: #f3f5f7;
  border-radius: 10px;
  flex: 0 0 auto; /* don’t shrink groups weirdly */
  min-width: 0;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px; /* was 8px */
  padding: 6px 10px; /* was 8px 16px */
  border: 2px solid #ddd;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem; /* was 0.9rem */
  transition: all 0.2s ease;
  white-space: nowrap; /* keep labels on one line */
}

/* stack text inside brush buttons */
.tool-btn .label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
}

.tool-btn .title {
  font-weight: 700;
}

.toolbar .hint {
  opacity: 0.85;
  font-size: 10px;
  margin: 2px 0 0 0;
  color: #4b5563; /* default hint color */
  transition: color 0.15s ease; /* smooth hover/active change */
}

/* When a brush button is active, make the hint white-ish */
.tool-btn.active .hint {
  color: rgba(255, 255, 255, 0.9);
}

/* If the active brush is hovered, make the hint dark gray */
.tool-btn.active:hover .hint {
  color: #ffffff; /* very dark gray */
}

/* Hover color for hint text (non-active buttons only) */
.tool-btn:not(.active):hover .hint {
  color: #1f2937; /* dark gray */
}

/* Button hover styling (skip active buttons) */
.tool-btn:not(.active):hover {
  border-color: #667eea;
  color: #667eea;
}

/* compact +/- and label */
#zoomInBtn,
#zoomOutBtn {
  width: 34px;
  min-width: 34px;
  padding: 6px;
  justify-content: center;
}
#zoomLabel {
  min-width: 48px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.tool-btn:hover {
  border-color: #667eea;
  color: #667eea;
}

.tool-btn.active {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.brush-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
}

.brush-icon.green {
  background: #28a745;
  border-color: #28a745;
}

.brush-icon.red {
  background: #dc3545;
  border-color: #dc3545;
}

#brushSize,
#tolerance {
  width: 90px;
}

#brushSizeValue,
#toleranceValue {
  min-width: 20px;
  text-align: center;
  font-weight: 600;
}

/* Canvas Container */
.canvas-container {
  padding: 20px;
  background: #f8f9fa;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
  overflow: auto;
  max-height: 75vh;
  display: block;
  text-align: center;
}

.canvas-container.hand {
  cursor: grab;
}
.canvas-container.hand.dragging {
  cursor: grabbing;
}

.canvas-wrapper {
  position: relative;
  display: inline-block;
  border-radius: 8px;
  overflow: visible;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  /* Checkered background to show transparency */
  background-image: linear-gradient(45deg, #ddd 25%, transparent 25%),
    linear-gradient(-45deg, #ddd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ddd 75%),
    linear-gradient(-45deg, transparent 75%, #ddd 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.canvas-wrapper canvas {
  display: block;
  max-width: none;
  height: auto;
}

#mainCanvas {
  position: relative;
  cursor: crosshair;
}

#overlayCanvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  opacity: 0.3;
}

/* Controls */
.controls {
  padding: 20px;
  text-align: center;
  display: flex;
  gap: 15px;
  justify-content: center;
}

.btn-primary,
.btn-secondary {
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: #667eea;
  color: white;
}

.btn-primary:hover {
  background: #5a6fd8;
  transform: translateY(-2px);
}

.btn-secondary {
  background: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background: #5a6268;
  transform: translateY(-2px);
}

/* Custom cursor */
.brush-cursor {
  position: absolute;
  border: 2px solid;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1000;
  transform: translate(-50%, -50%);
  display: none;
}

.brush-cursor.green {
  border-color: #28a745;
  background: rgba(40, 167, 69, 0.2);
}

.brush-cursor.red {
  border-color: #dc3545;
  background: rgba(220, 53, 69, 0.2);
}

.brush-cursor.active {
  display: block;
}

/* === Upload options centering + theme === */
.preset-format-group {
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 900px;
  margin: 8px auto 12px;
  gap: 24px;
}
.preset-format-group .tool-group {
  display: inline-flex !important;
  align-items: center;
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
.preset-format-group label {
  color: #eef2ff;
  font-weight: 500;
  margin-right: 10px;
}
.preset-format-group select {
  height: 38px;
  padding: 6px 12px;
  background: #fff;
  color: #1f2a44;
  border: 1px solid #d7def3;
  border-radius: 10px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    padding: 15px;
  }

  header h1 {
    font-size: 2rem;
  }

  .upload-area {
    padding: 40px 20px;
  }

  .toolbar {
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
  }

  .toolbar .hint {
    display: none;
  }

  .tool-group {
    justify-content: center;
  }

  .controls {
    flex-direction: column;
  }

  .canvas-container {
    padding: 15px;
    text-align: center;
  }

  .preset-format-group label {
    display: none;
  }
}