:root {
  --bg: #fff4f7;
  --card: #ffffff;
  --ink: #4a2d22;
  --sub: #9a7b70;
  --pink: #f48fb1;
  --pink-d: #d8679a;
  --choco: #7b4a2d;
  --choco-d: #5c331d;
  --mint: #2f9e7c;
  --line: #f6d3dd;
  --danger: #e5486c;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
/* 모바일 더블탭 확대 막기 (스크롤은 그대로, 게임 캔버스는 아래에서 none) */
html, body, * { touch-action: manipulation; }
html, body { height: 100%; }
body {
  background: radial-gradient(circle at 15% 5%, #ffe1eb 0, transparent 40%),
              radial-gradient(circle at 90% 95%, #fff0d9 0, transparent 40%), var(--bg);
  color: var(--ink);
  font-family: 'Gowun Dodum', system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }
#app { max-width: 480px; margin: 0 auto; height: 100dvh; position: relative; overflow: hidden; }

.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column; gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; }
.screen.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

h1, h2, h3, .btn, .jua, .tool, .chip, .pill, .diff, .steps { font-family: 'Jua', sans-serif; font-weight: 400; }
h1 { font-size: 44px; line-height: 1.1; color: var(--choco); }
h2 { font-size: 26px; color: var(--choco); }
h3 { font-size: 20px; color: var(--choco); }
b { color: var(--choco); }
.center { text-align: center; }
.right { text-align: right; display: block; }
.sub { color: var(--sub); font-size: 15px; line-height: 1.5; }
.tiny { color: var(--sub); font-size: 13px; line-height: 1.45; }
.eyebrow { color: var(--pink-d); font-family: 'Jua', sans-serif; font-size: 15px; }
.pill { display: inline-block; background: #fff; border: 2px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 14px; color: var(--choco); }

.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; }
.grow { flex: 1; }

.btn {
  appearance: none; border: 0; border-radius: 16px;
  padding: 14px 18px; font-size: 19px;
  background: var(--choco); color: #fff;
  box-shadow: 0 4px 0 var(--choco-d);
  cursor: pointer; width: 100%;
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--choco-d); }
.btn.pink { background: var(--pink); box-shadow: 0 4px 0 var(--pink-d); }
.btn.pink:active { box-shadow: 0 1px 0 var(--pink-d); }
.btn.ghost { background: #fff; color: var(--choco); box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line); }
.btn.ghost:active { box-shadow: 0 1px 0 var(--line); }
.btn.sm { padding: 10px 12px; font-size: 15px; width: auto; }
.btn.big { padding: 18px; font-size: 24px; }
.btn:disabled { opacity: .45; pointer-events: none; }

/* 타이틀 */
.title-top { text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; padding-top: 8px; }
.cv-box { flex: 1; min-height: 180px; position: relative; }
.cv-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cv-box.fixed { flex: none; height: 230px; }
.cv-box.tall { flex: none; height: min(58vh, 460px); }
#cv-recv { cursor: pointer; touch-action: manipulation; }

/* 만들기 HUD */
.hud { display: flex; flex-direction: column; gap: 8px; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#hud-num { font-size: 22px; color: var(--choco); }
.diff { color: #f2a33d; font-size: 18px; letter-spacing: 1px; }
.steps { list-style: none; display: flex; gap: 4px; }
.steps li {
  flex: 1; text-align: center; font-size: 13px; padding: 6px 0;
  border-radius: 10px; background: #fff; color: #c9b2aa; border: 2px solid var(--line);
}
.steps li.done { background: #e9f7f1; color: var(--mint); border-color: #bfe8d8; }
.steps li.now { background: var(--choco); color: #fff; border-color: var(--choco); }
.stage-wrap {
  flex: 1; min-height: 0; position: relative;
  border-radius: 22px; overflow: hidden; border: 2px solid var(--line); background: #fff6ef;
}
#cv-stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hint { font-size: 14px; line-height: 1.45; text-align: center; min-height: 2.9em; color: var(--ink); }
.controls { display: flex; flex-direction: column; gap: 8px; }
.controls:empty { display: none; }

.chips { display: flex; gap: 4px; justify-content: center; }
.chip {
  border: 2px solid var(--line); background: #fff; border-radius: 999px;
  padding: 7px 8px; font-size: 14px; color: var(--ink); display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
  flex: 1; justify-content: center; white-space: nowrap; min-width: 0;
}
.chip i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.1); flex: none; }
.chip.on { border-color: var(--choco); background: #fff3ea; }
.chip:disabled { opacity: .5; }

.tools { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.tool {
  border: 2px solid var(--line); background: #fff; border-radius: 12px;
  padding: 6px 0 4px; display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer; color: var(--ink);
}
.tool span { font-size: 20px; line-height: 1.1; }
.tool small { font-size: 11px; white-space: nowrap; }
.tool.on { border-color: var(--choco); background: #fff3ea; }
.tool:disabled { opacity: .45; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; min-height: 30px; }
.swatches.small { justify-content: center; }
.sw {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer;
}
.sw.lg { width: 38px; height: 38px; }
.sw.on { box-shadow: 0 0 0 3px var(--choco); }

/* 목표 개수 */
.goal-picker { display: flex; align-items: center; justify-content: center; gap: 22px; }
.round {
  width: 54px; height: 54px; border-radius: 50%; border: 2px solid var(--line); background: #fff;
  font-family: 'Jua', sans-serif; font-size: 30px; color: var(--choco); box-shadow: 0 4px 0 var(--line); cursor: pointer;
}
.round:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.round:disabled { opacity: .35; }
.goal-num { display: flex; align-items: baseline; gap: 4px; min-width: 96px; justify-content: center; }
.goal-num b { font-family: 'Jua', sans-serif; font-weight: 400; font-size: 60px; line-height: 1; }
.goal-num span { font-family: 'Jua', sans-serif; font-size: 22px; color: var(--choco); }
.goal-info { background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 10px 12px; text-align: center; font-size: 14px; line-height: 1.6; }
.goal-info .lbl { font-family: 'Jua', sans-serif; font-size: 18px; color: var(--pink-d); }
.goal-info .st { color: #f2a33d; letter-spacing: 1px; }

.tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.warn { color: var(--danger); }
.btn.shape { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px; font-size: 20px; }
.btn.shape span { font-size: 30px; line-height: 1.1; }
.linkbtn { background: none; border: 0; color: var(--sub); font: inherit; font-size: 13px; text-decoration: underline; padding: 4px; cursor: pointer; }

/* 결과 */
.grades { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grades li { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; font-family: 'Jua', sans-serif; font-size: 15px; color: var(--sub); }
.grades li.pf { color: #c47a1a; border-color: #ffd36e; background: #fffaf0; }

/* 포장 */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-family: 'Jua', sans-serif; font-size: 16px; color: var(--choco); }
.field.two { flex-direction: row; gap: 10px; }
.field.two > div { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
input, textarea {
  font: inherit; font-size: 16px; color: var(--ink);
  border: 2px solid var(--line); border-radius: 14px; padding: 12px; background: #fff; width: 100%;
  outline: none; resize: none;
}
input:focus, textarea:focus { border-color: var(--pink); }

.cert { background: #fffdf7; border: 2px dashed #f2cf73; border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.cert h3 { text-align: center; font-size: 18px; }
.cert-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cert-grid div { background: #fff; border-radius: 12px; padding: 8px 4px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.cert-grid b { font-family: 'Jua', sans-serif; font-weight: 400; font-size: 17px; color: var(--choco); }
.cert-grid span { font-size: 12px; color: var(--sub); }
.cert-c { text-align: center; font-size: 14px; color: var(--ink); }

/* 공유 */
.share-top { display: flex; flex-direction: column; gap: 8px; align-items: center; padding: 24px 0 8px; }
.big-emoji { font-size: 64px; }
.linkbox { font-size: 13px; color: var(--sub); text-overflow: ellipsis; }

/* 받는 화면 */
.letter {
  background: #fff; border-radius: 18px; padding: 20px 18px; margin: 6px 0 10px;
  box-shadow: 0 6px 0 var(--line);
  background-image: repeating-linear-gradient(transparent 0 29px, #fbe3ea 29px 30px);
  line-height: 30px;
}
.letter .to { font-family: 'Jua', sans-serif; font-size: 18px; color: var(--choco); }
.letter .msg { white-space: pre-wrap; word-break: break-word; font-size: 16px; margin: 6px 0; -webkit-user-select: text; user-select: text; }
.letter .from { font-family: 'Jua', sans-serif; font-size: 17px; color: var(--choco); text-align: right; }
#rv-open { display: flex; flex-direction: column; gap: 12px; padding-bottom: 12px; }
#rv-open[hidden] { display: none; }

/* 모달 & 토스트 */
.modal {
  position: absolute; inset: 0; background: rgba(74,45,34,.4);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal.show { display: flex; animation: fade .18s ease-out; }
.modal-card {
  background: #fff; border-radius: 22px; padding: 22px 18px 18px; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: 0 10px 0 rgba(74,45,34,.15); animation: pop .22s ease-out;
  max-height: 90%; overflow-y: auto;
}
#modal-body { display: flex; flex-direction: column; gap: 8px; font-size: 15px; line-height: 1.5; }
.notes { text-align: left; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.pep-detail canvas { width: 100%; height: 320px; display: block; }

.toast {
  position: absolute; left: 50%; top: 18%; transform: translate(-50%, 0) scale(.8);
  background: var(--choco); color: #fff; font-family: 'Jua', sans-serif; font-size: 22px;
  padding: 10px 20px; border-radius: 22px; opacity: 0; pointer-events: none; z-index: 60;
  width: max-content; max-width: 88%; text-align: center; line-height: 1.3;
  box-shadow: 0 4px 0 var(--choco-d);
}
.toast.show { animation: toast 1.4s ease-out forwards; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(.8); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  25% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(1); }
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-height: 640px) {
  h1 { font-size: 36px; }
  .hint { font-size: 13px; min-height: 2.6em; }
  .btn.big { padding: 14px; font-size: 21px; }
}

/* 빼빼로함 */
.card { background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.card h3 { font-size: 17px; }
.warn-card { border-color: #f2cf73; background: #fffdf5; }
.giftlist { display: flex; flex-direction: column; gap: 8px; }
.gift-item {
  display: flex; align-items: center; gap: 10px; background: #fff; border: 2px solid var(--line); border-radius: 16px;
  padding: 12px; cursor: pointer; text-align: left; font: inherit; color: var(--ink); width: 100%;
}
.gift-item .gi-emoji { font-size: 28px; }
.gift-item .gi-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.gift-item .gi-from { font-family: 'Jua', sans-serif; font-size: 17px; color: var(--choco); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gift-item .gi-meta { font-size: 13px; color: var(--sub); }
.gift-item .gi-del { background: none; border: 0; color: #c9b2aa; font-size: 18px; padding: 6px; cursor: pointer; }
.empty { text-align: center; color: var(--sub); padding: 30px 10px; background: #fff; border: 2px dashed var(--line); border-radius: 18px; line-height: 1.6; }

.gift-item.new { border-color: var(--pink); background: #fff7fa; }
.gift-item.seen { opacity: .72; }
.badge { display: inline-block; background: var(--danger); color: #fff; font-size: 11px; border-radius: 999px; padding: 1px 7px; margin-right: 6px; vertical-align: 2px; font-family: 'Jua', sans-serif; }
#mb-tabs .chip { flex: none; }
