
:root {
  --pink: #e99db7;
  --pink-dark: #ce7899;
  --pink-light: #fff0f5;
  --lavender: #eee8fa;
  --cream: #fffaf6;
  --ink: #443d49;
  --muted: #716977;
  --border: #e8dfe8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "Trebuchet MS", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
.upload-zone:focus-visible {
  outline: 3px solid #8063b5;
  outline-offset: 3px;
}

.hidden {
  display: none !important;
}

.app {
  max-width: 1180px;
  margin: auto;
  padding: 20px;
}

.app-header {
  text-align: center;
  padding: 24px 10px 30px;
}

.header-icon {
  font-size: 36px;
  color: var(--pink-dark);
}

h1 {
  margin: 4px 0 8px;
  font-size: clamp(28px, 5vw, 40px);
}

.app-header p,
.section-description,
.helper-text {
  color: var(--muted);
  line-height: 1.5;
}

.workspace {
  display: grid;
  grid-template-columns:
    minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.reference-panel,
.palette-panel {
  background: white;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 6px 24px #5e43500b;
  min-width: 0;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

h2 {
  font-size: 19px;
  margin: 0;
}

.step {
  background: var(--lavender);
  border-radius: 30px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: bold;
}

.upload-zone {
  position: relative;
  min-height: 340px;
  background: #f8f5fb;
  border: 2px dashed #d7c9df;
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s;
}

.upload-zone.dragover {
  border-color: var(--pink-dark);
  background: var(--pink-light);
}

.upload-placeholder {
  text-align: center;
  padding: 30px;
}

.upload-icon {
  font-size: 60px;
  color: var(--pink-dark);
}

.upload-placeholder h3 {
  margin: 8px 0;
}

.upload-placeholder p {
  font-size: 14px;
  line-height: 1.5;
}

.upload-hint {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 30px;
  background: white;
  color: var(--muted);
  font-size: 12px;
}

.image-container {
  width: 100%;
  height: 340px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: none;
}

#referenceCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.image-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.soft-button,
.icon-button {
  border: 1px solid var(--border);
  background: var(--pink-light);
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 14px;
  min-height: 44px;
}

.icon-button {
  min-width: 44px;
}

.helper-text {
  font-size: 12px;
  text-align: center;
}

.section-description {
  font-size: 13px;
  margin-bottom: 20px;
}

.swatch-grid {
  display: grid;
  grid-template-columns:
    repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.swatch-item {
  min-width: 0;
  text-align: center;
}

.swatch-color {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid #e5dde5;
  border-radius: 18px;
  display: block;
  transition: transform 0.15s;
}

.swatch-color:active {
  transform: scale(0.96);
}

.swatch-name {
  display: block;
  width: 100%;
  min-height: 32px;
  padding: 5px 3px;
  margin-top: 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  text-align: center;
  text-overflow: ellipsis;
  transition:
    background 0.2s,
    border-color 0.2s;
}

.swatch-name:hover,
.swatch-name:focus {
  background: var(--pink-light);
  border-color: var(--pink);
  outline: none;
}

.swatch-name::placeholder {
  color: var(--muted);
}

.add-button {
  width: 100%;
  min-height: 50px;
  margin-top: 20px;
  border: 2px dashed #d6b4c6;
  background: var(--pink-light);
  border-radius: 14px;
  color: #854765;
  font-weight: bold;
}

.add-button span {
  font-size: 22px;
  vertical-align: middle;
}

.export-actions {
  margin-top: 28px;
  display: grid;
  gap: 10px;
}

.primary-button {
  background: var(--pink-dark);
  color: white;
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  min-height: 48px;
  font-weight: bold;
}

.primary-button:hover {
  background: #b65f83;
}

.reset-button,
.delete-button {
  border: none;
  background: transparent;
  color: #9b516a;
  min-height: 44px;
}

footer {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 30px 10px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: #29212e99;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
  padding: 16px;
}

.editor-modal {
  width: 100%;
  max-width: 420px;
  max-height: 90dvh;
  overflow-y: auto;
  background: white;
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 12px 50px #0002;
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.close-button {
  border: none;
  background: var(--lavender);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 25px;
}

.editor-modal label {
  display: block;
  font-size: 13px;
  font-weight: bold;
  margin: 15px 0 8px;
}

#colorName {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 46px;
}

.picker-area {
  position: relative;
  height: 190px;
  background: red;
  border-radius: 12px;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}

.picker-white,
.picker-black {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.picker-white {
  background:
    linear-gradient(to right, white, transparent);
}

.picker-black {
  background:
    linear-gradient(to top, black, transparent);
}

.picker-cursor {
  position: absolute;
  width: 17px;
  height: 17px;
  border: 2px solid white;
  box-shadow: 0 0 0 1px #333;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.hue-area {
  height: 24px;
  border-radius: 20px;
  margin: 18px 0;
  position: relative;
  background: linear-gradient(
    to right,
    red,
    yellow,
    lime,
    cyan,
    blue,
    magenta,
    red
  );
  touch-action: none;
}

.hue-cursor {
  position: absolute;
  top: 50%;
  width: 15px;
  height: 32px;
  background: white;
  border: 2px solid #555;
  border-radius: 8px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.selected-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.preview-color {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.sample-button {
  width: 100%;
  margin-top: 20px;
}

.sample-help {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 13px 20px;
  border-radius: 14px;
  z-index: 30;
  text-align: center;
  max-width: 90vw;
  box-shadow: 0 5px 20px #0002;
}

@media (max-width: 700px) {
  .app {
    padding: 12px;
  }

  .app-header {
    padding: 15px 0 20px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .reference-panel,
  .palette-panel {
    padding: 15px;
    border-radius: 20px;
  }

  .upload-zone {
    min-height: 220px;
  }

  .image-container {
    height: 260px;
  }

  .swatch-grid {
    gap: 10px;
  }

  .swatch-color {
    border-radius: 14px;
  }

  .swatch-name {
    font-size: 11px;
    min-height: 36px;
  }

  .editor-modal {
    padding: 17px;
  }

  .picker-area {
    height: 170px;
  }
}

@media (max-width: 360px) {
  .swatch-grid {
    gap: 7px;
  }

  .swatch-color {
    border-radius: 11px;
  }
}
