/* ============================================================
   Auto Pixel Art — 모바일 우선 스타일
   기준: 세로 모바일 화면. 데스크톱은 반응형 확장으로 대응.
   ============================================================ */

:root {
  color-scheme: dark;
  --bg: #0f0f1a;
  --bg-stage: #14141f;
  --surface: #1c1c2b;
  --surface-2: #262638;
  --text: #e8e8f0;
  --muted: #9a9ab0;
  --accent: #7873f5;
  --accent-2: #ff6ec4;
  --border: #2e2e44;
  --danger: #ff5c7a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --topbar-h: calc(52px + var(--safe-top));
}

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

/* display를 직접 지정한 요소(.sheet, .busy 등)에서도 hidden이 항상 이기도록 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------------- 상단 바 ---------------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  padding: var(--safe-top) 10px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(180deg, rgba(15,15,26,0.95), rgba(15,15,26,0.55) 70%, transparent);
  z-index: 30;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar__title {
  font-weight: 700; font-size: 1rem;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.topbar__spacer { flex: 1; }

/* ---------------- 작업판 ---------------- */
.stage {
  position: fixed;
  inset: 0;
  background: repeating-conic-gradient(#1a1a28 0% 25%, #15151f 0% 50%) 50% / 24px 24px;
  background-color: var(--bg-stage);
  overflow: hidden;
  touch-action: none;
}
.canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: block;
}

/* ---------------- 드롭존 ---------------- */
.dropzone {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 20;
  transition: background 0.15s ease;
}
.dropzone.is-dragover { background: rgba(120,115,245,0.12); }
.dropzone.is-dragover .dropzone__inner { border-color: var(--accent); transform: scale(1.02); }
.dropzone__inner {
  width: 100%; max-width: 360px;
  padding: 36px 24px;
  border: 2px dashed var(--border);
  border-radius: 18px;
  background: rgba(28,28,43,0.6);
  text-align: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.dropzone__icon { font-size: 2.6rem; }
.dropzone__title { margin: 12px 0 4px; font-size: 1.15rem; font-weight: 600; }
.dropzone__hint { margin: 0 0 20px; color: var(--muted); font-size: 0.85rem; }

/* ---------------- 보기 모드 세그먼트 (플로팅) ---------------- */
.seg {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px; gap: 3px;
}
.seg--float {
  position: fixed;
  top: calc(var(--topbar-h) + 6px);
  left: 50%; transform: translateX(-50%);
  z-index: 28;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
.seg__btn {
  min-width: 60px; min-height: 40px;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--muted);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.seg__btn.is-active { background: var(--accent); color: #fff; }

/* ---------------- 우측 플로팅 액션 ---------------- */
.side-actions {
  position: fixed;
  right: 10px;
  bottom: calc(150px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 10px;
  z-index: 28;
}
.fab {
  width: 52px; height: 52px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
}
.fab--accent {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border-color: transparent; color: #fff;
}
.fab:active { transform: scale(0.94); }

/* ---------------- 하단 툴바 ---------------- */
.toolbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding-bottom: var(--safe-bottom);
  background: linear-gradient(0deg, rgba(15,15,26,0.97), rgba(15,15,26,0.75) 80%, transparent);
  z-index: 30;
}

/* 도구 옵션 패널 */
.tool-options {
  padding: 10px 12px 4px;
  border-bottom: 1px solid var(--border);
}
.opt-line {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px;
}
.opt-line:last-child { margin-bottom: 0; }
.opt label { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.opt label b { color: var(--text); }
.opt input[type="range"] {
  flex: 1; min-width: 80px;
  accent-color: var(--accent);
  height: 28px;
}
.opt-hint { font-size: 0.75rem; color: var(--muted); }

.chip {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85rem; font-weight: 600;
  cursor: pointer;
}
.chip.is-active { background: var(--accent); border-color: transparent; color: #fff; }
.chip:active { transform: scale(0.96); }

/* 도구 선택 행 */
.tool-row {
  display: flex;
  gap: 4px;
  padding: 8px 8px;
  overflow-x: auto;
}
.tool {
  flex: 1 0 auto;
  min-width: 60px; min-height: 56px;
  border: 0; border-radius: 12px;
  background: transparent; color: var(--muted);
  font-size: 0.72rem; font-weight: 600;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
}
.tool__ico { font-size: 1.4rem; line-height: 1; }
.tool.is-active { background: var(--surface); color: var(--text); }

/* ---------------- 버튼 ---------------- */
.btn {
  min-height: 48px; padding: 0 22px;
  border: 0; border-radius: 12px;
  font-size: 1rem; font-weight: 600; cursor: pointer;
}
.btn--primary { background: linear-gradient(90deg, var(--accent-2), var(--accent)); color: #fff; }
.iconbtn {
  width: 44px; height: 44px; flex: 0 0 auto;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-size: 1.2rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.iconbtn:disabled { opacity: 0.35; }
.iconbtn:active:not(:disabled) { background: var(--surface-2); }

/* ---------------- 비교 슬라이더 ---------------- */
.compare-handle {
  position: absolute; top: 0; bottom: 0;
  width: 44px; margin-left: -22px;
  z-index: 25;
  display: flex; align-items: center; justify-content: center;
  touch-action: none; cursor: ew-resize;
}
.compare-handle__line {
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 2px; margin-left: -1px;
  background: rgba(255,255,255,0.85);
  box-shadow: 0 0 6px rgba(0,0,0,0.5);
}
.compare-handle__grip {
  width: 40px; height: 40px; border-radius: 50%;
  background: #fff; color: #111;
  font-size: 1rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.view-label {
  position: absolute;
  top: calc(var(--topbar-h) + 56px);
  padding: 4px 10px;
  font-size: 0.78rem; font-weight: 600;
  border-radius: 8px;
  background: rgba(0,0,0,0.55); color: #fff;
  z-index: 24; pointer-events: none;
}
.view-label--left { left: 12px; }
.view-label--right { right: 12px; }

/* ---------------- 처리 오버레이 ---------------- */
.busy {
  position: fixed; inset: 0;
  background: rgba(8,8,14,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 60;
}
.busy__box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 32px;
  text-align: center;
  max-width: 80vw;
}
.busy__box p { margin: 14px 0 0; color: var(--text); font-size: 0.92rem; }
.spinner {
  width: 40px; height: 40px; margin: 0 auto;
  border: 4px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 도움말 시트 ---------------- */
.sheet {
  position: fixed; inset: 0;
  background: rgba(8,8,14,0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 70;
}
.sheet__box {
  width: 100%; max-width: 480px;
  max-height: 86vh; overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding: 22px 22px calc(22px + var(--safe-bottom));
}
.sheet__box h3 { margin: 0 0 14px; font-size: 1.15rem; }
.sheet__box ul { margin: 6px 0 14px; padding-left: 20px; color: var(--text); }
.sheet__box li { margin: 5px 0; font-size: 0.9rem; line-height: 1.45; }
.sheet__good { margin: 6px 0 2px; color: #4ade80; font-weight: 700; }
.sheet__bad { margin: 6px 0 2px; color: var(--danger); font-weight: 700; }
.sheet__tip {
  margin: 8px 0; padding: 10px 12px;
  background: var(--surface-2); border-radius: 10px;
  font-size: 0.85rem; line-height: 1.5; color: var(--text);
}
.sheet__box .btn { width: 100%; margin-top: 8px; }

/* ---------------- 픽셀화 패널 ---------------- */
.pixpanel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 64vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -6px 20px rgba(0,0,0,0.4);
  z-index: 40;
  padding-bottom: var(--safe-bottom);
}
.pixpanel__head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
.pixpanel__info { flex: 1; font-size: 0.78rem; font-weight: 500; color: var(--muted); }
.pixpanel__body { overflow-y: auto; padding: 12px 14px 16px; }

.prow { margin-bottom: 14px; }
.prow:last-child { margin-bottom: 0; }
.prow__label {
  display: block; margin-bottom: 7px;
  font-size: 0.82rem; color: var(--muted);
}
.prow__label b { color: var(--text); }
.prow input[type="range"] { width: 100%; accent-color: var(--accent); height: 30px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.num {
  width: 76px; min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
  font-size: 0.85rem;
}
.pixexport { width: 100%; margin-top: 10px; }

/* 픽셀 모드일 때 하단 툴바 숨김 처리는 JS(hidden)로 */

/* ---------------- 데스크톱 확장 ---------------- */
@media (min-width: 768px) {
  .topbar__title { font-size: 1.15rem; }
  .tool-row { justify-content: center; }
  .tool { flex: 0 0 auto; min-width: 84px; }
  .toolbar { padding-left: 0; padding-right: 0; }
  .tool-options { max-width: 720px; margin: 0 auto; }
  .pixpanel { left: 50%; right: auto; transform: translateX(-50%); width: 560px; border-radius: 16px 16px 0 0; }
}
