/* ───────── 편집기 UI ───────── */
:root {
  --ui-bg: #f7f3f5;
  --ui-panel: #ffffff;
  --ui-line: #eadde3;
  --ui-text: #3b3036;
  --ui-sub: #8f7f87;
  --ui-accent: #e88aab;
  --ui-accent-ink: #ffffff;
  --ui-danger: #d9534f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: Galmuri11, system-ui, sans-serif;
  font-size: 13px;
}
.app { display: flex; min-height: 100vh; }

.panel {
  width: 320px;
  flex: none;
  background: var(--ui-panel);
  border-right: 1px solid var(--ui-line);
  padding: 16px;
  height: 100vh;
  overflow-y: auto;
  position: sticky;
  top: 0;
}
.logo { font-size: 18px; margin: 0 0 12px; }
.logo span { color: var(--ui-accent); }
details { border-top: 1px solid var(--ui-line); padding: 10px 0; }
summary { cursor: pointer; font-weight: 700; padding: 2px 0 8px; list-style: none; }
summary::before { content: '▸ '; color: var(--ui-accent); }
details[open] > summary::before { content: '▾ '; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.hint { color: var(--ui-sub); font-size: 11px; line-height: 1.6; margin: 6px 0; }
.btn {
  font: inherit;
  border: 1px solid var(--ui-line);
  background: #fff;
  color: var(--ui-text);
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.btn:hover { border-color: var(--ui-accent); }
.btn.primary { background: var(--ui-accent); border-color: var(--ui-accent); color: var(--ui-accent-ink); }
.btn.danger { color: var(--ui-danger); }
.btn.ghost { border-style: dashed; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: default; }
select, input[type=text] {
  font: inherit;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
  color: var(--ui-text);
}
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0; cursor: pointer; }
.add-pairs span { color: var(--ui-sub); margin-right: 2px; }
.fmt span { color: var(--ui-sub); margin-right: 4px; }

.saves { list-style: none; margin: 0; padding: 0; }
.saves li {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 0; border-bottom: 1px dashed var(--ui-line);
}
.saves li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saves li small { color: var(--ui-sub); display: block; font-size: 10px; }

.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.presets button { display: flex; align-items: center; gap: 6px; }
.presets i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid #0002; }
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.colors .cgroup { grid-column: 1 / -1; font-size: 11px; color: var(--ui-sub); margin-top: 6px; }
.colors .span2 { grid-column: 1 / -1; }
.colors label { display: flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; }
.colors input[type=color] {
  width: 28px; height: 22px; padding: 0; border: 1px solid var(--ui-line);
  border-radius: 6px; background: none; cursor: pointer; flex: none;
}

.tray { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.tray .item {
  position: relative; width: 52px; height: 52px; border: 1px solid var(--ui-line);
  border-radius: 8px; cursor: pointer; padding: 4px;
  background: repeating-conic-gradient(#f2f2f2 0 25%, #fff 0 50%) 0 0 / 10px 10px;
}
.tray .item img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.tray .item .x {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%;
  border: 0; background: #444; color: #fff; font-size: 10px; cursor: pointer; display: none; line-height: 18px; padding: 0;
}
.tray .item:hover .x { display: block; }
.sel-tools { display: none; }
.sel-tools.on { display: flex; }

.stage { flex: 1; min-width: 0; padding: 32px 24px 80px; display: flex; justify-content: center; align-items: flex-start; }
.scaler { transform-origin: top left; width: 600px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #3b3036; color: #fff; padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 99; max-width: 90vw;
}
.toast.on { opacity: 1; transform: translateX(-50%); }

@media (max-width: 860px) {
  .app { flex-direction: column-reverse; }
  .panel { width: 100%; height: auto; position: static; border-right: 0; border-top: 1px solid var(--ui-line); }
  .stage { padding: 16px; }
}

/* ───────── 메인트 캔버스 (이미지로 저장되는 부분) ───────── */
.mt {
  --font: Galmuri11;
  width: 600px;
  position: relative;
  padding: 28px 26px 34px;
  background: var(--bgimg);
  color: var(--text);
  font-family: var(--font), Galmuri11, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: none;
}
.mt.grid {
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    var(--bgimg);
  background-size: 24px 24px, 24px 24px, 100% 100%;
  background-position: -1px -1px, -1px -1px, 0 0;
}
.mt .ed { outline: none; border-radius: 3px; min-width: 1em; }
.mt .ed:hover { box-shadow: 0 0 0 1px #e88aab88; }
.mt .ed:focus { box-shadow: 0 0 0 2px #e88aab; }
.mt.exporting .ed { box-shadow: none !important; }

.win { position: relative; }
/* 폴더 탭 */
.stack { position: relative; }
.folder-line {
  position: absolute; left: 0; top: 0;
  overflow: visible; pointer-events: none; z-index: 2;
}
.folder-line { color: var(--title); }
.mt[data-line="folder"] .folder-line { color: var(--folder); }
.mt[data-line="none"] .folder-line { display: none; }
.folder-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 32px;
  min-width: 150px;
  padding: 0 18px 0 16px;
  background: var(--title);
  color: var(--titleText);
  border-radius: 12px 0 0 0;
  margin-bottom: -1px;
  font-size: 13px;
  letter-spacing: 1px;
  z-index: 1;
}
.folder-tab::after {
  content: '';
  position: absolute;
  top: 0; right: -38px;
  width: 40px; height: 33px;
  background: var(--title);
  /* 둥근 어깨에서 비스듬히 내려오는 탭 모서리 (아래는 폴더와 겹쳐 이음매가 생기지 않음) */
  clip-path: path('M0 0 H6 C12 0 15 3 18 8 L34 33 H0 Z');
}
.folder {
  background: var(--title);
  border-radius: 0 12px 0 0;
  padding: 10px 14px 12px;
  position: relative;
}
.folder::before {
  content: '';
  position: absolute; inset: 6px 6px 6px 6px;
  background: var(--folder);
  border-radius: 8px;
}
.folder > * { position: relative; }
.nav {
  background: var(--nav);
  display: flex; align-items: center; gap: 12px;
  padding: 7px 14px;
  border-radius: 6px;
}
.nav .ico { display: flex; gap: 10px; color: var(--icon); }
.nav svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.url {
  flex: 1;
  max-width: 260px;
  margin: 0 auto;
  background: var(--url);
  color: var(--urlText);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}
.strip {
  background: var(--strip);
  color: var(--stripText);
  font-size: 10px;
  letter-spacing: 2px;
  white-space: nowrap;
  overflow: hidden;
  padding: 3px 0;
  margin-top: 7px;
}
.banner { height: 150px; }
/* 헤더 사진이 없을 때도 프사 뒤에 테마색 배경이 깔림 */
.slot.banner:not(.has) {
  background:
    radial-gradient(circle, var(--dotBg) 1.4px, transparent 1.6px) 0 0 / 14px 14px,
    linear-gradient(135deg, var(--folder), var(--url));
}
.mt:not(.show-banner) .banner { display: none; }

/* 프로필 */
.profile {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 20px;
  padding: 0 20px 22px;
  background: var(--card);
  border-radius: 0 0 8px 8px;
}
.mt:not(.show-banner) .profile { padding-top: 18px; }
.pf-left { min-width: 0; }
.avatar {
  width: 112px; height: 112px;
  border-radius: 50%;
  border: 5px solid var(--card);
  box-shadow: 0 0 0 2px var(--plBg);
  margin: -56px 0 0 4px;
  position: relative;
  z-index: 1;
}
.mt:not(.show-banner) .avatar { margin-top: 0; }
.avatar .slot-tools { right: auto; left: 50%; transform: translateX(-50%); bottom: 10px; gap: 2px; }
.avatar .slot-tools button { padding: 2px 3px; font-size: 10px; }
.nick { font-size: 26px; font-weight: 700; line-height: 1.2; margin-top: 8px; }
.handle { font-size: 12px; color: var(--sub); margin-top: 1px; }
.bio { font-size: 12px; line-height: 1.6; margin-top: 8px; overflow-wrap: anywhere; }
.joined {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--sub); margin-top: 8px;
}
.joined svg { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }

.about {
  margin-top: 16px;
  border: 2px solid var(--plBg);
  border-radius: 4px;
  background: var(--card);
  position: relative;
  z-index: 1;
}

.about-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-bottom: 2px solid var(--plBg);
}
.about-icon {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 3px;
  border: 1.5px solid var(--plBg);
  border-radius: 3px;
  font-size: 12px;
  color: var(--plText);
}
.pl-label { font-size: 15px; font-weight: 700; color: var(--plText); }
.pl-body { font-size: 13px; line-height: 1.6; padding: 8px 12px 12px; overflow-wrap: anywhere; }

/* 사진 칸 */
.slot {
  position: relative;
  overflow: hidden;
  background: var(--empty);
  cursor: pointer;
}
.slot.has { cursor: grab; touch-action: none; }
.slot.has:active { cursor: grabbing; }
.slot > img.ph {
  position: absolute;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  image-rendering: auto;
}
.slot-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; text-shadow: 0 1px 2px #0004;
  pointer-events: none;
}
.slot.has .slot-hint { display: none; }
.slot.drop { box-shadow: inset 0 0 0 3px #e88aab; }
.slot-tools {
  position: absolute; right: 4px; bottom: 4px;
  display: none; gap: 3px; z-index: 2;
}
.slot.has:hover .slot-tools { display: flex; }
.slot-tools button, .pair-tools button {
  font: 11px Galmuri11, sans-serif;
  border: 0; border-radius: 6px;
  background: #000a; color: #fff;
  padding: 3px 6px; cursor: pointer;
}
.slot-tools button:hover, .pair-tools button:hover { background: #e88aab; }

/* 페어 카드 */
.pair {
  position: relative;
  height: 236px;
  border-radius: 6px;
  overflow: hidden;
}
.pair > .slot { position: absolute; inset: 0; }
.pair-text {
  position: absolute;
  transform: translate(-50%, -50%);
  color: var(--pairText);
  text-shadow: 0 1px 0 #0003, 0 0 6px #0002;
  max-width: 80%;
  width: max-content;
  z-index: 1;
}
.pair-text.left { text-align: left; }
.pair-text.center { text-align: center; }
.pair-text.right { text-align: right; }
.pt-move {
  position: absolute; left: -24px; top: 0;
  width: 20px; height: 20px; border-radius: 6px;
  background: #000a; color: #fff; text-shadow: none;
  font: 13px/20px Galmuri11, sans-serif; text-align: center;
  cursor: move; display: none; touch-action: none;
}
.pair:hover .pt-move, .pair.moving .pt-move { display: block; }
.pair.moving .pair-text { outline: 1px dashed #fff; outline-offset: 4px; }
.pair-name { color: var(--pairName); }
.pair-tags { color: var(--pairTags); }
.pair-name { font-size: 26px; font-weight: 700; line-height: 1.3; }
.pair-tags { font-size: 15px; line-height: 1.5; margin-top: 4px; }
.pair-tools {
  position: absolute; left: 6px; top: 6px; z-index: 3;
  display: none; gap: 3px;
}
.pair:hover .pair-tools { display: flex; }

/* 스티커 */
.stickers { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.sticker {
  position: absolute;
  pointer-events: auto;
  cursor: move;
  touch-action: none;
}
.sticker img { display: block; width: 100%; height: auto; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.sticker.sel { outline: 1px dashed #e88aab; outline-offset: 2px; }
.sticker .h {
  position: absolute; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 2px solid #e88aab; display: none;
  font: 10px/12px Galmuri11, sans-serif; text-align: center; color: #e88aab;
}
.sticker.sel .h { display: block; }
.h-rot { top: -26px; left: 50%; margin-left: -8px; cursor: grab; }
.h-size { right: -10px; bottom: -10px; cursor: nwse-resize; }
.h-del { right: -10px; top: -10px; cursor: pointer; background: #e88aab !important; color: #fff !important; }
.mt.exporting .sticker { outline: none; }

/* 프로필과 첫 페어 카드를 붙임 */
.mt.has-pairs .profile { border-radius: 0; }
.pair-row {
  position: relative;
  display: grid;
  gap: 3px;
  background: var(--card);
}
.pair-row + .pair-row { border-top: 3px solid var(--card); }
.pair-row[data-cols="1"] { grid-template-columns: 1fr; }
.pair-row[data-cols="2"] { grid-template-columns: repeat(2, 1fr); }
.pair-row[data-cols="3"] { grid-template-columns: repeat(3, 1fr); }
.pair-row[data-cols="4"] { grid-template-columns: repeat(4, 1fr); }
#pairs .pair { border-radius: 0; min-width: 0; }
.pair-row[data-cols="1"] .pair { height: 236px; }
.pair-row[data-cols="2"] .pair { height: 340px; }
.pair-row[data-cols="3"] .pair { height: 280px; }
.pair-row[data-cols="4"] .pair { height: 230px; }
.pair-row[data-cols="2"] .pair-name { font-size: 21px; }
.pair-row[data-cols="2"] .pair-tags { font-size: 13px; }
.pair-row[data-cols="3"] .pair-name { font-size: 17px; }
.pair-row[data-cols="3"] .pair-tags { font-size: 12px; }
.pair-row[data-cols="4"] .pair-name { font-size: 14px; }
.pair-row[data-cols="4"] .pair-tags { font-size: 11px; }
#pairs .pair-row:last-child { border-radius: 0 0 8px 8px; overflow: hidden; }
.row-tools {
  position: absolute; left: 6px; top: 6px; z-index: 4;
  display: none; gap: 3px; flex-wrap: wrap;
}
.pair-row:hover .row-tools { display: flex; }
.pair-tools { top: auto; bottom: 6px; }
.row-tools button {
  font: 11px Galmuri11, sans-serif;
  border: 0; border-radius: 6px;
  background: #000a; color: #fff;
  padding: 3px 6px; cursor: pointer;
}
.row-tools button:hover, .row-tools button.on { background: #e88aab; }
.row-tools button:disabled { opacity: .4; cursor: default; }
