/* 카드뉴스 메이커 - 도구 전용 스타일 */

/* 전체 레이아웃: 컨트롤 좌측 + 미리보기 우측 */
.card-editor {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

/* 컨트롤 패널 */
.controls-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* 미리보기 패널 */
.preview-panel {
  flex: 1;
  min-width: 0;
  position: sticky;
  top: 1rem;
}

/* 캔버스 래퍼 */
.canvas-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* 컨트롤 섹션 */
.control-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.control-section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* 크기 프리셋 버튼 */
.size-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.size-preset {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-sub);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.size-preset:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.size-preset.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* 커스텀 크기 입력 */
.custom-size {
  display: none;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.custom-size.visible {
  display: flex;
}

.custom-size input {
  width: 80px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

.custom-size input:focus {
  border-color: var(--primary);
}

.custom-size span {
  color: var(--text-sub);
  font-size: 0.85rem;
}

/* 텍스트 입력 */
.text-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.text-input-group + .text-input-group {
  margin-top: 0.5rem;
}

.text-input-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-sub);
}

.text-input-group textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.text-input-group textarea:focus {
  border-color: var(--primary);
}

/* 배경 타입 선택 */
.bg-type-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.bg-type-btn {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-sub);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.bg-type-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.bg-type-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* 색상 컨트롤 행 */
.color-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.color-row label {
  font-size: 0.8rem;
  color: var(--text-sub);
  min-width: 60px;
}

.color-row input[type="color"] {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  cursor: pointer;
  background: none;
  -webkit-appearance: none;
  appearance: none;
}

.color-row input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-row input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 5px;
}

.color-row input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 5px;
}

/* 레이어 순서 패널 */
.layer-order {
  margin-bottom: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.layer-order[hidden] { display: none; }
.layer-order-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.9rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-sub);
}
.layer-order-hint {
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0.7;
  color: var(--text-sub);
}
.layer-order-list {
  display: flex;
  flex-direction: column;
}
.layer-order-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  cursor: grab;
}
.layer-order-item:last-child { border-bottom: none; }
.layer-order-item:hover {
  background: rgba(102, 126, 234, 0.05);
}
.layer-order-item.dragging {
  opacity: 0.4;
  cursor: grabbing;
}
.layer-order-item.drop-above {
  box-shadow: inset 0 2px 0 var(--primary);
}
.layer-order-item.drop-below {
  box-shadow: inset 0 -2px 0 var(--primary);
}
.layer-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  opacity: 0.45;
  font-size: 0.9rem;
  line-height: 1;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}
.layer-order-item:hover .layer-handle { opacity: 0.75; }

.layer-swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  background-size: cover;
  background-position: center;
}
.layer-swatch svg { width: 14px; height: 14px; }

.layer-order-name {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
}

.layer-order-actions {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
}
.layer-order-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-sub);
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
}
.layer-order-btn:hover:not(:disabled) {
  background: var(--primary);
  color: white;
}
.layer-order-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.layer-order-btn svg {
  width: 12px;
  height: 12px;
  pointer-events: none;
}

/* 그라데이션 방향 셀렉트 */
.gradient-options {
  display: none;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.gradient-options.visible {
  display: flex;
}

/* 이미지 배경 옵션 */
.image-options {
  display: none;
  flex-direction: column;
  gap: 0.6rem;
}
.image-options.visible {
  display: flex;
}

.file-pick {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.file-pick-btn {
  padding: 0.4rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-sub);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.file-pick-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.file-pick-name {
  font-size: 0.75rem;
  color: var(--text-sub);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.fit-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.fit-label {
  font-size: 0.75rem;
  color: var(--text-sub);
  margin-right: 0.25rem;
}
.btn-reset-pos {
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-sub);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-reset-pos:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.drag-hint {
  font-size: 0.72rem;
  color: var(--text-sub);
  margin: 0;
  padding-top: 0.15rem;
}
.fit-btn {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-sub);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
}
.fit-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.fit-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.bg-image-clear {
  margin-left: auto;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-sub);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.bg-image-clear:hover {
  border-color: #e53e3e;
  color: #e53e3e;
}

.gradient-options select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
}

/* 슬라이더 행 */
.slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.slider-row label {
  font-size: 0.8rem;
  color: var(--text-sub);
  min-width: 70px;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

.slider-row .slider-value {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  min-width: 40px;
  text-align: right;
}

/* 정렬 버튼 그룹 */
.align-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.align-group label {
  font-size: 0.8rem;
  color: var(--text-sub);
  min-width: 70px;
}

.align-buttons {
  display: flex;
  gap: 0.25rem;
}

.align-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-sub);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.align-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.align-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* 다운로드 버튼 */
.action-buttons {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.btn-download-main {
  flex: 1;
  padding: 0.7rem 1.2rem;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 8px;
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  text-align: center;
}

.btn-download-main:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

/* 반응형: 768px 이하에서 세로 배치 */
@media (max-width: 768px) {
  .card-editor {
    flex-direction: column;
  }

  .preview-panel {
    position: static;
    order: -1;
  }
}

@media (max-width: 480px) {
  .control-section {
    padding: 0.75rem;
  }

  .size-presets {
    gap: 0.3rem;
  }

  .size-preset {
    font-size: 0.75rem;
    padding: 0.3rem 0.5rem;
  }

  .slider-row label,
  .align-group label,
  .color-row label {
    min-width: 55px;
    font-size: 0.75rem;
  }

  .action-buttons {
    flex-direction: column;
  }

  /* 모바일 터치 영역 확대 */
  .layer-order-item {
    padding: 0.75rem 0.9rem;
  }
  .layer-order-btn {
    width: 34px;
    height: 34px;
  }
  .layer-order-btn svg {
    width: 14px;
    height: 14px;
  }
  .layer-swatch {
    width: 28px;
    height: 28px;
  }
}
