html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

.drawing-app {
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  background: #f5f5f7;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.drawing-app * {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

.canvas-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #f5f5f7;
}

#bgImageLayer,
#drawingCanvas {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

#bgImageLayer {
  display: none;
  pointer-events: none;
}

#drawingCanvas {
  display: block;
  touch-action: none;
}

.top-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 40;
  display: flex;
  gap: 6px;
}

.chip {
  appearance: none;
  border: none;
  border-radius: 12px;
  background: rgba(255,255,255,0.88);
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
  padding: 0 12px;
  height: 34px;
  font-size: 12px;
  font-weight: 700;
}

.chip.small {
  height: 32px;
  padding: 0 10px;
}

.tool-toggle {
  position: absolute;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 60;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 999px;
  background: rgba(255,255,255,0.9);
  box-shadow: 0 8px 24px rgba(0,0,0,0.14);
}

.tool-toggle-brush {
  position: absolute;
  width: 16px;
  height: 4px;
  border-radius: 99px;
  background: #111;
  left: 11px;
  top: 14px;
  transform: rotate(-30deg);
}

.tool-toggle-color {
  position: absolute;
  width: 12px;
  height: 12px;
  right: 7px;
  bottom: 7px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #000;
}

.tool-panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.tool-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
}

.tool-panel.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.panel-row {
  background: rgba(255,255,255,0.9);
  box-shadow: 0 8px 24px rgba(0,0,0,0.14);
  border-radius: 20px;
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-row-colors {
  align-items: center;
}

.brush-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 14px;
  background: rgba(255,255,255,0.95);
}

.brush-btn.active {
  background: #111;
  color: #fff;
}

.brush-preview {
  width: 18px;
  height: 18px;
  margin: 0 auto;
  position: relative;
}

.brush-preview.pen::before,
.brush-preview.marker::before,
.brush-preview.pencil::before,
.brush-preview.eraser::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-25deg);
  border-radius: 999px;
  background: currentColor;
}

.brush-preview.pen::before { width: 14px; height: 3px; }
.brush-preview.marker::before { width: 16px; height: 7px; opacity: 0.75; }
.brush-preview.pencil::before { width: 14px; height: 2px; background: transparent; box-shadow: 0 0 0 1px currentColor; }
.brush-preview.eraser::before { width: 12px; height: 9px; border-radius: 4px; }

#sizeSlider {
  flex: 1;
  min-width: 120px;
}

#colorWheel {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  touch-action: none;
  flex: 0 0 auto;
}

.swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255,255,255,0.95);
  border-radius: 50%;
  box-shadow: 0 3px 10px rgba(0,0,0,0.15);
  padding: 0;
  appearance: none;
}

@media (max-width: 640px) {
  .tool-panel {
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .top-actions {
    top: 8px;
    right: 8px;
  }
}