/* 색·폰트·간격 토큰은 /shared/brand.css 에서 온다. 여기엔 누끼 편집기 고유 스타일만 둔다. */

* { box-sizing: border-box; }
body {
  margin: 0;
  /* 편집 화면이라 배경은 평평하게 — 상단에만 브랜드 글로우를 옅게 남긴다 */
  background: var(--bg-1);
  background-image: radial-gradient(760px 300px at 50% -10%, rgba(124, 92, 255, .14), transparent 70%);
  background-repeat: no-repeat;
  background-attachment: scroll;
  color: var(--text);
}
.container { max-width: 880px; margin: 0 auto; padding: 24px 20px 64px; }
h1 { margin: 0 0 4px; font-size: var(--fs-xl); letter-spacing: -.02em; }
.sub { color: var(--text-dim); margin: 0 0 24px; font-size: var(--fs-sm); }

.dropzone {
  border: 2px dashed var(--line-2);
  border-radius: 14px;
  padding: 40px 20px;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--cyan); background: var(--bg-2); }
.dropzone p { margin: 0 0 16px; color: #c4c9d2; }

button, .download {
  background: var(--accent); color: #fff; border: 0;
  padding: 9px 16px; border-radius: 8px; cursor: pointer;
  font-size: 14px; text-decoration: none; display: inline-block;
}
button:hover, .download:hover { background: var(--accent-dim); }

.hint { font-size: 12px; color: var(--cyan); font-weight: normal; margin-left: 6px; }

/* 편집 툴바 */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 12px;
}
.mode-group { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.mode {
  background: var(--bg-3); color: var(--text-dim); border: 0; border-radius: 0;
  padding: 8px 12px; font-size: 13px; min-height: 36px;
}
.mode:hover { background: #222a36; }
.mode.active { color: #fff; }
#modePos.active { background: #1d5c3a; }
#modeNeg.active { background: #6b2b2b; }
.tool {
  background: var(--bg-3); color: #c4c9d2; border: 1px solid var(--line-2);
  padding: 8px 12px; font-size: 13px; min-height: 36px;
}
.tool:hover { background: #222a36; }
.precise-label {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-dim); font-size: 13px; cursor: pointer; min-height: 36px;
  margin-left: auto;
}
.precise-label input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ⚙ 옵션 접이식 (네이티브 details — 라이브러리 없이) */
.opts { position: relative; }
.opts > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center;
}
.opts > summary::-webkit-details-marker { display: none; }
.opts-body {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 8px; padding: 10px; border: 1px solid var(--line);
  border-radius: 10px; background: #12161e;
}
/* 마우스 환경에서는 접지 않고 기존 툴바 그대로 펼쳐 보인다 (JS 가 open 을 켠다) */
@media (pointer: fine) {
  .opts { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
  .opts > summary { display: none; }
  .opts-body {
    display: inline-flex; margin-top: 0; padding: 0;
    border: 0; background: none;
  }
}

/* 원본 편집 영역: 뷰포트(pickwrap) 안에서 zoomlayer가 확대/이동된다 */
.pickwrap {
  position: relative; display: inline-block; max-width: 100%;
  overflow: hidden; touch-action: none; border-radius: 8px;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: contain;          /* 편집 중 당겨서 새로고침 방지 */
  -webkit-touch-callout: none;
}

/* ⛶ 전체화면 편집 — iOS 는 Fullscreen API 를 못 쓰므로 CSS 로 구현 */
.pickwrap.fullscreen {
  position: fixed; inset: 0; z-index: 100;
  width: 100vw; height: 100dvh; max-width: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-1); border-radius: 0;
}
/* 이미지 box 와 렌더링 크기가 어긋나면 마스크 캔버스가 밀린다 → object-fit 금지 */
.pickwrap.fullscreen .zoomlayer img { max-width: 100vw; max-height: 100dvh; width: auto; }
body.editing-full { overflow: hidden; }
/* 전체화면일 때 툴바(pickwrap 바깥 형제)를 화면 아래에 띄워 계속 쓸 수 있게 */
body.editing-full .toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 101;
  margin: 0; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(22, 27, 36, .96); border-top: 1px solid var(--line);
}
body.editing-full .opts-body {
  position: absolute; bottom: calc(100% + 8px); left: 10px; right: 10px;
  background: #12161e;
}
.zoomlayer {
  position: relative; display: inline-block; line-height: 0;
  transform-origin: 0 0;
}
.zoomlayer img { cursor: crosshair; -webkit-user-drag: none; }
.pickwrap.mode-pan .zoomlayer img { cursor: grab; }
.pickwrap.mode-brush .zoomlayer img, .pickwrap.mode-erase .zoomlayer img { cursor: none; }
#maskCanvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; border-radius: 8px;
}
#markers { position: absolute; inset: 0; pointer-events: none; }

/* 브러시 크기 슬라이더 + 커서 미리보기 (값 = 화면 CSS px) */
.brush-size {
  display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
  color: var(--text-dim); font-size: 13px; min-height: 36px;
}
.brush-size input { width: 110px; accent-color: var(--accent); }
.bs-preset { border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 10px; font-size: 12px; }
.brush-size input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--bg-1);
}
.brush-size input[type="range"]::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg-1);
}
.brush-cursor {
  position: absolute; border: 1.5px solid #fff; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .55) inset, 0 0 0 1px rgba(0, 0, 0, .55);
  pointer-events: none; transform: translate(-50%, -50%);
}

/* 확대경 — 손가락에 가려지는 편집 지점을 위쪽 모서리에 확대해 보여준다 */
.loupe {
  position: absolute; top: 10px; width: 116px; height: 116px;
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, .85);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
  pointer-events: none; background: var(--bg-1); z-index: 20;
}
.loupe.left { left: 10px; }
.loupe.right { right: 10px; }

/* 테두리 깎기 그룹 */
.tool.grouped { border: 0; border-radius: 0; }
.tool.grouped + .tool.grouped { border-left: 1px solid var(--line-2); }
.erode-val {
  align-self: center; padding: 0 10px; font-size: 12px; color: var(--cyan);
}

/* 선택 확정 버튼 */
.apply { display: block; width: 100%; margin-top: 12px; padding: 12px 16px; font-size: 15px; }
button:disabled { opacity: .45; cursor: default; }
button:disabled:hover { background: var(--accent); }
.mode:disabled:hover, .tool:disabled:hover { background: var(--bg-3); }
.pmark {
  position: absolute; width: 22px; height: 22px;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(var(--invz, 1));
  pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff; line-height: 1;
  box-shadow: 0 0 6px rgba(0, 0, 0, .6);
}
.pmark.pos { background: rgba(34, 160, 90, .85); border: 2px solid var(--ok); }
.pmark.neg { background: rgba(190, 55, 55, .85); border: 2px solid var(--err); }
/* 🪄 문지르기로 찍힌 부분 프롬프트는 작은 점으로 (클릭 마커와 구분) */
.pmark.part { width: 11px; height: 11px; border-width: 1.5px; }

/* 🪄 스마트 토글 */
.mode.smart {
  border: 1px solid var(--line-2); border-radius: 8px; background: var(--bg-3);
}
.mode.smart.active { background: #3b3168; color: #fff; border-color: #6d5bd0; }

/* 결과 영역: 배경 토글 + 스피너 */
.bg-toggle { float: right; display: inline-flex; gap: 4px; }
.bg-toggle button {
  background: var(--bg-3); color: var(--text-dim); border: 1px solid var(--line-2);
  padding: 4px 10px; font-size: 12px; border-radius: 6px; min-height: 28px;
}
.bg-toggle button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.resultwrap { position: relative; border-radius: 8px; min-height: 120px; }
.resultwrap.bg-white { background: #fff; }
.resultwrap.bg-black { background: #000; }
.spinner-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 17, 21, .55); border-radius: 8px;
}
.spinner {
  width: 36px; height: 36px;
  border: 4px solid rgba(255, 255, 255, .25);
  border-top-color: var(--cyan); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status {
  margin-top: 20px; padding: 14px 16px; border-radius: 10px;
  background: var(--bg-2); border: 1px solid var(--line);
}
.status.error { border-color: #7a2e2e; color: #ffb4b4; }

.results { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 24px; }
@media (max-width: 640px) { .results { grid-template-columns: 1fr; } }
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; color: var(--text-dim); }
.card img { max-width: 100%; border-radius: 8px; display: block; }

/* 결과가 현재 선택보다 낡았을 때 */
.stale-note {
  margin: 0 0 10px; padding: 8px 12px; border-radius: 8px;
  background: #3a2f16; border: 1px solid #7a6a2e; color: var(--warn); font-size: 13px;
}
.card.stale .resultwrap { opacity: .45; }

/* 투명 배경 확인용 체커보드 */
.checker {
  background-image:
    linear-gradient(45deg, #2a2f3a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2f3a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2f3a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2f3a 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  border-radius: 8px;
}
.download { margin-top: 12px; }
.hidden { display: none; }

/* ---------- 터치 기기 (손가락 조작) ---------- */
@media (pointer: coarse) {
  button, .download, .mode, .tool, .precise-label {
    min-height: 44px; font-size: 15px; touch-action: manipulation;
  }
  .mode, .tool { padding: 10px 14px; }
  .container { padding: 20px 12px 40px; }
  .card { padding: 12px; }
  /* 두 손가락 제스처가 대체하므로 줌 버튼·이동 모드는 숨긴다 */
  .zoom-group, #modePan { display: none; }
  .toolbar { position: sticky; bottom: 0; z-index: 10;
    background: var(--bg-2); padding: 8px 0; margin-bottom: 8px; }
  .precise-label { margin-left: 0; }
  .brush-size { width: 100%; }
  .brush-size input { flex: 1 1 120px; }
  .apply { position: sticky; bottom: 60px; z-index: 9; }
  .bg-toggle button { min-height: 40px; }
}
