:root {
  --bg: #FFF3F7;
  --pink-50: #FFF0F5;
  --pink-100: #FADCE7;
  --pink-200: #F6C4D6;
  --pink-400: #EC76A2;
  --pink-500: #E05A8D;
  --pink-600: #C9447A;
  --ink: #4A2A3A;
  --ink-soft: #8A6576;
  --line: #F1D3DF;
  --white: #fff;
  --radius: 18px;
  --font: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --bar-h: 76px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html.locked { overflow: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--bar-h) + var(--safe-b) + 8px);
  word-break: keep-all;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
/* 화면이 남으면 포스터를 위아래 가운데에 */
.stage { flex: 1 0 auto; display: flex; flex-direction: column; justify-content: center; width: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button, label, summary { cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

/* 상단 */
.top {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px 4px;
  text-align: center;
}
.top__title {
  margin: 0 0 10px;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--pink-500);
}
.top__guide {
  margin: 9px 0 0;
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.top__guide b { color: var(--pink-500); }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--pink-100);
  border-radius: 14px;
}
.tabs__btn {
  border: 0;
  background: transparent;
  padding: 10px 6px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  transition: background .15s, color .15s, box-shadow .15s;
}
.tabs__btn[aria-selected="true"] {
  background: var(--white);
  color: var(--pink-500);
  box-shadow: 0 2px 8px rgba(224, 90, 141, .15);
}

/* 포스터 */
.stage {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 16px 10px;
}
.poster {
  position: relative;
  width: 100%;
  margin: 0 auto;
  aspect-ratio: 1240 / 1754;
  border-radius: 14px;
  overflow: hidden;
  background: var(--pink-100);
  box-shadow: 0 10px 30px rgba(224, 90, 141, .16), 0 1px 3px rgba(224, 90, 141, .12);
}
.poster canvas { display: block; width: 100%; height: 100%; }
.hotspots { position: absolute; inset: 0; }
.hotspot {
  position: absolute;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 3.6%/2.5%;
  transition: background .12s, box-shadow .12s;
}
.hotspot--card { border-radius: 12% / 18%; }
@media (hover: hover) { .hotspot:hover { background: rgba(255, 255, 255, .14); } }
.hotspot:active { background: rgba(224, 90, 141, .12); }
.hotspot:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--pink-500); }

/* 하단 버튼 바 */
.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  background: rgba(255, 243, 247, .9);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + var(--safe-b));
}
.actionbar__inner {
  max-width: 608px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 2.2fr;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 18px;
  border-radius: 14px;
  border: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn:focus-visible { outline: 3px solid var(--pink-200); outline-offset: 2px; }
.btn--primary { background: var(--pink-500); color: var(--white); }
.btn--primary:hover:not(:disabled) { background: var(--pink-600); }
.btn--ghost { background: var(--white); color: var(--pink-600); box-shadow: inset 0 0 0 1.5px var(--pink-200); }
.btn--ghost:hover { background: var(--pink-50); }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: 12px;
  background: var(--pink-50);
  color: var(--ink-soft);
}
.icon-btn:hover { background: var(--pink-100); }
.link-btn {
  border: 0; background: none; padding: 6px 0;
  color: var(--pink-600); font-weight: 700; font-size: 14px;
  text-decoration: underline; text-underline-offset: 3px;
}

/* 시트/모달 공통 */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(74, 42, 58, .38);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .18s ease-out;
}
.backdrop--center { align-items: center; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }

.sheet {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: calc(var(--vvh, 100dvh) - 24px);
  margin-bottom: var(--kb, 0px);
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 30px rgba(74, 42, 58, .15);
  animation: up .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet__grab {
  width: 40px; height: 5px;
  border-radius: 3px;
  background: var(--pink-200);
  margin: 8px auto 0;
}
.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px 6px 20px;
}
.sheet__title {
  margin: 0;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 20px 12px;
}
.sheet__foot, .modal__foot {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line);
}

.mini {
  display: flex;
  justify-content: center;
  padding: 14px;
  margin-bottom: 12px;
  background: var(--mini-bg, var(--pink-100));
  border-radius: 16px;
}
.mini canvas { display: block; max-width: 100%; }

.field { display: block; margin-bottom: 16px; }
.field__label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}
.field__label small { font-weight: 500; color: var(--ink-soft); margin-right: auto; }
.field__count { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.field input[type="text"], .field textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--pink-50);
  padding: 13px 14px;
  font-size: 16px; /* iOS 확대 방지 */
  line-height: 1.45;
  outline: none;
  resize: none;
  transition: border-color .15s, background .15s;
}
.field input[type="text"]:focus, .field textarea:focus { border-color: var(--pink-400); background: var(--white); }
.field textarea::placeholder, .field input::placeholder { color: #C9A3B4; }

.photos {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.photos__item, .photos__add {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  overflow: hidden;
}
.photos__item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos__del {
  position: absolute;
  top: 4px; right: 4px;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(74, 42, 58, .72);
  color: #fff;
}
.photos__add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1.5px dashed var(--pink-400);
  background: var(--pink-50);
  color: var(--pink-500);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.photos__add:hover { background: var(--pink-100); }
.photos__add input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.photos__add:focus-within { box-shadow: 0 0 0 3px var(--pink-200); }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 10px;
  padding: 4px;
  border-radius: 12px;
  background: var(--pink-100);
}
.seg button {
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 9px 4px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
}
.seg button[aria-checked="true"] { background: var(--white); color: var(--pink-500); }

/* 포스터 위 연필 버튼 (칸 이름 바꾸기) */
.pencils { position: absolute; inset: 0; pointer-events: none; }
.pencil {
  position: absolute;
  pointer-events: auto;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px; /* 가운데 기준 배치 */
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  transition: background .12s, transform .12s;
}
.pencil svg {
  width: var(--icon, 14px);
  height: var(--icon, 14px);
  padding: 3px;
  box-sizing: content-box;
  border-radius: 50%;
  background: rgba(255, 255, 255, .22);
  filter: drop-shadow(0 1px 1px rgba(160, 40, 90, .25));
}
@media (hover: hover) { .pencil:hover svg { background: rgba(255, 255, 255, .4); } }
.pencil:active { transform: scale(.9); }
.pencil:focus-visible { outline: none; }
.pencil:focus-visible svg { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--pink-500); }
.pencil[hidden] { display: none; }

.icon-btn--pink { color: var(--pink-500); }
#sheet-close, #save-close { margin-left: auto; }
.sheet__head { justify-content: flex-start; }

/* 저장 모달 */
.modal {
  width: 100%;
  max-width: 460px;
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-radius: 24px;
  overflow: hidden;
  animation: up .22s cubic-bezier(.2, .8, .2, 1);
}
.modal .modal__foot { padding-bottom: 14px; grid-template-columns: auto 1fr; }
.modal__foot .btn { white-space: nowrap; }
.modal__foot--single, .modal .modal__foot--single { grid-template-columns: 1fr; }
.modal--small { max-width: 360px; }
.modal .modal__foot--even { grid-template-columns: 1fr 1fr; }
.confirm { padding: 24px 22px 18px; text-align: center; }
.confirm .sheet__title { white-space: normal; }
.confirm__desc { margin: 10px 0 0; font-size: 15px; line-height: 1.55; color: var(--ink-soft); }
.confirm__desc b { color: var(--pink-600); }
.result {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 20px;
}
.result img {
  display: block;
  max-width: 100%;
  max-height: min(56dvh, 520px);
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(224, 90, 141, .2);
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}
.result__loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 80px 0;
  font-weight: 700;
  color: var(--ink-soft);
}
.result__hint {
  margin: 10px 20px 4px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
  text-align: center;
}
.result__hint b { color: var(--pink-600); }
.spinner {
  width: 20px; height: 20px;
  border: 3px solid var(--pink-100);
  border-top-color: var(--pink-500);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 인앱 브라우저 안내 */
.inapp {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--pink-500);
  color: #fff;
  font-size: 13px;
  line-height: 1.45;
}
.inapp p { margin: 0; flex: 1; }
.inapp__btn {
  flex: none;
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
  color: var(--pink-600);
  font-size: 13px;
  font-weight: 800;
}

/* 토스트 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + var(--safe-b) + 18px);
  z-index: 80;
  transform: translate(-50%, 12px);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: rgba(74, 42, 58, .92);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  display: flex;
  align-items: center;
  gap: 14px;
  width: max-content;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast__action {
  flex: none;
  border: 0;
  padding: 6px 10px;
  margin: -4px -6px -4px 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, .16);
  color: #FFC6DA;
  font-size: 14px;
  font-weight: 800;
}
.toast__action:hover { background: rgba(255, 255, 255, .26); }
.backdrop:not([hidden]) ~ .toast, .viewer:not([hidden]) ~ .toast { bottom: calc(var(--safe-b) + 96px); }

/* 진행률 */
.top__status { margin-top: 9px; display: flex; justify-content: center; }
.progress { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.progress__bar { width: 72px; height: 6px; border-radius: 3px; background: var(--pink-100); overflow: hidden; }
.progress__fill { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--pink-500); transition: width .3s; }
.progress.done .progress__text { color: var(--pink-600); }

/* 포스터 모서리 버튼 (꾸미기 / 크게 보기) */
.corner-btn {
  position: absolute;
  top: 1.6%;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .78);
  color: var(--pink-600);
  box-shadow: 0 2px 8px rgba(224, 90, 141, .18);
}
.corner-btn svg { width: 19px; height: 19px; }
.corner-btn--left { left: 2.2%; }
.corner-btn--right { right: 2.2%; }
@media (hover: hover) { .corner-btn:hover { background: #fff; } }
.corner-btn:focus-visible { outline: 3px solid var(--pink-400); outline-offset: 1px; }

/* 시트: 칸 번호, 3버튼 바닥 */
.sheet__count { font-size: 13px; font-weight: 700; color: var(--ink-soft); margin-left: 2px; white-space: nowrap; }
.sheet__foot.has-next { grid-template-columns: 1fr 1fr 1.5fr; }
.sheet__foot.has-next .btn { padding: 0 10px; white-space: nowrap; }

/* 사진 끌어 옮기기 */
.mini canvas.draggable { cursor: grab; touch-action: none; }
.mini canvas.dragging { cursor: grabbing; }
.mini__hint { margin: -6px 0 14px; font-size: 12.5px; color: var(--ink-soft); text-align: center; }
.mini__hint b { color: var(--pink-600); }
.photos__item.selected { box-shadow: 0 0 0 3px var(--pink-500); }
.photos__item img { cursor: pointer; }
.zoom-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.zoom-row__label { flex: none; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.zoom-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--pink-500); height: 28px; }
.field__warn { display: block; margin-top: 6px; font-size: 12.5px; color: var(--pink-600); }

/* 칸 구성 바꾸기 */
.manage { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.manage summary { font-size: 14px; font-weight: 800; color: var(--ink-soft); padding: 4px 0 10px; }
.manage summary small { font-weight: 500; }
.manage__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chip {
  min-height: 42px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}
.chip:hover:not(:disabled) { background: var(--pink-50); }
.chip:disabled { opacity: .4; cursor: default; }
.chip--danger { grid-column: 1 / -1; color: #C2334F; border-color: #F3C6CF; }

/* 색 고르기 */
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.swatch {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 0; background: none; padding: 6px 0; border-radius: 12px;
  font-size: 12px; font-weight: 700; color: var(--ink-soft);
}
.swatch__dot {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--white);
  box-shadow: 0 0 0 1.5px var(--line);
  background: linear-gradient(135deg, var(--h) 0 50%, var(--b) 50% 100%);
}
.swatch[aria-checked="true"] { color: var(--pink-600); }
.swatch[aria-checked="true"] .swatch__dot { box-shadow: 0 0 0 3px var(--pink-500); }

/* 저장 크기 선택 */
.seg--save { margin: 0 20px 6px; }

/* 크게 보기 */
.viewer {
  position: fixed; inset: 0; z-index: 70;
  display: flex; flex-direction: column;
  background: rgba(40, 20, 30, .92);
}
.viewer__bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px 18px;
  color: #fff;
}
.viewer__hint { font-size: 13px; font-weight: 600; opacity: .85; }
.icon-btn--light { background: rgba(255, 255, 255, .14); color: #fff; }
.icon-btn--light:hover { background: rgba(255, 255, 255, .24); }
.viewer__scroll {
  flex: 1; min-height: 0; overflow: auto;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8px 12px calc(20px + var(--safe-b));
  -webkit-overflow-scrolling: touch;
}
.viewer__scroll canvas {
  display: block; width: 100%; max-width: min(100%, calc((100dvh - 90px) * 1240 / 1754));
  height: auto; border-radius: 8px; cursor: zoom-in; margin: auto;
}
.viewer__scroll.zoomed { justify-content: flex-start; }
.viewer__scroll.zoomed canvas { width: 230%; max-width: none; cursor: zoom-out; margin: 0; }

/* 처음 안내 */
.coach {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(74, 42, 58, .45);
  animation: fade .2s ease-out;
}
.coach__card {
  width: 100%; max-width: 360px;
  padding: 24px 22px 18px;
  border-radius: 24px;
  background: var(--white);
  box-shadow: 0 16px 40px rgba(74, 42, 58, .2);
  animation: up .25s cubic-bezier(.2, .8, .2, 1);
}
.coach__title { margin: 0 0 14px; font-size: 20px; font-weight: 900; letter-spacing: -0.02em; text-align: center; }
.coach__list { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 12px; }
.coach__list li { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; line-height: 1.5; }
.coach__list b { color: var(--pink-600); }
.coach__num {
  flex: none; width: 24px; height: 24px; margin-top: 1px;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--pink-100); color: var(--pink-600);
  font-size: 13px; font-weight: 900;
}
.coach__btn { width: 100%; }

@media (min-width: 720px) {
  .top { padding-top: 20px; }
  .top__title { font-size: 24px; }
  .backdrop:not(.backdrop--center) { align-items: center; padding: 16px; }
  .sheet { border-radius: 24px; max-height: calc(100dvh - 32px); margin-bottom: 0; }
  .sheet__grab { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
