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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #EFEFEF;
  font-family: Arial, sans-serif;
  color: black;
  overflow: hidden;
  touch-action: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

#canvasContainer {
  position: relative;
  width: 768px;
  height: 1024px;
  max-width: 100vw;
  max-height: 100vh;
}

canvas {
  display: block;
  background: #ffffff;
  border: 1px solid #aaa;
  cursor: none;
  touch-action: none;
  width: 100%;
  height: 100%;
}

/* Top Controls */
#topControls {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  z-index: 1000;
  background: rgba(255,255,255,0.95);
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

#topControls .control-group {
  background: transparent;
  padding: 0;
  box-shadow: none;
  min-width: 200px;
}

#topControls input[type="range"] {
  width: 200px;
  height: 8px;
  -webkit-appearance: none;
  appearance: none;
  background: #ddd;
  border-radius: 4px;
  outline: none;
}

#topControls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: #007AFF;
  border-radius: 50%;
  cursor: pointer;
}

#topControls input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: #007AFF;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

/* Color Picker */
#colorpick_div {
  position: fixed;
  top: 70px;
  left: 8px;
  z-index: 1000;
}

/* Left Panel */
#leftPanel {
  position: fixed;
  top: 130px;
  left: 8px;
  max-height: calc(100vh - 140px);
  width: 50px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  overflow-y: auto;
}

/* Palette */
#palette {
  background: rgba(255,255,255,0.95);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.palette-color {
  width: 34px;
  height: 34px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.2s ease;
  flex-shrink: 0;
}

.palette-color:hover {
  border-color: #666;
}

.palette-color.selected {
  border-color: black;
  border-width: 3px;
}

/* Right Panel */
#rightPanel {
  position: fixed;
  top: 70px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.control-group {
  background: rgba(255,255,255,0.95);
  padding: 8px 12px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.control-group input[type="range"] {
  width: 140px;
}

.control-group select {
  width: 140px;
  padding: 4px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.adjust-btn {
  flex: 1;
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-weight: bold;
}

/* Toggle Switch */
.toggle-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: #ccc;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-switch.active {
  background: #007AFF;
}

.toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: left 0.3s;
}

.toggle-switch.active .toggle-knob {
  left: 22px;
}

/* Bottom Controls */
#bottomControls {
  position: fixed;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 8px;
  z-index: 1000;
  flex-wrap: wrap;
  max-width: calc(100vw - 16px);
  justify-content: flex-end;
}

#bottomControls button {
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  background: rgba(255,255,255,0.95);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
  transition: background 0.2s;
}

#bottomControls button:active {
  background: #e0e0e0;
}

.face-btn {
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  background: rgba(100,200,255,0.95);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
  transition: background 0.2s;
}

.face-btn:active {
  background: rgba(80,180,235,0.95);
}

.body-btn {
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  background: rgba(255,200,100,0.95);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
  transition: background 0.2s;
}

.body-btn:active {
  background: rgba(235,180,80,0.95);
}

.tat-body-btn {
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  background: rgba(200,150,255,0.95);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
  transition: background 0.2s;
}

.tat-body-btn:active {
  background: rgba(180,130,235,0.95);
}

/* Color Preview Button */
#colorDisplay {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 2px solid #333;
  cursor: pointer;
  background-color: #000000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transition: transform 0.2s ease;
}

#colorDisplay:active {
  transform: scale(0.95);
}

/* Custom Color Picker */
#colorPickerOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 2000;
}

#colorPickerOverlay.active {
  opacity: 1;
  pointer-events: auto;
}

#customColorPicker {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  width: 280px;
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 2001;
}

#customColorPicker.active {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

#svPicker {
  position: relative;
  width: 100%;
  height: 200px;
  border-radius: 8px;
  cursor: crosshair;
  margin-bottom: 10px;
}

#svCursor {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000;
  transform: translate(-7px, -7px);
}

#huePicker {
  position: relative;
  height: 24px;
  border-radius: 12px;
  background: linear-gradient(
    to right,
    red, yellow, lime, cyan, blue, magenta, red
  );
  cursor: pointer;
  margin-bottom: 10px;
}

#hueCursor {
  position: absolute;
  top: 0;
  width: 4px;
  height: 100%;
  background: #000;
}

#colorPickerClose {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: none;
  font-weight: bold;
  background: #000;
  color: #fff;
  cursor: pointer;
}

/* Mobile Adjustments */
@media (max-width: 768px), (max-height: 768px) {
  #topControls {
    flex-direction: column;
    gap: 8px;
    padding: 8px 12px;
  }
  
  #topControls .control-group {
    min-width: 160px;
  }
  
  #topControls input[type="range"] {
    width: 160px;
  }
  
  #colorpick_div {
    top: 56px;
    left: 4px;
  }
  
  #leftPanel {
    top: 100px;
    left: 4px;
    width: 44px;
  }
  
  .palette-color {
    width: 32px;
    height: 32px;
  }
  
  #rightPanel {
    top: 56px;
    right: 4px;
    gap: 6px;
  }
  
  #bottomControls {
    bottom: 4px;
    right: 4px;
    gap: 6px;
  }
  
  #bottomControls button {
    padding: 8px 12px;
    font-size: 11px;
  }
}

@media (max-width: 480px) {
  #topControls .control-group {
    min-width: 140px;
  }
  
  #topControls input[type="range"] {
    width: 140px;
  }
}
