.ci-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  margin-top: 20px;
}
.ci-options,
.ci-preview-panel {
  min-width: 0;
}
.ci-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
  align-items: stretch;
}
.ci-fields > div {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 0;
}
.ci-fields input,
.ci-fields select {
  width: 100%;
  height: 48px;
  min-height: 48px;
  min-width: 0;
}
.ci-fields input[type="color"] {
  padding: 4px;
}
.ci-fields label {
  overflow-wrap: anywhere;
}
.ci-options details {
  margin: 18px 0;
  border-top: 1px solid #e5e7eb;
  padding-top: 14px;
}
.ci-options summary {
  font-weight: 700;
  cursor: pointer;
}
.ci-stage {
  --ci-preview-height: 75vh;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  padding: 24px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background-color: #fff;
  background-image: conic-gradient(
    #e5e7eb 25%,
    transparent 0 50%,
    #e5e7eb 0 75%,
    transparent 0
  );
  background-size: 20px 20px;
}
.ci-stage canvas,
.ci-stage img {
  display: block;
  max-width: 100%;
  max-height: 75vh;
  width: auto;
  height: auto;
  object-fit: contain;
}
.ci-canvas-wrap {
  position: relative;
  max-width: 100%;
  flex: 0 1 auto;
  line-height: 0;
}
.ci-canvas-wrap canvas {
  width: 100%;
  height: auto;
  max-height: none;
}
.ci-selection {
  position: absolute;
  border: 2px solid #2563eb;
  pointer-events: none;
  box-sizing: border-box;
}
.ci-handle,
.ci-delete {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  display: grid;
  place-items: center;
  padding: 0;
}
.ci-handle {
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  transform: translate(-50%, -50%);
}
.ci-handle::after {
  content: "";
  width: 12px;
  height: 12px;
  background: white;
  border: 2px solid #2563eb;
  border-radius: 2px;
}
.ci-handle[data-handle="nw"] {
  left: 0;
  top: 0;
  cursor: nwse-resize;
}
.ci-handle[data-handle="ne"] {
  left: 100%;
  top: 0;
  cursor: nesw-resize;
}
.ci-handle[data-handle="se"] {
  left: 100%;
  top: 100%;
  cursor: nwse-resize;
}
.ci-handle[data-handle="sw"] {
  left: 0;
  top: 100%;
  cursor: nesw-resize;
}
.ci-delete {
  width: 36px;
  height: 36px;
  left: 50%;
  top: -44px;
  transform: translateX(-50%);
  border: 1px solid #dc2626;
  border-radius: 6px;
  color: #dc2626;
  background: white;
  cursor: pointer;
  z-index: 1;
}
.ci-delete.is-below {
  top: calc(100% + 8px);
}
.ci-delete.is-inside {
  top: 6px;
}
.ci-handle:focus-visible,
.ci-delete:focus-visible,
#ci-canvas:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}
[data-mode="blur"] .ci-stage canvas {
  touch-action: none;
  cursor: crosshair;
}
#creative-tool [hidden] {
  display: none !important;
}
#ci-empty {
  background: white;
  padding: 16px;
  text-align: center;
}
#creative-tool .tool-check-row {
  flex-wrap: wrap;
  margin: 14px 0;
}
#creative-tool button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#creative-tool button[aria-pressed="true"] {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}
.ci-text {
  width: 100%;
  min-height: 130px;
}
.ci-pieces {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 14px;
  max-height: 55vh;
  overflow: auto;
}
.ci-piece {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px;
  min-width: 0;
}
.ci-piece img {
  max-width: 100%;
  height: 90px;
  object-fit: contain;
  margin: auto;
}
.ci-piece button {
  width: 100%;
  margin-top: 8px;
  overflow-wrap: anywhere;
}
.ci-piece p {
  font-size: 13px;
  overflow-wrap: anywhere;
}
#ci-status,
#ci-file-name {
  overflow-wrap: anywhere;
}
#ci-status {
  min-height: 24px;
}
#ci-stage {
  scroll-margin-top: 16px;
}
@media (max-width: 850px) {
  .ci-stage {
    --ci-preview-height: 65vh;
  }
  .ci-layout {
    grid-template-columns: 1fr;
    gap: 18px;
  }
  .ci-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .ci-stage canvas,
  .ci-stage img {
    max-height: 65vh;
  }
  .ci-pieces {
    max-height: 40vh;
  }
}
@media (max-width: 480px) {
  .ci-fields {
    grid-template-columns: minmax(0, 1fr);
  }
  .ci-edit-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
