:root {
  --bg: #fbf4f4;
  --panel: #ffffff;
  --panel2: #fdf8f8;
  --line: #f0dfdf;
  --text: #2e2426;
  --muted: #9a8587;
  --accent: #ff8a8a;
  --accent-hover: #f57373;
  --accent-ink: #5b1f1f;   /* 연한 코랄 위에선 흰 글씨가 잘 안 읽혀서 짙은 팥색 */
  --accent-soft: #ffe8e8;
  --accent-text: #b8403f;
  --stage: #f5e6e6;
  --chip: #fbecec;
  --sel: #3b82f6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1718; --panel: #252021; --panel2: #201b1c; --line: #3b3133; --text: #f1e9ea; --muted: #a8979a;
    --accent-soft: #3d2526; --accent-text: #ffaaaa; --stage: #141011; --chip: #30282a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1718; --panel: #252021; --panel2: #201b1c; --line: #3b3133; --text: #f1e9ea; --muted: #a8979a;
  --accent-soft: #3d2526; --accent-text: #ffaaaa; --stage: #141011; --chip: #30282a; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: 'Gowun Dodum', 'Noto Sans KR', system-ui, sans-serif; font-size: 14px;
  display: flex; flex-direction: column; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
small { color: var(--muted); font-weight: 400; }

/* ---------- 상단 ---------- */
.top {
  height: 56px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-family: 'Jua', sans-serif; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.brand .logo { width: 30px; height: 30px; display: block; flex: none; }
.brand small { font-family: 'Gowun Dodum'; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--chip); }
.tools { display: flex; gap: 6px; align-items: center; }
.tools button {
  border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: 10px;
}
.tools button:hover { background: var(--chip); }
.tools .primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; padding: 7px 18px; }
.tools .primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.tools .primary:disabled { opacity: .6; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

/* ---------- 레이아웃 ---------- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 300px 1fr 300px; }
.left, .right { background: var(--panel); overflow-y: auto; min-height: 0; }
.left { border-right: 1px solid var(--line); }
.right { border-left: 1px solid var(--line); }
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.tabs { display: flex; position: sticky; top: 0; background: var(--panel); z-index: 2; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: 0; background: none; padding: 13px 0; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 700; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.pane { display: none; padding: 6px 14px 30px; }
.pane.on { display: block; }
h3 { font-size: 13px; margin: 18px 0 8px; font-family: 'Jua'; font-weight: 400; letter-spacing: .02em; }
h3 small { font-family: 'Gowun Dodum'; margin-left: 4px; font-size: 11px; }
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 10px; line-height: 1.5; }

.preset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.left { overflow-x: hidden; }
.pbtn {
  text-align: left; border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 9px 10px;
  display: flex; flex-direction: column; gap: 2px; min-height: 44px; justify-content: center;
}
.pbtn b { font-size: 13.5px; }
.pbtn small { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.pbtn:hover { border-color: var(--accent); background: var(--accent-soft); }

.frame-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.fbtn {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 8px 4px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--muted);
}
.fbtn svg { width: 34px; height: 34px; }
.fbtn span { font-size: 11.5px; color: var(--text); }
.fbtn:hover { border-color: var(--accent); background: var(--accent-soft); }
.shapesel .shb svg { color: #9a9087; }
.btns button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.sticker-grid.chara { grid-template-columns: repeat(3, 1fr); }
.sticker-grid.wide { grid-template-columns: 1fr; }
.stk {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 4px;
  aspect-ratio: 1; display: grid; place-items: center; overflow: hidden;
}
.sticker-grid.chara .stk { aspect-ratio: 3/4; padding: 0; align-items: end; }
.sticker-grid.wide .stk { aspect-ratio: 3/1; padding: 10px; }
.stk img { max-width: 100%; max-height: 100%; pointer-events: none; }
.sticker-grid.chara .stk img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.stk svg { width: 80%; height: 80%; }
.stk:hover { border-color: var(--accent); background: var(--accent-soft); }

.searchbar { position: sticky; top: 46px; z-index: 1; background: var(--panel); padding: 10px 0 8px; }
.searchbar input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel2); color: var(--text); font: inherit;
}
.searchbar input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.seg.mini { margin-bottom: 8px; }
.char-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.ccard {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 0 0 5px; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative;
}
.ccard img { width: 100%; aspect-ratio: 1; object-fit: cover; object-position: 50% 12%; background: var(--chip); }
.ccard b { font-size: 11.5px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; padding: 0 3px; }
.ccard small { position: absolute; top: 4px; right: 4px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 10px; padding: 0 5px; border-radius: 99px; }
.ccard:hover { border-color: var(--accent); }
.chead { display: flex; align-items: baseline; gap: 8px; margin: 2px 0 10px; flex-wrap: wrap; }
.chead b { font-family: 'Jua'; font-weight: 400; font-size: 18px; }
.back { border: 1px solid var(--line); background: var(--panel2); border-radius: 99px; padding: 3px 10px; font-size: 12px; }
.back:hover { border-color: var(--accent); }
.stk.skin { aspect-ratio: auto; display: flex; flex-direction: column; padding: 0 0 4px; gap: 3px; }
.stk.skin img { width: 100%; aspect-ratio: 3/4; object-fit: cover; object-position: top; max-height: none; }
.stk.skin span { font-size: 10.5px; line-height: 1.25; padding: 0 4px; color: var(--text); text-align: center; word-break: keep-all; }
.sticker-grid.sd { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sticker-grid.emoc { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.sticker-grid.logos { grid-template-columns: 1fr 1fr; }
.sticker-grid.logos .stk { aspect-ratio: 3/1; padding: 8px; }
.stk.dark { background: #2b2622; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 16px; cursor: pointer;
  border: 2px dashed var(--line); border-radius: 14px; text-align: center; margin-bottom: 8px;
}
.drop span { color: var(--muted); font-size: 12px; }
.drop:hover { border-color: var(--accent); }

/* ---------- 무대 ---------- */
.stage {
  flex: 1; min-height: 0; background: var(--stage); display: grid; place-items: center; overflow: hidden;
  position: relative;
}
.stage.dragover { outline: 3px dashed var(--accent); outline-offset: -10px; }
.sizer { position: relative; }
.card {
  position: absolute; left: 0; top: 0; transform-origin: 0 0; overflow: hidden;
  background-repeat: repeat; box-shadow: 0 2px 0 rgba(0, 0, 0, .06), 0 10px 30px rgba(0, 0, 0, .08);
  color: #2b2622; font-family: 'Noto Sans KR';
}
.helpbar {
  flex: none; display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; padding: 9px 12px;
  background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 12px;
}
kbd { font-family: inherit; background: var(--chip); color: var(--text); padding: 1px 6px; border-radius: 5px; margin-right: 3px; }

/* ---------- 카드 바탕 층 ---------- */
.bg-layer { position: absolute; inset: 0; pointer-events: none; }
.bg-photo { background-size: cover; background-repeat: no-repeat; }
.bg-pattern { background-repeat: repeat; }

/* ---------- 카드 안 요소 ---------- */
.item { position: absolute; transform-origin: 50% 50%; cursor: grab; user-select: none; touch-action: none; }
.item.locked { cursor: default; }
.item.sel { outline: 2px solid var(--sel); outline-offset: 4px; }
.item.sel.locked { outline-style: dashed; }
.item > svg { display: block; overflow: visible; }
.txt { outline: none; word-break: keep-all; overflow-wrap: anywhere; min-height: 1em; }
.txt[contenteditable="true"] { cursor: text; user-select: text; box-shadow: 0 0 0 3px rgba(59, 130, 246, .35); }
.boxin, .imgwrap { width: 100%; height: 100%; }
.imgwrap img { width: 100%; height: 100%; display: block; pointer-events: none; }
.h {
  position: absolute; width: 22px; height: 22px; background: #fff; border: 3px solid var(--sel); border-radius: 50%;
  z-index: 5;
}
.h-rs { right: -15px; bottom: -15px; cursor: nwse-resize; }
.h-rot { left: 50%; top: -46px; margin-left: -11px; cursor: grab; background: var(--sel); }
.h-rot::after { content: ''; position: absolute; left: 50%; top: 19px; width: 2px; height: 20px; background: var(--sel); margin-left: -1px; }

/* 프로필 프레임 */
.cpdefs { position: absolute; width: 0; height: 0; overflow: hidden; }
.fr-out { position: absolute; inset: 0; overflow: hidden; }
.fr-in { position: absolute; overflow: hidden; }
.fr-in img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; display: block; pointer-events: none; transform-origin: 50% 50%; }
.ph {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-family: 'Jua'; font-size: 30px; color: rgba(43, 38, 34, .45); text-align: center; line-height: 1.3;
}
.ph small { font-family: 'Gowun Dodum'; font-size: 17px; color: inherit; }
.item.cropping { outline: 3px dashed var(--accent); outline-offset: 4px; cursor: move; }

/* 선택 칩 */
.chips { line-height: 1.25; }
.ctitle { font-family: 'Jua'; font-size: 1.05em; margin-bottom: .5em; }
.clist { display: flex; flex-wrap: wrap; gap: .38em; }
.chip {
  display: inline-block; padding: .28em .7em; border-radius: 99px; border: 2px solid currentColor;
  color: var(--ink); opacity: .32; cursor: pointer; white-space: nowrap;
}
.chip.on { opacity: 1; }
.chip-empty { opacity: .4; font-size: .85em; }
.st-fill .chip.on { background: var(--ac); border-color: var(--ac); color: var(--ac-ink, #fff); }
.st-circle .chip { border-color: transparent; position: relative; opacity: .45; }
.st-circle .chip.on { opacity: 1; border-color: var(--ac); border-width: 3px; border-radius: 50%; transform: rotate(-3deg); }
.st-check .chip { border-color: transparent; padding-left: .2em; padding-right: .5em; opacity: .5; }
.st-check .chip::before { content: '☐ '; }
.st-check .chip.on { opacity: 1; }
.st-check .chip.on::before { content: '☑ '; color: var(--ac); }

/* ---------- 인스펙터 ---------- */
#inspector { padding: 6px 14px 30px; }
.ihead { display: flex; justify-content: space-between; align-items: center; padding: 12px 0 8px; border-bottom: 1px solid var(--line); }
.ihead b { font-family: 'Jua'; font-weight: 400; font-size: 17px; }
.muted { color: var(--muted); font-size: 12px; }
h4 { font-family: 'Jua'; font-weight: 400; font-size: 13px; margin: 16px 0 6px; color: var(--muted); }
.f { display: flex; flex-direction: column; gap: 5px; margin-bottom: 9px; }
.f > span { font-size: 12px; color: var(--muted); }
.f > span:empty { display: none; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rng { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 120px; }
.rng input { flex: 1; accent-color: var(--accent); }
.rng output { width: 42px; text-align: right; font-size: 12px; color: var(--muted); }
input[type=text], select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel2); color: var(--text); font: inherit;
}
input[type=color] { width: 36px; height: 28px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--panel2); cursor: pointer; }
.ck { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; cursor: pointer; }
.ck input { accent-color: var(--accent); }
.sw { display: flex; flex-wrap: wrap; gap: 5px; }
.swb { width: 22px; height: 22px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .15); padding: 0; }
.swb:hover { transform: scale(1.12); }
.shapesel .shb { width: 40px; height: 40px; border: 1px solid var(--line); background: var(--panel2); border-radius: 9px; padding: 5px; }
.shapesel .shb.on { border-color: var(--accent); background: var(--accent-soft); }
.shapesel svg { width: 100%; height: 100%; }
.seg { display: flex; gap: 4px; }
.seg.wrap { flex-wrap: wrap; }
.seg button { flex: 1; border: 1px solid var(--line); background: var(--panel2); border-radius: 9px; padding: 6px 4px; font-size: 12.5px; display: flex; flex-direction: column; align-items: center; }
.seg.wrap button { flex: 1 1 calc(50% - 4px); }
.seg button small { font-size: 10.5px; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg button.on small { color: var(--accent-ink); opacity: .85; }
.optlist { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.opt { display: flex; gap: 6px; align-items: center; }
.opt input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.opt input[type=text] { padding: 5px 8px; }
.opt .x { border: 0; background: none; color: var(--muted); font-size: 18px; padding: 0 4px; }
.opt .x:hover { color: var(--accent); }
.addopt { flex-wrap: nowrap; margin-bottom: 8px; }
.addopt button, .btns button { border: 1px solid var(--line); background: var(--panel2); border-radius: 9px; padding: 7px 10px; white-space: nowrap; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 6px; }
.btns button:hover, .addopt button:hover { background: var(--chip); }
.btns .danger { color: #e0452b; }
.bgthumb { height: 110px; border-radius: 12px; border: 1px solid var(--line); background-size: cover; background-position: center; margin-bottom: 4px; }
.btns.one { grid-template-columns: 1fr; margin-top: 10px; }
.btnlike {
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel2); border-radius: 9px; padding: 7px 10px;
}
.btnlike:hover { background: var(--chip); }
.drop.small { padding: 12px; margin: 0 0 6px; }
.tips { padding-left: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.6; margin: 0; }
.tips b { color: var(--text); }

.toast {
  position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; transition: .2s; z-index: 50;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 좁은 화면 ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 260px 1fr 260px; }
}
@media (max-width: 820px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 70vh auto; }
  .center { order: -1; }
  .left, .right { border: 0; border-top: 1px solid var(--line); max-height: none; }
  .tools button:not(.primary):not(#btnTheme) { display: none; }
  .tools .sep { display: none; }
}
.sticker-grid.skins { grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* 도형 미리보기는 테마와 상관없이 밝은 바탕 위에 (검은 선 장식도 잘 보이게) */
.sticker-grid.shapes .stk { background: #fdf6f6; border-color: #f0dfdf; }
.sticker-grid.shapes .stk:hover { background: #ffe8e8; border-color: var(--accent); }

/* 이미지 자르기 */
.crop-ghost { opacity: .28; pointer-events: none; }
.ch { position: absolute; background: #fff; border: 3px solid var(--accent); border-radius: 99px; z-index: 6; }
.ch-l, .ch-r { top: 50%; width: 16px; height: 56px; margin-top: -28px; cursor: ew-resize; }
.ch-t, .ch-b { left: 50%; height: 16px; width: 56px; margin-left: -28px; cursor: ns-resize; }
.ch-l { left: -9px; } .ch-r { right: -9px; } .ch-t { top: -9px; } .ch-b { bottom: -9px; }

/* 슬라이더 옆 숫자 칸 · 위치/크기 입력 */
.numwrap { display: inline-flex; align-items: center; gap: 2px; flex: none; }
.numwrap i { font-style: normal; font-size: 11px; color: var(--muted); }
input.num {
  width: 54px; padding: 4px 5px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel2);
  color: var(--text); font: inherit; font-size: 12.5px; text-align: right;
}
input.num:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.num::-webkit-inner-spin-button { opacity: .5; }
.row.nowrap { flex-wrap: nowrap; }
.xy { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.xy b { font-weight: 400; font-size: 12px; color: var(--muted); white-space: nowrap; }
.xy input.num { width: 100%; min-width: 0; }
.xy .numwrap { flex: 1; min-width: 0; }
.f > span small { font-size: 10.5px; margin-left: 4px; }

/* 선택 항목: 제목 · 칩 나란히 */
.chips.lay-inline { display: flex; align-items: center; gap: .7em; }
.chips.lay-inline .ctitle { margin-bottom: 0; flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips.lay-inline .clist { flex: 1; min-width: 0; }

/* 배경·테두리 없는 빈 프레임도 편집 중엔 보이게 (PNG 저장 땐 .ph 가 빠짐) */
.ph.ph-guide { border: 3px dashed rgba(43, 38, 34, .3); border-radius: inherit; background: rgba(255, 255, 255, .35); }

/* 격자 · 줄맞춤 (편집용, PNG에는 안 나옴) */
.grid-overlay, .guides { position: absolute; inset: 0; pointer-events: none; z-index: 50; }
.grid-overlay { background-repeat: repeat; }
.guides i { position: absolute; background: #ff3d8b; }
.tools button.on:not(.primary) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }

/* 도움말 안내 */
.tour { position: fixed; inset: 0; z-index: 200; }
.tour-spot {
  position: fixed; border-radius: 14px; border: 3px solid var(--accent); pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(30, 18, 20, .62); transition: left .2s, top .2s, width .2s, height .2s;
}
.tour-card {
  position: fixed; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 18px 14px; box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
}
.tour-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.tour-head b { font-family: 'Jua'; font-weight: 400; font-size: 19px; flex: 1; }
.tour-no { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.tour-x { border: 0; background: none; font-size: 22px; color: var(--muted); padding: 0 4px; }
.tour-card dl { margin: 0; display: grid; gap: 7px; }
.tour-card dt { font-weight: 700; font-size: 13.5px; }
.tour-card dd { margin: 1px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.tour-tip { margin: 12px 0 0; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); font-size: 12.5px; }
.tour-foot { display: flex; align-items: center; gap: 6px; margin-top: 14px; }
.tour-foot > button { border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 7px 14px; }
.tour-foot > button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.tour-dots { display: flex; gap: 5px; flex: 1; }
.tour-dots button { width: 8px; height: 8px; border-radius: 50%; border: 0; padding: 0; background: var(--line); }
.tour-dots button.on { background: var(--accent); width: 18px; border-radius: 99px; }

/* 카드는 글 편집 때 안쪽이 밀려 올라가지 않게(clip), 길어진 카드는 작업 화면을 스크롤 */
.card { overflow: clip; }
.stage { overflow: auto; place-items: start center; padding: 24px 0; }
