:root {
  --bg: #ffffff;
  --text: #111111;
  --muted: #6b6b6b;
  --line: #e9e9e9;
  --line-2: #efefef;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial,
    sans-serif;
  color: var(--text);
  background: #fafafa;
}

.app {
  min-height: 100%;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  box-shadow: var(--shadow);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-right: 12px;
  border-right: 1px solid var(--line);
}

.tool-btn {
  appearance: none;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  line-height: 1;
  font-size: 14px;
  transition: background-color 0.16s ease, border-color 0.16s ease,
    transform 0.08s ease;
}

.tool-icon {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
}

.tool-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

.tool-btn:active {
  transform: translateY(1px);
}

.tool-btn.is-selected {
  background: rgba(0, 0, 0, 0.08);
  border-color: rgba(0, 0, 0, 0.4);
}

.palette {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: var(--bg);
  padding: 0;
  cursor: pointer;
}

.swatch[data-color="#000000"] {
  background: #000;
  border-color: #000;
}
.swatch[data-color="#9BBF3F"] {
  background: #9bbf3f;
}
.swatch[data-color="#A8B5EA"] {
  background: #a8b5ea;
}
.swatch[data-color="#FFFFFF"] {
  background: #fff;
}

.swatch.is-selected {
  outline: 2px solid rgba(0, 0, 0, 0.65);
  outline-offset: 2px;
}

.save {
  appearance: none;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: #ffffff;
  color: #111;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  transition: background-color 0.16s ease, color 0.16s ease,
    box-shadow 0.16s ease, transform 0.08s ease;
}

.save:active {
  transform: translateY(1px);
}

.save:hover {
  background: #000000;
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
}

body[data-theme="dark"] .save {
  border-color: rgba(255, 255, 255, 0.2);
  background: #f5f5f5;
  color: #111111;
}

body[data-theme="dark"] .save:hover {
  background: #ffffff;
  color: #000000;
}

.icon-btn {
  appearance: none;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: transparent;
  cursor: pointer;
  color: var(--text);
  transition: background-color 0.16s ease, color 0.16s ease,
    border-color 0.16s ease;
  border-radius: 999px;
  display: grid;
  place-items: center;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

.model.is-active-target {
  outline: 2px solid rgba(0, 0, 0, 0.28);
  outline-offset: 2px;
}


.placed-image {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transform-origin: center center;
  cursor: grab;
  user-select: none;
  touch-action: none;
  z-index: 3;
  border: 1px dashed rgba(0, 0, 0, 0.45);
  border-radius: 10px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.28);
}

.placed-image:active {
  cursor: grabbing;
}

.placed-image img {
  display: block;
  width: 220px;
  height: auto;
  pointer-events: none;
  border-radius: 6px;
}

.resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.45);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  z-index: 4;
}

.resize-handle[data-dir="n"] {
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}
.resize-handle[data-dir="s"] {
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}
.resize-handle[data-dir="e"] {
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}
.resize-handle[data-dir="w"] {
  left: -5px;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}
.resize-handle[data-dir="ne"] {
  right: -5px;
  top: -5px;
  cursor: nesw-resize;
}
.resize-handle[data-dir="nw"] {
  left: -5px;
  top: -5px;
  cursor: nwse-resize;
}
.resize-handle[data-dir="se"] {
  right: -5px;
  bottom: -5px;
  cursor: nwse-resize;
}
.resize-handle[data-dir="sw"] {
  left: -5px;
  bottom: -5px;
  cursor: nesw-resize;
}

.placed-image.is-pinned {
  border: none;
  background: transparent;
  padding: 0;
}

.placed-image.is-pinned .resize-handle {
  display: none;
}

.is-saving .placed-image {
  border: none !important;
  background: transparent !important;
  padding: 0 !important;
}

.is-saving .img-controls,
.is-saving .resize-handle {
  display: none !important;
}

.img-controls {
  position: absolute;
  top: -14px;
  right: -8px;
  display: inline-flex;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  box-shadow: var(--shadow);
}

.img-controls button {
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  line-height: 1;
}

.img-controls button:hover {
  background: rgba(0, 0, 0, 0.04);
}


.placed-image.is-pinned {
  cursor: default;
}

.placed-image.is-pinned {
  pointer-events: none;
}

.placed-image.is-pinned .img-controls {
  display: none;
}


.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}


.undo {
  appearance: none;
  border: none;
  background: transparent;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 999px;
  cursor: pointer;
  color: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.undo:hover {
  background: rgba(0, 0, 0, 0.04);
}

.undo svg {
  display: block;
  stroke-width: 1.6;
}


.stage {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: calc(100vh - 70px);
}

.models {
  position: relative;
  display: grid;
  grid-template-columns: 0.9fr 1.1fr 0.9fr;
  gap: 12px;
  padding: 16px 20px;
  background: #f1f1f1;
}


.model {
  position: relative;
  border: 1px solid transparent;
  border-radius: 6px;
  overflow: hidden;
  background: #f6f6f6;
  display: grid;
  place-items: center;
  min-height: 260px;
}

.model.is-center {
  min-height: 340px;
}


.model-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.draw {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.garment-outline {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04) inset;
  background: rgba(255, 255, 255, 0.9);
  pointer-events: none;
}

.model.is-placeholder {
  background: linear-gradient(135deg, #f2f2f2, #f8f8f8);
}

.placeholder {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  text-align: center;
  color: #4a4a4a;
  font-size: 12px;
  line-height: 1.35;
}

.model.is-placeholder .placeholder {
  display: flex;
}

.placeholder code {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 6px;
}

.steps {
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding: 14px 24px;
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 18px;
}

.step {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border-right: 1px solid var(--line-2);
}

.step:last-child {
  border-right: none;
}

.num {
  font-size: 34px;
  font-weight: 200;
  line-height: 1;
  color: #1a1a1a;
}

.text {
  font-size: 12px;
  line-height: 1.35;
  color: #202020;
}


.tag {
  font-weight: 600;
}

.step-list {
  list-style: disc;
  padding-left: 16px;
  margin: 0;
}

.step-list li + li {
  margin-top: 2px;
}

@media (max-width: 1000px) {
  .topbar {
    grid-template-columns: 1fr auto auto auto;
    grid-template-areas:
      "tools center save right";
    padding: 18px 24px;
    gap: 16px;
    align-items: center;
  }

  .topbar-left {
    grid-area: tools;
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
  }

  .tools {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding-right: 12px;
    border-right: 1px solid var(--line);
  }

  .tool-btn {
    width: 34px;
    height: 34px;
  }

  .tool-icon {
    width: 18px;
    height: 18px;
  }

  .palette {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .swatch {
    width: 28px;
    height: 28px;
  }

  .save {
    grid-area: save;
    padding: 8px 18px;
    font-size: 13px;
  }

  .topbar-center {
    grid-area: center;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .topbar-right {
    grid-area: right;
    gap: 8px;
  }

  .undo {
    width: 32px;
    height: 32px;
  }

  .undo svg {
    width: 20px;
    height: 20px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .models {
    grid-template-columns: 1fr;
    padding: 12px 16px;
    gap: 10px;
  }

  .model {
    min-height: 240px;
  }

  .model.is-center {
    min-height: 280px;
  }

  .steps {
    grid-template-columns: 1fr;
    padding: 12px 16px;
    gap: 14px;
  }

  .step {
    border-right: none;
    border-bottom: 1px solid var(--line-2);
    padding: 8px 10px;
  }

  .step:last-child {
    border-bottom: none;
  }

  .num {
    font-size: 28px;
  }

  .text {
    font-size: 11px;
  }
}

@media (max-width: 640px) {
  .topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "tools right"
      "center center"
      "undo undo";
    padding: 18px 24px;
    gap: 12px;
    align-items: flex-start;
  }

  .topbar-left {
    grid-area: tools;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
  }

  .tools {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding-right: 0;
    border-right: none;
  }

  .tool-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .tool-icon {
    width: 18px;
    height: 18px;
  }

  .palette {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .swatch {
    width: 28px;
    height: 28px;
  }

  .topbar-center {
    grid-area: center;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-start;
  }

  .topbar-right {
    grid-area: right;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
  }

  .save {
    padding: 8px 18px;
    font-size: 13px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .icon-btn svg {
    width: 22px;
    height: 22px;
  }

  .undo {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .undo svg {
    width: 20px;
    height: 20px;
  }

  .topbar-right .undo {
    width: 32px;
    height: 32px;
  }

  .models {
    padding: 16px 20px;
    gap: 12px;
  }

  .model {
    min-height: 260px;
  }

  .model.is-center {
    min-height: 340px;
  }

  .steps {
    padding: 14px 24px;
    gap: 18px;
  }

  .step {
    grid-template-columns: 28px 1fr;
    gap: 12px;
    padding: 10px 12px;
  }

  .step:not(:last-child) {
    padding-bottom: 18px;
  }

  .num {
    font-size: 34px;
  }

  .text {
    font-size: 12px;
  }

  .img-controls button {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }
}
