:root {
  --pink: #B0175A;
  --pink-light: #FF7AA8;
  --grad: linear-gradient(135deg, #FF7AA8, #B0175A);
  --bg: #ffffff;
  --bg-soft: #fbf5f8;
  --text: #2a1a22;
  --muted: #7d6a73;
  --line: #ecdfe5;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px;
  touch-action: manipulation; overscroll-behavior: none;
  -webkit-text-size-adjust: 100%; -webkit-user-select: none; user-select: none;
}
.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  padding: var(--sat) var(--sar) 0 var(--sal); background: var(--bg);
}
.screen.dark { background: #16110f; color: #fff; }

.topbar {
  flex: none; min-height: 52px; display: flex; align-items: center; gap: 12px;
  padding: 6px 16px; position: relative;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; color: var(--pink); }
.dark .topbar { justify-content: center; }
.dark .topbar h1 { color: #fff; }
.topbar .count { position: absolute; right: 16px; font-size: 15px; color: #ffd3e3; font-variant-numeric: tabular-nums; }

.btn {
  min-height: 48px; min-width: 48px; padding: 0 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: #fff; color: var(--text);
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--grad); color: #fff; border-color: transparent; }
.btn.big { min-height: 56px; font-size: 17px; width: 100%; border-radius: 16px; }
.btn.small { min-height: 40px; }
.dark .btn { background: #2b2327; color: #fff; border-color: #3d3238; }
.dark .btn.primary { background: var(--grad); border-color: transparent; }

.bottombar {
  flex: none; display: flex; gap: 8px; padding: 10px 12px calc(10px + var(--sab));
  border-top: 1px solid var(--line); background: var(--bg);
}
.dark .bottombar { background: #16110f; border-top-color: #2f262b; }
.bottombar .btn { flex: 1; padding: 0 6px; }
.bottombar .btn.primary { flex: 1.4; }

/* home */
#home-main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--bg-soft); }
#empty {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px 28px calc(24px + var(--sab)); text-align: center; background: var(--bg);
}
.empty-icon { width: 96px; height: 96px; border-radius: 22px; box-shadow: 0 6px 20px rgba(176, 23, 90, .25); }
#empty p { margin: 6px 0 14px; font-size: 18px; color: var(--muted); }
.big-btns { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
#grid {
  list-style: none; margin: 0; padding: 14px; display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
#grid li, .drag-clone { position: relative; }
#grid button, .drag-clone button {
  display: block; width: 100%; aspect-ratio: 3 / 4; padding: 0; border: 1px solid var(--line);
  border-radius: 12px; background: #fff; overflow: hidden; cursor: pointer;
  box-shadow: 0 2px 8px rgba(42, 26, 34, .08);
}
#grid img, .drag-clone img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
#grid .num, .drag-clone .num {
  position: absolute; left: 8px; top: 8px; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 13px;
  background: var(--grad); color: #fff; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; pointer-events: none;
}

/* adjust */
#adjust-msg {
  flex: none; margin: 0 12px 4px; padding: 10px 14px; border-radius: 12px;
  background: #3a1f2b; color: #ffd3e3; font-size: 15px; line-height: 1.4; text-align: center;
}
#stage { flex: 1; position: relative; min-height: 0; touch-action: none; overflow: hidden; }
#wrap { position: absolute; touch-action: none; }
#photo { width: 100%; height: 100%; display: block; background: #000; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#mask { fill: rgba(0, 0, 0, .5); }
#quad { fill: rgba(255, 122, 168, .12); stroke: #fff; stroke-width: 2.5; stroke-linejoin: round; paint-order: stroke; }
.handle, .edge {
  position: absolute; left: 0; top: 0; width: 56px; height: 56px; margin: -28px 0 0 -28px;
  touch-action: none; display: flex; align-items: center; justify-content: center; cursor: grab;
}
.handle::after {
  content: ""; width: 28px; height: 28px; border-radius: 50%; background: rgba(255, 255, 255, .25);
  border: 4px solid #fff; box-shadow: 0 0 0 2.5px var(--pink), 0 0 0 5px rgba(0, 0, 0, .25), inset 0 0 0 2.5px var(--pink);
}
.handle.active::after { background: rgba(255, 122, 168, .5); }
.edge { width: 48px; height: 48px; margin: -24px 0 0 -24px; }
.edge::after {
  content: ""; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  border: 3px solid var(--pink); box-shadow: 0 0 0 2px rgba(0, 0, 0, .25);
}
#loupe {
  position: fixed; z-index: 20; width: 120px; height: 120px; border-radius: 50%; overflow: hidden;
  border: 3px solid #fff; box-shadow: 0 4px 18px rgba(0, 0, 0, .6), 0 0 0 2px var(--pink); background: #000; pointer-events: none;
}
#loupe canvas { width: 100%; height: 100%; display: block; }

/* editor */
#editor .topbar { justify-content: space-between; }
#editor .topbar h1 { position: absolute; left: 0; right: 0; text-align: center; pointer-events: none; }
#editor .topbar .btn { position: relative; z-index: 1; }
#ed-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 22px; overflow: hidden; touch-action: none; }
#ed-wrap { position: relative; flex: none; }
#ed-canvas { width: 100%; height: 100%; display: block; background: #fff; border-radius: 2px; box-shadow: 0 2px 14px rgba(0, 0, 0, .5); }
#crop-ui { position: absolute; inset: 0; touch-action: none; }
#crop-rect { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 4000px rgba(0, 0, 0, .55); cursor: move; touch-action: none; }
#crop-rect .ch { position: absolute; width: 48px; height: 48px; margin: -24px 0 0 -24px; touch-action: none; }
#crop-rect .ch::after { content: ""; position: absolute; left: 14px; top: 14px; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 3px solid var(--pink); }
#crop-rect .ch[data-c="0"] { left: 0; top: 0; }
#crop-rect .ch[data-c="1"] { left: 100%; top: 0; }
#crop-rect .ch[data-c="2"] { left: 100%; top: 100%; }
#crop-rect .ch[data-c="3"] { left: 0; top: 100%; }
#ed-panel { flex: none; height: 158px; padding: 8px 12px 0; border-top: 1px solid #2f262b; background: #16110f; }
#ed-panel .pane { height: 100%; display: flex; flex-direction: column; gap: 4px; justify-content: center; }
#filter-strip { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; touch-action: pan-x; }
#filter-strip button { flex: none; width: 76px; padding: 0; border: 2px solid transparent; border-radius: 10px; background: #2b2327; color: #fff; font: inherit; font-size: 12px; font-weight: 600; text-align: center; overflow: hidden; }
#filter-strip button.on { border-color: var(--pink-light); }
#filter-strip canvas { display: block; width: 100%; height: 56px; object-fit: contain; background: #fff; }
#filter-strip span { display: block; padding: 4px 2px 5px; line-height: 1.15; min-height: 2.4em; }
#editor .btn.wide { width: 100%; }
.slider { display: flex; align-items: center; gap: 10px; min-height: 30px; font-weight: 600; font-size: 15px; }
.slider span { width: 48px; }
.slider input { flex: 1; min-width: 0; height: 24px; margin: 0; accent-color: var(--pink-light); touch-action: pan-y; }
.slider b { width: 36px; text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; color: #ffd3e3; }
#ed-panel .row { display: flex; gap: 8px; }
#ed-panel .row .btn { flex: 1; padding: 0 4px; }
#ed-panel .btn.small { min-height: 36px; }
#ed-panel .hint { margin: 0; text-align: center; font-size: 14px; color: #ffd3e3; }
.tabs button { flex: 1; min-width: 0; white-space: nowrap; padding: 0 2px; min-height: 44px; border: 0; border-radius: 12px; background: transparent; color: #bda9b2; font: inherit; font-weight: 700; font-size: 15px; }
.tabs button[data-tab="geom"] { flex: 1.5; }
.tabs button.on { background: #3a1f2b; color: #fff; }

/* home extras */
#home .topbar { justify-content: space-between; }
#home .topbar .btn { min-height: 38px; }
#grid li { -webkit-touch-callout: none; touch-action: pan-y; }
#grid li.ghost { opacity: .3; }
#grid .more {
  position: absolute; right: 6px; top: 6px; width: 36px; height: 36px; min-height: 0; padding: 0; border-radius: 18px;
  aspect-ratio: auto; background: rgba(255, 255, 255, .92); border: 1px solid var(--line); font-size: 20px; font-weight: 700; line-height: 1;
  color: var(--text); box-shadow: none; display: flex; align-items: center; justify-content: center;
}
.drag-clone { position: fixed !important; z-index: 40; margin: 0; pointer-events: none; list-style: none; transform: scale(1.06); opacity: .92; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .35)); }
.drag-clone .more { display: none; }
.drag-clone button.thumb { width: 100%; height: 100%; aspect-ratio: auto; }
.sheet { position: fixed; inset: 0; z-index: 45; background: rgba(20, 12, 16, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet-box { width: 100%; max-width: 480px; background: #fff; border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + var(--sab)); display: flex; flex-direction: column; gap: 10px; }
.sheet-box h2 { margin: 0 0 4px; font-size: 17px; text-align: center; color: var(--pink); }
.sheet-box .btn { width: 100%; }

/* overlays */
#busy {
  position: fixed; inset: 0; z-index: 50; background: rgba(20, 12, 16, .55); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
#busy p { margin: 0; font-size: 17px; font-weight: 600; }
.spin {
  width: 44px; height: 44px; border-radius: 50%; border: 5px solid rgba(255, 255, 255, .3); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--sab));
  max-width: 88%; padding: 12px 18px; border-radius: 14px; background: rgba(42, 26, 34, .92); color: #fff;
  font-size: 15px; text-align: center;
}
@media (min-width: 700px) {
  #grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .bottombar { justify-content: center; }
  .bottombar .btn { flex: 0 1 200px; }
}
