:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --accent: #6c8cff;
  --accent-2: #5470ff;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 화면에는 안 보이고 검색엔진/스크린리더에만 노출 */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── 상단바 ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(8px + var(--safe-t)) 14px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.logo { font-weight: 800; font-size: 18px; letter-spacing: -0.5px; }
.topbar-actions { display: flex; gap: 8px; }

.iconbtn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 10px;
  font-size: 19px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: 0.12s;
}
.iconbtn.sm { width: 38px; height: 38px; }
.iconbtn.lang { width: auto; min-width: 40px; padding: 0 12px; font-size: 13px; font-weight: 600; }
.iconbtn:active:not(:disabled) { transform: scale(0.94); }

/* 라인 아이콘 공통 */
svg {
  width: 20px; height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}
.iconbtn.sm svg { width: 18px; height: 18px; }
.iconbtn.primary { background: var(--accent-2); border-color: var(--accent-2); }
.iconbtn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── 작업 영역 ── */
.stage {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  touch-action: none;
  background:
    repeating-conic-gradient(#15171d 0% 25%, #1a1d24 0% 50%) 50% / 24px 24px;
}
#canvas {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  image-rendering: auto;
  box-shadow: 0 6px 30px rgba(0,0,0,0.5);
  touch-action: none;
}
.hidden { display: none !important; }

/* 드롭존 */
.dropzone {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(420px, 84%);
  height: min(60%, 320px);
  border: 2px dashed var(--line);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-align: center;
}
.dropzone.dragover { border-color: var(--accent); background: rgba(108,140,255,0.07); }
.dropzone-inner p { margin: 4px 0; }
.dz-icon { color: var(--accent); margin-bottom: 10px; }
.dz-icon svg { width: 44px; height: 44px; margin: 0 auto; stroke-width: 1.6; }
.muted { color: var(--muted); font-size: 13px; }

/* 슬라이더 조정 시 사진 중앙에 뜨는 미리보기 오버레이 */
.stage-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  pointer-events: none;
  z-index: 40;
  opacity: 0;
  transition: opacity .16s ease, transform .16s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.stage-overlay.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.brush-ring {
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.95);
  background: rgba(108,140,255,0.16);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 10px 34px rgba(0,0,0,0.45);
  box-sizing: border-box;
}
.patch-canvas {
  width: 132px; height: 132px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 10px 34px rgba(0,0,0,0.5);
  display: block;
}
.overlay-label {
  background: rgba(15,17,21,0.82);
  border: 1px solid var(--line);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 13px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  white-space: nowrap;
}

/* 마우스 커서 링 */
.brush-cursor {
  position: fixed;
  border: 2px solid rgba(255,255,255,0.92);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.55);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: none;
  z-index: 60;
}

/* ── 하단 툴바 ── */
.toolbar {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + var(--safe-b));
}
.tool-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.modes { display: flex; gap: 6px; background: var(--panel-2); padding: 4px; border-radius: 11px; border: 1px solid var(--line); }
.modebtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.modebtn svg { width: 17px; height: 17px; }
.modebtn.active { background: var(--accent-2); color: #fff; }
.zoom { display: flex; gap: 6px; }

.sliders {
  display: flex;
  gap: 14px;
}
.control { flex: 1 1 0; min-width: 0; }
.control label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}
.control label span { color: var(--accent); font-variant-numeric: tabular-nums; }
input[type="range"] {
  width: 100%;
  height: 28px;
  accent-color: var(--accent);
}

/* 데스크탑에선 슬라이더를 가로로 더 넉넉히 */
@media (min-width: 760px) {
  .sliders { gap: 24px; max-width: 720px; }
  .toolbar { padding-left: 24px; padding-right: 24px; }
}
