#wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background-color: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

h1 {
  font-size: 1.2rem;
  margin: 0;
}

button {
  padding: 8px 15px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1rem;
}

button:active {
  background-color: #45a049;
}

#back-btn {
  background-color: #888;
}

#canvas-container {
  flex: 1;
  position: relative;
  background-color: #fff;
  /* Desk color */
  cursor: crosshair;
  overflow: hidden;
  padding: 10px;
  /* 10px Spacing acting as margin */
  display: flex;
  justify-content: center;
  align-items: center;
}

#drawing-canvas {
  display: block;
  background-color: #fff;
  /* Paper color */
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  /* Paper shadow */
  touch-action: none;
  border: 1px solid #d4d4d4;
  /* Requested border */
  /* Disable default touch actions like scroll */
  /* Will be measured by JS */
}

#toolbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  /* Removed padding to let button touch the top */
  background-color: #ffffff;
  /* Transparent so the button shape stands out */
  border-top: none;
  /* Moved border to content */
  z-index: 10;
  width: 100%;
}

#toolbar-content {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 25px;
  flex-wrap: wrap;
  padding: 15px;
  background-color: #fff;
  border-top: 1px solid #ddd;
  width: 100%;
  box-sizing: border-box;
  transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
  overflow: hidden;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.03);
  /* Subtle shadow for depth */
}

#toolbar-content.collapsed {
  max-height: 0;
  opacity: 0;
  padding: 0;
  border-top: none;
}

.toggle-btn {
  background-color: #fff;
  /* Match toolbar content */
  color: #555;
  padding: 8px 30px;
  font-size: 0.9rem;
  border: 1px solid #ddd;
  border-bottom: 1px solid #fff;
  /* Hide bottom border to merge */
  border-radius: 10px 10px 0 0;
  margin-bottom: -1px;
  /* Overlap the content border */
  cursor: pointer;
  transition: all 0.2s;
  z-index: 20;
  /* Above content */
  font-weight: bold;
}

.toggle-btn:hover {
  background-color: #f5f5f5;
  color: #333;
}

/* Color Palette */
.palette {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  max-width: 300px;
  justify-content: center;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: transform 0.1s;
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.active {
  border-color: #333;
  box-shadow: 0 0 0 2px #fff inset;
  transform: scale(1.2);
}

input[type="range"] {
  width: 150px;
  /* 1.5x of 100px */
  height: 8px;
  cursor: pointer;
}

#brush-size-value {
  min-width: 25px;
  text-align: center;
  font-weight: bold;
}

#current-color-indicator {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #333;
  background-color: #000000;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 15px;
  background-color: #f8f8f8;
  border-radius: 8px;
  border: 1px solid #eee;
}

.tool-group label {
  font-weight: bold;
  color: #555;
  font-size: 0.9rem;
}

.tool-group button {
  background-color: #ddd;
  color: #333;
}

.tool-group button.active {
  background-color: #2196F3;
  color: white;
}

/* Mobile responsive adjustments */
#wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  /* Fallback */
  height: 100dvh;
  /* Mobile browser friendly */
}

/* ... existing styles ... */

/* Eraser Cursor */
#brush-cursor {
  position: absolute;
  pointer-events: none;
  border: 1px solid #000;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  display: none;
  z-index: 20;
  background-color: rgba(255, 255, 255, 0.5);
  /* Semi-transparent white */
}

/* Mobile responsive adjustments */
@media (max-width: 600px) {
  header h1 {
    font-size: 1rem;
  }

  header {
    padding: 5px 10px;
    /* Reduce header height */
  }

  #toolbar {
    flex-wrap: wrap;
    gap: 5px;
    padding: 5px;
  }

  .tool-group {
    /* Remove width: 100% to allow side-by-side if space permits */
    /* width: 100%; */
    justify-content: center;
    flex-grow: 1;
    /* Allow sharing space */
  }

  /* Make inputs smaller on mobile */
  /* Make inputs smaller on mobile */
  /* input[type="color"] removed */

  button {
    padding: 5px 10px;
    font-size: 0.9rem;
  }
}

footer {
  text-align: center;
  padding: 10px;
  font-size: 0.8rem;
  color: #888;
  background-color: #f9f9f9;
}

/* Color Picker Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  /* Force on top */
}

.modal.hidden {
  display: none;
}

.color-picker-content,
#background-modal .modal-content {
  background-color: #ffffff;
  padding: 0;
  border-radius: 15px;
  width: 90%;
  max-width: 350px;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  border: 1px solid #eee;
}

#background-modal h2,
.color-picker-content h2 {
  margin: 0;
  padding: 15px;
  background-color: #f0f4f8;
  /* Soft blue-gray */
  color: #333;
  font-size: 1.1rem;
  border-bottom: 1px solid #e0e0e0;
}

.modal-body {
  padding: 20px;
}

.option-group {
  margin-bottom: 15px;
  text-align: left;
}

.option-group h3 {
  font-size: 0.95rem;
  color: #666;
  margin-bottom: 10px;
}

.option-group input[type="file"] {
  display: block;
  width: 100%;
  padding: 8px;
  background-color: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 5px;
}

.option-group input[type="color"] {
  width: 100%;
  height: 40px;
  border: none;
  cursor: pointer;
  background: none;
}

hr {
  border: 0;
  height: 1px;
  background-color: #eee;
  margin: 15px 0;
}

.modal-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 0 20px 20px 20px;
}

.color-picker-body {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-bottom: 20px;
}

.sv-wrapper,
.hue-wrapper {
  position: relative;
  cursor: crosshair;
}

#sv-cursor {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 0 2px black;
  pointer-events: none;
  transform: translate(-50%, -50%);
  top: 0;
  left: 100%;
}

#hue-cursor {
  position: absolute;
  width: 30px;
  height: 6px;
  border: 2px solid white;
  box-shadow: 0 0 2px black;
  pointer-events: none;
  left: -2px;
  top: 0;
}

.color-preview-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 20px;
}

#new-color-preview {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #000;
  border: 2px solid #ddd;
}

.modal-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.modal-buttons button {
  min-width: 80px;
}

.secondary {
  background-color: #888;
}

.primary {
  background-color: #4CAF50;
}