/* ─── 리셋 & CSS 변수 ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* hidden 속성이 display:flex 등 CSS 규칙에 의해 무시되는 것을 방지 */
[hidden] { display: none !important; }

:root {
  --bg:        #0f172a;
  --bg-panel:  #1e293b;
  --bg-input:  #334155;
  --bg-hover:  #2d3f55;
  --accent:    #6366f1;
  --accent-h:  #4f46e5;
  --danger:    #ef4444;
  --text:      #e2e8f0;
  --text-muted:#94a3b8;
  --border:    #334155;
  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard', 'Noto Sans KR', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.3px;
}

.header-right { display: flex; gap: 8px; }

/* ─── 레이아웃 ─── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── 사이드바 ─── */
.sidebar {
  width: 240px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  flex-shrink: 0;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.section:last-child { border-bottom: none; margin-bottom: 0; }

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ─── 업로드 존 ─── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(99,102,241,0.06);
}
.upload-icon { margin-bottom: 8px; }
.upload-text { color: var(--text-muted); font-size: 12px; margin-bottom: 10px; }
.upload-hint { color: var(--text-muted); font-size: 10px; margin-top: 8px; opacity: 0.7; }

.file-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-top: 8px;
}
.file-icon { font-size: 16px; flex-shrink: 0; }
.file-name-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.btn-icon-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
}
.btn-icon-remove:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

/* ─── 컨트롤 ─── */
.row-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.ctrl-label { color: var(--text-muted); font-size: 12px; }
.fixed-val  { color: var(--text-muted); font-size: 12px; }

.stepper {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-input);
  border-radius: var(--radius);
  overflow: hidden;
}
.stepper-btn {
  background: none;
  border: none;
  color: var(--text);
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
}
.stepper-btn:hover { background: var(--bg-hover); }
.stepper-val {
  padding: 0 8px;
  font-size: 13px;
  font-weight: 600;
  min-width: 42px;
  text-align: center;
}

.type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.type-btn {
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
  text-align: center;
}
.type-btn:hover { background: var(--bg-hover); color: var(--text); }
.type-btn.active {
  background: rgba(99,102,241,0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── 체크박스 ─── */
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
}
.check-row input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }
.check-text { font-size: 12px; color: var(--text-muted); }
.check-row:hover .check-text { color: var(--text); }

/* ─── 버튼 ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--accent);   color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-input); color: var(--text); }
.btn-danger { background: rgba(239,68,68,0.1); color: var(--danger); border: 1px solid transparent; }
.btn-danger:hover { background: rgba(239,68,68,0.2); }
.btn-sm { font-size: 12px; padding: 5px 10px; }
.btn-block { width: 100%; justify-content: center; }
.btn-upload { margin: 6px auto 0; display: block; }

/* ─── 캔버스 영역 ─── */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  position: relative;
}

.canvas-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
}

#preview-canvas {
  display: block;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 100%;
  max-height: 100%;
}

.empty-state {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}
.empty-icon { font-size: 40px; opacity: 0.3; }
.empty-msg { color: var(--text-muted); text-align: center; line-height: 1.7; font-size: 13px; }

.canvas-footer {
  padding-top: 12px;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.3px;
}

/* ─── 모달 오버레이 ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal {
  background: #1a1f2e;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  width: 92vw;
  height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-panel);
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}

.modal-size-tag {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.modal-actions { display: flex; align-items: center; gap: 8px; }

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
}
.btn-close:hover { background: var(--bg-input); color: var(--text); }

.modal-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── 3D 뷰어 ─── */
.viewer-3d {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0d1117;
}
.viewer-3d canvas { display: block; }

/* ─── 3D 사이드 패널 ─── */
.side-panel {
  width: 180px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  padding: 14px;
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.side-section { display: flex; flex-direction: column; gap: 8px; }
.side-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.preset-btn {
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: 10px 6px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  transition: all 0.15s;
}
.preset-btn:hover { background: var(--bg-hover); color: var(--text); }
.preset-btn.active {
  border-color: var(--accent);
  background: rgba(99,102,241,0.15);
  color: var(--accent);
}

/* 프리셋 아이콘 (CSS 도형) */
.preset-icon {
  width: 32px;
  height: 24px;
  position: relative;
}
.pi-i::before {
  content: '';
  position: absolute;
  left: 50%; top: 0;
  transform: translateX(-50%);
  width: 8px; height: 100%;
  background: currentColor;
  border-radius: 2px;
  opacity: 0.8;
}
.pi-l::before {
  content: '';
  position: absolute;
  left: 50%; top: 0;
  transform: translateX(-50%);
  width: 8px; height: 100%;
  background: currentColor;
  border-radius: 2px;
  opacity: 0.8;
}
.pi-l::after {
  content: '';
  position: absolute;
  left: 50%; bottom: 0;
  width: 14px; height: 8px;
  background: currentColor;
  border-radius: 2px;
  opacity: 0.8;
}
.pi-u::before {
  content: '';
  position: absolute;
  left: 6px; top: 0;
  width: 6px; height: 100%;
  background: currentColor;
  border-radius: 2px;
  opacity: 0.8;
  box-shadow: 14px 0 0 currentColor;
}
.pi-u::after {
  content: '';
  position: absolute;
  left: 6px; bottom: 0;
  width: 20px; height: 6px;
  background: currentColor;
  border-radius: 2px;
  opacity: 0.8;
}
.pi-booth::before {
  content: '';
  position: absolute;
  left: 4px; top: 2px;
  width: 24px; height: 20px;
  border: 4px solid currentColor;
  border-radius: 2px;
  opacity: 0.8;
}

.side-row-btns { flex-direction: row; gap: 6px; }

.dot-yellow {
  width: 8px; height: 8px;
  background: #eab308;
  border-radius: 50%;
  flex-shrink: 0;
}

.viewer-hint {
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.8;
  padding: 10px;
  background: var(--bg-input);
  border-radius: var(--radius);
  margin-top: auto;
}

/* ─── 이미지 크기 입력 ─── */
.img-size-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.img-size-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  padding: 5px 4px;
  text-align: center;
}
.img-size-input:focus { outline: none; border-color: var(--accent); }
.img-size-sep { color: var(--text-muted); font-size: 12px; flex-shrink: 0; }
.btn-drag-active {
  background: rgba(99,102,241,0.2) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

/* ─── 디자인 목록 모달 ─── */
.modal-designs {
  width: 500px;
  height: auto;
  max-height: 70vh;
}
.designs-body {
  flex-direction: column;
  overflow-y: auto;
  padding: 12px;
}
.designs-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.design-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.design-item-info { flex: 1; min-width: 0; }
.design-item-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.design-item-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.designs-empty { color: var(--text-muted); text-align: center; padding: 40px 0; font-size: 13px; }
