@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;600;700&family=Nanum+Gothic&family=Nanum+Myeongjo&display=swap");

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

:root {
  --bg-dark: #0f0f0f;
  --bg-panel: #1a1a1a;
  --bg-card: #242424;
  --bg-hover: #2d2d2d;
  --bg-active: #363636;
  --border-color: #333;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --canvas-bg: #2a2a2a;
}

body {
  font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
}

/* 헤더 */
.header {
  height: 56px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
}

.logo i {
  color: var(--accent);
  font-size: 20px;
}

/* 버튼 스타일 */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

/* 앱 컨테이너 */
.app-container {
  display: flex;
  height: calc(100vh - 56px);
}

/* 사이드바 */
.sidebar {
  width: 260px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.right-sidebar {
  border-right: none;
  border-left: 1px solid var(--border-color);
}

/* 패널 */
.panel {
  background: var(--bg-card);
  border-radius: 12px;
  overflow: hidden;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel-title i {
  font-size: 14px;
  color: var(--accent);
}

.panel-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-content.row {
  flex-direction: row;
  gap: 8px;
}

/* 도구 버튼 */
.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.tool-btn:hover {
  background: var(--bg-active);
  border-color: var(--accent);
}

.tool-btn.small {
  flex: 1;
  padding: 10px 12px;
  font-size: 12px;
}

.tool-btn-danger {
  border-color: transparent;
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.tool-btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--danger);
}

/* 업로드 버튼 */
.upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.upload-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* 인풋 그룹 */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.input-with-unit {
  display: flex;
  align-items: center;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.input-with-unit input {
  flex: 1;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.input-with-unit span {
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 12px;
  background: var(--bg-active);
}

select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}

select:focus {
  border-color: var(--accent);
}

/* 컬러 피커 */
.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 12px;
}

.color-picker-wrapper input[type="color"] {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: none;
  padding: 0;
}

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

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
  border: 2px solid var(--border-color);
  border-radius: 6px;
}

.color-value {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: monospace;
}

/* 체크박스 */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}

.checkbox-label input {
  display: none;
}

.checkmark {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.checkbox-label input:checked + .checkmark {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-label input:checked + .checkmark::after {
  content: "✓";
  color: white;
  font-size: 12px;
  font-weight: bold;
}

/* 레이어 패널 */
.layer-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

#layerList {
  list-style: none;
  padding: 8px;
  margin: 0;
  flex: 1;
  overflow-y: auto;
}

#layerList li {
  padding: 12px 14px;
  margin-bottom: 6px;
  background: var(--bg-hover);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}

#layerList li::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

#layerList li:hover {
  background: var(--bg-active);
}

#layerList li.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

#layerList li.active::before {
  background: var(--accent);
}

#layerList li.background {
  font-weight: 600;
}

#layerList li.background::before {
  background: var(--success);
}

/* 캔버스 영역 */
.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-dark);
  overflow: auto;
}

.canvas-wrapper {
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  overflow: hidden;
}

#canvas {
  position: relative;
  width: 1200px;
  height: 700px;
  background: var(--canvas-bg);
  background-image: linear-gradient(45deg, #333 25%, transparent 25%),
    linear-gradient(-45deg, #333 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #333 75%),
    linear-gradient(-45deg, transparent 75%, #333 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  overflow: hidden;
}

/* 레이어 스타일 */
.layer {
  position: absolute;
  cursor: move;
  user-select: none;
  transform-origin: center center;
}

.layer.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.layer img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: block;
}

.text-layer {
  min-width: 80px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: pre-wrap;
  padding: 8px;
}

.text-layer:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 핸들 표시/숨김 규칙 수정 - 기본적으로 숨기고 selected 클래스가 있을 때만 표시 */
.resize-handle,
.rotate-handle {
  display: none;
}

.layer.selected .resize-handle,
.layer.selected .rotate-handle {
  display: block;
}

.resize-handle {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: 2px solid white;
  border-radius: 3px;
  position: absolute;
  right: -7px;
  bottom: -7px;
  cursor: nwse-resize;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.rotate-handle {
  width: 16px;
  height: 16px;
  background: #f59e0b;
  border: 2px solid white;
  border-radius: 50%;
  position: absolute;
  top: -32px;
  left: 50%;
  transform: translateX(-50%);
  cursor: grab;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.rotate-handle::before {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 2px;
  height: 16px;
  background: rgba(245, 158, 11, 0.5);
  transform: translateX(-50%);
}

.background-layer {
  z-index: 0;
  cursor: default;
}

.background-layer .resize-handle,
.background-layer .rotate-handle {
  display: none;
}

/* 스크롤바 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* 반응형 */
@media (max-width: 1200px) {
  .sidebar {
    width: 220px;
  }
}
