:root {
  --page: #f4f1ee;
  --card: #ffffff;
  --ink: #2b2523;
  --muted: #7d726e;
  --rule: #e4ddd8;
  --accent: #5d4e48;
  --accent-ink: #ffffff;
  --on: #c9573f;
}

/* 복사한 이미지의 dovemayo.com 글자에 쓴다 (둘기마요고딕 소문자) */
@font-face {
  font-family: "Dovemayo Gothic";
  src: url("../fonts/dovemayo-gothic-latin.woff2") format("woff2");
  font-display: swap;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}

.app {
  display: grid;
  grid-template-columns: minmax(280px, 520px) minmax(320px, 540px);
  gap: 28px;
  justify-content: center;
  align-items: start;
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}

/* ---------- 미리보기 ---------- */
.stage { position: sticky; top: 20px; display: grid; gap: 12px; }

.preview {
  aspect-ratio: 1;
  border-radius: 28px;
  overflow: hidden;
  background:
    repeating-conic-gradient(#ebe6e2 0 25%, #f7f4f1 0 50%) 0 0 / 24px 24px;
  box-shadow: 0 1px 2px rgba(60, 40, 30, .08), 0 12px 32px rgba(60, 40, 30, .10);
}
.preview svg { display: block; width: 100%; height: 100%; }
.preview-wrap { position: relative; }

/* 카드 옆 버튼: 휴대폰에서만 보인다. 아이콘 아래에 작은 글씨 */
.card-tools { display: none; }
.ico {
  width: 42px;
  height: 46px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 12px;
  border: 1px solid var(--rule);
  background: #fff;
  font-size: 10px;
  line-height: 1.1;
  -webkit-tap-highlight-color: transparent;
}
.ico svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico:disabled { opacity: .4; }
/* 랜덤: 화면의 랜덤 버튼과 같은 갈색으로만 구분한다 (그림자 없음) */
.ico.go { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* 안내 글: 카드 아래쪽에 잠깐 뜬다 */
.toast {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  margin: 0;
  padding: 5px 11px;
  border-radius: 9px;
  background: rgba(43, 37, 35, .84);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}
.toast:empty { display: none; }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.actions.four { grid-template-columns: repeat(4, 1fr); }
.actions.four button { padding-inline: 4px; white-space: nowrap; }

button {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
}
button:hover { border-color: #c9beb8; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--on);
  outline-offset: 2px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 16px;
  padding: 12px;
}
button.primary:hover { background: #4d403b; }

.build-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.build-bar button { white-space: nowrap; }
.build-bar .status { margin: 0; }
.build-bar[hidden] { display: none; }

.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); }

.code label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.code-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.code input {
  min-width: 0;
  font: 12px/1.4 ui-monospace, Consolas, monospace;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 9px 10px;
}
.status { min-height: 1.5em; margin: 6px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- 패널 ---------- */
/* 설정 카드 위의 홈페이지 링크 */
.side { display: grid; gap: 8px; min-width: 0; }
.back { justify-self: start; font-size: 13px; color: var(--muted); }
.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 20px;
  padding: 20px;
}
.panel-head h1 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.panel-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
/* 카테고리마다 위에 구분선, 그 아래 둥근 제목 */
.group { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--rule); }
.panel h2 {
  margin: 0 0 10px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--group-bg, #f1ebe7);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
/* 묶음마다 옅은 배경색 (헤어 · 눈 · 얼굴 · 악세사리 · 옷 · 배경) */
.group[data-group="hair"] { --group-bg: #f2e5da; }
.group[data-group="eyes"] { --group-bg: #e2eaf3; }
.group[data-group="face"] { --group-bg: #f6e2e0; }
.group[data-group="acc"] { --group-bg: #f3ecd4; }
.group[data-group="cloth"] { --group-bg: #e3eee0; }
.group[data-group="bg"] { --group-bg: #ebe8e6; }

.panel h3 {
  margin: 14px 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .02em;
}
.panel h2 + h3 { margin-top: 0; }
.panel-head .repo { display: inline-block; margin: 2px 10px 0 0; font-size: 13px; color: var(--muted); }

.rows { display: grid; gap: 8px; }
/* 제목 없는 소분류끼리는 틈으로만 나눈다 */
.rows + .rows { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--rule); }

.row {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}
.row .name, .color-head .name { font-weight: 600; white-space: nowrap; }

.row select {
  width: 100%;
  min-width: 0;
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 8px 8px;
}

.row button { padding: 7px 0; }
/* 썸네일 고르기: 드롭다운처럼 생긴 버튼 + 아래에 열리는 썸네일 카드 */
.part-item { display: grid; gap: 6px; }
.row .pick { display: flex; align-items: center; gap: 6px; width: 100%; min-width: 0; padding: 8px 10px; text-align: left; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--rule); border-radius: 10px; }
.row .pick[aria-expanded="true"] { border-color: var(--accent); }
.pick-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-arrow { flex: none; font-size: 11px; color: var(--muted); }
.thumb-card { max-height: 360px; overflow-y: auto; padding: 8px 10px 10px; border: 1px solid var(--rule); border-radius: 14px; background: var(--card); }
.thumb-card[hidden] { display: none; }
.thumb-group { margin: 6px 0 4px; font-size: 12px; color: var(--muted); }
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.row button.thumb, .thumb { position: relative; display: grid; gap: 2px; padding: 3px 3px 4px; background: var(--card); border: 2px solid var(--rule); border-radius: 10px; cursor: pointer; }
.thumb[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(93, 78, 72, .25); }
.thumb .th-img { display: block; aspect-ratio: 1; border-radius: 7px; overflow: hidden; }
.thumb svg { display: block; width: 100%; height: 100%; }
.thumb .th-name { font-size: 10.5px; line-height: 1.2; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.row .step { width: 34px; }
.row .file { padding: 7px 10px; font-size: 12px; white-space: nowrap; }
.row .tools { display: flex; gap: 6px; }
.tool, .tool-gap { width: 34px; height: 34px; flex: none; }
.row .tool, .color-head .tool { padding: 0; display: grid; place-items: center; }
.tool svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool:disabled { opacity: .28; cursor: default; }
.flip.idle { opacity: .4; }
/* 반전 켜짐: 덜 진한 갈색 (2026-11-16, 예전 --accent 는 너무 진함) */
.flip[aria-pressed="true"] { background: #b39484; border-color: #b39484; color: #fff; }

.lock[aria-pressed="true"] {
  background: var(--on);
  border-color: var(--on);
  color: #fff;
}

/* ---------- 색 ---------- */
.color-row { display: grid; gap: 6px; padding: 4px 0 6px; }
.color-head { display: flex; gap: 6px; align-items: center; }
.color-head .name { width: 104px; flex: none; }
.color-head .picked { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
/* 커스텀 색 칸: 무지개 테두리, 고른 커스텀 색이 가운데에 */
.swatch.custom { background: radial-gradient(circle, var(--c, transparent) 0 46%, transparent 47%), conic-gradient(#e0475a, #e8a23a, #e5d84a, #5fc06a, #4aa6d8, #7a5ad0, #d04aa8, #e0475a); }
.custom-pick { display: flex; gap: 12px; align-items: stretch; padding: 10px; border: 1px solid var(--rule); border-radius: 14px; background: var(--card); }
.custom-pick[hidden] { display: none; }
.cp-preview { flex: none; width: 92px; border-radius: 12px; border: 1px solid rgba(43, 37, 35, .12); min-height: 92px; }
.cp-side { flex: 1; min-width: 0; display: grid; gap: 6px; }
.cp-line { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.cp-name { flex: none; width: 28px; }
.cp-num { flex: none; width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.cp-line input[type=range] { flex: 1; min-width: 0; height: 14px; border-radius: 7px; -webkit-appearance: none; appearance: none; border: 1px solid rgba(43, 37, 35, .12); margin: 0; }
.cp-line input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); cursor: pointer; }
.cp-line input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); cursor: pointer; }
.cp-hex { width: 100px; font: 13px ui-monospace, Consolas, monospace; color: var(--ink); background: var(--card); border: 1px solid var(--rule); border-radius: 8px; padding: 4px 8px; }
.swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, .18);
}
.swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink);
}
.swatch.none {
  background:
    linear-gradient(135deg, transparent 46%, #c9573f 46% 54%, transparent 54%),
    #fff;
}

/* ---------- 휴대폰 ----------
   얼굴 카드는 화면 위에 붙어 있고, 버튼은 카드 양옆 여백의 아이콘 넷뿐이다 (왼쪽 랜덤, 오른쪽 이전 · 자랑 · 복사).
   항목은 한 줄에 하나: 이름 · 선택 · 랜덤 · 고정 */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 0 12px 40px; }
  .stage {
    position: sticky;
    top: 0;
    z-index: 5;
    display: block;
    margin: 0 -12px;
    padding: 10px 12px 8px;
    background: var(--page);
    box-shadow: 0 6px 10px -8px rgba(60, 40, 30, .35);
  }
  /* 버튼 기둥(42px) · 카드 · 버튼 기둥을 나란히 놓는다. 카드는 두 기둥만큼 줄어든다 */
  .preview-row { display: flex; justify-content: center; align-items: stretch; gap: 6px; }
  .preview-wrap { flex: none; width: min(calc(100% - 96px), 42vh, 400px); width: min(calc(100% - 96px), 42svh, 400px); }
  .preview { border-radius: 22px; box-shadow: 0 1px 2px rgba(60, 40, 30, .08); }
  .stage .actions, .stage .code, .stage .build-bar, .stage .masc-row { display: none; }
  .card-tools { display: flex; flex-direction: column; gap: 6px; flex: none; }
  /* 랜덤 버튼 아래 세로 슬라이더: 위 = 여자, 아래 = 남자 */
  .card-tools .masc-v { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; min-height: 0; padding: 4px 0 2px; font-size: 10px; color: var(--muted); }
  .card-tools .masc-v[hidden] { display: none; }
  .masc-v input { writing-mode: vertical-lr; direction: ltr; flex: 1; min-height: 60px; width: 22px; margin: 0; accent-color: var(--accent); }

  .panel { padding: 14px 12px; border-radius: 16px; }
  .panel-head h1 { font-size: 17px; }
  .group { margin-top: 14px; padding-top: 14px; }
  .panel h2 { margin: 0 0 8px; padding: 7px 12px; border-radius: 10px; }
  .panel h3 { margin: 10px 0 6px; }
  .rows { gap: 6px; }
  .row { grid-template-columns: 82px minmax(0, 1fr) auto; gap: 5px; }
  .row .tools { gap: 5px; }
  .tool-gap { display: none; }
  .row .step { display: none; }
  .row .name, .color-head .name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
  .row select { padding: 7px 4px; }
  .row .file { padding: 7px 8px; }
  .color-head { gap: 5px; }
  .color-head .name { width: 82px; }
  .swatch { width: 28px; height: 28px; }
}

/* ---------- 항목 편집 ---------- */
.items-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 18px;
  background: var(--card);
  color: var(--ink);
}
/* 랜덤 성별 비율 슬라이더 (여자 ─ 남자) */
.masc-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); padding: 0 4px; }
.masc-row input { flex: 1; accent-color: var(--accent); }
.masc-row[hidden], .masc-v[hidden] { display: none; }
.masc-v { display: none; }
.sheet-dialog { width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 32px); border: 1px solid var(--rule); border-radius: 18px; padding: 16px; color: var(--ink); background: var(--card); }
.sheet-dialog::backdrop { background: rgba(40, 30, 25, .35); }
.sheet-dialog[open] { display: flex; flex-direction: column; gap: 10px; }
/* 프롬프트 (로컬 테스트) */
.prompt-dialog { width: min(720px, calc(100vw - 32px)); }
.prompt-dialog h2 small { font-weight: 400; font-size: 12px; color: var(--muted); }
.prompt-dialog input, .prompt-dialog textarea { width: 100%; font: 12.5px/1.5 ui-monospace, Consolas, monospace; color: var(--ink); background: var(--card); border: 1px solid var(--rule); border-radius: 10px; padding: 8px 10px; resize: vertical; }
.prompt-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.prompt-head button { padding: 4px 12px; font-size: 12px; }
.sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; overflow: auto; padding: 2px; }
.sheet-cell { position: relative; border-radius: 14px; overflow: hidden; }
.sheet-face { padding: 0; border: 0; border-radius: 0; background: none; display: block; width: 100%; cursor: pointer; }
.sheet-face svg { display: block; width: 100%; height: auto; }
.sheet-face:hover { filter: brightness(1.06); }
.sheet-re { position: absolute; top: 6px; left: 6px; width: 28px; height: 28px; padding: 0; display: grid; place-items: center; border-radius: 9px; border: 1px solid rgba(43, 37, 35, .10); background: rgba(255, 255, 255, .86); }
.sheet-re svg { width: 15px; height: 15px; }
.items-dialog::backdrop { background: rgba(40, 30, 25, .35); }
.items-dialog[open] { display: flex; flex-direction: column; gap: 10px; }
.items-head { display: flex; align-items: center; gap: 8px; margin: 0; }
.items-head h2 { margin: 0 auto 0 0; font-size: 17px; }
.items-head select { font: inherit; padding: 7px 8px; border: 1px solid var(--rule); border-radius: 10px; background: var(--card); color: var(--ink); }
.items-help { margin: 0; font-size: 12px; color: var(--muted); }
.items-table-wrap { overflow: auto; border: 1px solid var(--rule); border-radius: 10px; }
.items-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.items-table th { position: sticky; top: 0; background: #faf8f6; text-align: left; font-weight: 600; color: var(--muted); padding: 7px 8px; border-bottom: 1px solid var(--rule); }
.items-table td { padding: 5px 8px; border-bottom: 1px solid #f0ebe7; vertical-align: middle; }
.items-table input[type="text"] { width: 100%; min-width: 120px; font: inherit; padding: 6px 8px; border: 1px solid var(--rule); border-radius: 8px; }
.items-table input[type="number"] { width: 64px; font: inherit; padding: 6px; border: 1px solid var(--rule); border-radius: 8px; }
.items-table .file { font: 12px ui-monospace, Consolas, monospace; color: var(--muted); }
.items-table .order, .items-table .acts { white-space: nowrap; }
.items-table td button { padding: 4px 8px; font-size: 12px; }
.items-table button.danger { color: #b33a2a; }
.items-foot { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.items-foot .status { margin: 0 auto 0 0; }
