* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #1a1a1a;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#toolbar {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(30, 30, 30, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 8px 14px;
  z-index: 100;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.tool-group:last-child {
  border-right: none;
}

.tool-group.right {
  margin-left: auto;
}

.tool-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  transition: all 0.15s ease;
  padding: 6px;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.9);
}

.tool-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.tool-btn svg {
  width: 18px;
  height: 18px;
}

#colorPicker {
  width: 30px;
  height: 30px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  cursor: pointer;
  background: none;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
}

#colorPicker::-webkit-color-swatch-wrapper {
  padding: 0;
}

#colorPicker::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

.swatch-group {
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

#swatch-grid {
  display: grid;
  grid-template-columns: repeat(10, 20px);
  gap: 4px;
}

.swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
  position: relative;
}

.swatch:hover {
  transform: scale(1.15);
}

.swatch.active {
  border-color: rgba(255, 255, 255, 0.6);
}

.swatch-remove {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 12px;
  height: 12px;
  background: #ff4444;
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 8px;
  line-height: 12px;
  text-align: center;
  cursor: pointer;
  display: none;
  padding: 0;
  z-index: 2;
}

.swatch:hover .swatch-remove {
  display: block;
}

.swatch-add {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px dashed rgba(255, 255, 255, 0.25);
  background: transparent;
  color: rgba(255, 255, 255, 0.4);
  font-size: 14px;
  line-height: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
}

.swatch-add:hover {
  border-color: rgba(255, 255, 255, 0.5);
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.06);
}

.slider-label {
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  white-space: nowrap;
}

input[type="range"] {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  outline: none;
}

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

#brushSizeVal, #opacityVal {
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  min-width: 28px;
  text-align: center;
}

#zoomLevel {
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  min-width: 38px;
  text-align: center;
}

#status-widget {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(30, 30, 30, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 6px 14px;
  z-index: 50;
}

.status-field {
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-field label {
  color: rgba(255, 255, 255, 0.4);
  font-size: 13px;
  font-weight: 600;
}

.status-field input {
  width: 64px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  padding: 4px 6px;
  text-align: right;
  outline: none;
  -moz-appearance: textfield;
}

.status-field input::-webkit-inner-spin-button,
.status-field input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.status-field input:focus {
  border-color: #4d96ff;
  color: #fff;
}

.status-separator {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.12);
}

#rotationLevel {
  color: rgba(255, 255, 255, 0.5);
  font-size: 13px;
  min-width: 36px;
  text-align: center;
}

#resetRotation,
#resetPosition {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  padding: 3px;
  display: flex;
  align-items: center;
  border-radius: 5px;
}

#resetRotation:hover,
#resetPosition:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

#center-dot {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  background: #ff3333;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  z-index: 100;
  pointer-events: none;
  display: none;
}

#cursor-preview {
  position: fixed;
  pointer-events: none;
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  z-index: 99;
  display: none;
  transform: translate(-50%, -50%);
}

/* Hide default cursor on canvas when drawing */
body.drawing #canvas {
  cursor: none;
}

body.panning #canvas {
  cursor: grab;
}

body.panning-active #canvas {
  cursor: grabbing;
}

body.tool-pen #canvas,
body.tool-eraser #canvas {
  cursor: none;
}

body.tool-hand #canvas {
  cursor: grab;
}

/* --- Modals (shared) --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay.hidden {
  display: none;
}

.modal-overlay > div {
  background: #222;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 28px 32px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

#settings-modal {
  width: 460px;
}

.modal-footer {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.settings-header h2 {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
}

.settings-header .tool-btn {
  font-size: 20px;
  width: 32px;
  height: 32px;
}

.settings-hint {
  color: rgba(255, 255, 255, 0.45);
  font-size: 13px;
  margin-bottom: 20px;
}

#bindings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.binding-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  transition: border-color 0.15s;
}

.binding-row:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.binding-row.listening {
  border-color: #4d96ff;
  background: rgba(77, 150, 255, 0.08);
}

.binding-action {
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
}

.binding-key-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.7);
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
  min-width: 100px;
  text-align: center;
  transition: all 0.15s;
  font-family: inherit;
}

.binding-key-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.binding-key-btn.listening {
  background: rgba(77, 150, 255, 0.15);
  border-color: #4d96ff;
  color: #4d96ff;
}

.settings-footer {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.settings-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.6);
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.settings-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.85);
}

.settings-btn.primary {
  background: #4d96ff;
  border-color: #4d96ff;
  color: #fff;
}

.settings-btn.primary:hover {
  background: #3a80e8;
  border-color: #3a80e8;
}

/* --- Color picker modal --- */
#color-modal {
  width: 340px;
}

#color-editor {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
}

#color-picker-custom {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#colorSatVal {
  width: 100%;
  height: 160px;
  border-radius: 10px;
  cursor: crosshair;
}

#colorHueStrip {
  width: 100%;
  height: 16px;
  border-radius: 8px;
  cursor: pointer;
}

#color-preview-row {
  display: flex;
  width: 100%;
  gap: 8px;
}

#color-preview-old,
#color-preview-new {
  flex: 1;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.color-preview-label {
  font-size: 11px;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  color: #fff;
  mix-blend-mode: difference;
}

#color-hex-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

#colorHexInput {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #fff;
  padding: 8px 12px;
  font-size: 14px;
  font-family: monospace;
  outline: none;
}

#colorHexInput:focus {
  border-color: #4d96ff;
}
