/* 안녕 ANNYEONG — 웜 아이보리 + 캔디 팔레트.
   레퍼런스(순백 배경·파스텔 얼굴·검정 잉크·검정 말풍선)와 의도적 차별화:
   버터빛 아이보리 바탕 + 콘페티 점 + 네이비 잉크 + 노랑 말풍선 + 고채도 캔디 얼굴 */
:root {
  --bg: #FAF3E6;
  --bg-top: #FFFCF4;
  --ink: #262450;
  --paper: #FFFFFF;
  --cream: #FFF6E8;
  --sun: #FFD43B;
  --tangerine: #FF8A3D;
  --muted: #A89E8C;
  --line: #EDE4D2;
  --chip: #F4ECDA;
  --like: #E5484D;
  --like-bg: #FFE9E9;
  --shadow: 0 8px 26px rgba(43, 40, 87, 0.24);
  --pill: 999px;
  --font-hand: 'Gaegu', 'Comic Sans MS', cursive;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  position: fixed; inset: 0; width: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font-ui); overflow: hidden;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font-family: inherit; border: 0; background: none; cursor: pointer; color: inherit; }

/* ---------- 월드 (아이보리 + 콘페티) ---------- */
#world {
  position: absolute; inset: 0; overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, var(--bg-top) 0%, var(--bg) 58%);
}
#world::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(rgba(255, 138, 61, 0.22) 2px, transparent 2.7px),
    radial-gradient(rgba(116, 192, 252, 0.2) 2px, transparent 2.7px),
    radial-gradient(rgba(247, 131, 172, 0.18) 2px, transparent 2.7px);
  background-size: 260px 260px, 330px 330px, 290px 290px;
  background-position: 0 0, 140px 90px, 60px 200px;
}
#faces { position: absolute; inset: 0; }
.face {
  position: absolute; left: 0; top: 0;
  will-change: transform;
  user-select: none; -webkit-user-select: none;
  touch-action: none; cursor: grab;
}
.face.grabbed { z-index: 10; scale: 1.04; transition: scale 0.15s; cursor: grabbing; }
.face:not(.grabbed) { transition: scale 0.2s; }
.face > img, .face > canvas {
  display: block; width: 100%; height: 100%;
  pointer-events: none; -webkit-touch-callout: none;
}
.face.pop { animation: facePop 0.7s cubic-bezier(0.3, 1.35, 0.55, 1); }
@keyframes facePop {
  0% { opacity: 0; scale: 0.35; translate: 0 44px; }
  55% { opacity: 1; }
  100% { opacity: 1; scale: 1; translate: 0 0; }
}

.puff { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; z-index: 4; }
.puffDot {
  position: absolute; left: 0; top: 0; border-radius: 50%;
  background: rgba(202, 188, 152, 0.5);
  transform: translate(-50%, -50%);
  opacity: 0;
  animation: puffOut 0.85s ease-out forwards;
}
.puffDot.alt { background: rgba(255, 255, 255, 0.85); }
@keyframes puffOut {
  0% { opacity: 0.9; transform: translate(-50%, -50%) scale(0.4); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.2); }
}
.face.reported { transition: opacity 0.6s; opacity: 0; pointer-events: none; }

.bubble {
  position: absolute; bottom: calc(100% + 8px); left: 50%;
  background: var(--sun); color: var(--ink);
  font-family: var(--font-hand); font-size: 17px; line-height: 1;
  padding: 7px 14px 8px; border-radius: var(--pill); white-space: nowrap;
  box-shadow: 0 3px 10px rgba(90, 70, 20, 0.22);
  transform: translateX(-50%) scale(0); transform-origin: bottom center;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none; z-index: 3;
}
.bubble::after {
  content: ''; position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--sun); border-bottom: 0;
}
.bubble.show { transform: translateX(-50%) scale(1); }

.brand {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 18px;
  z-index: 5; pointer-events: none; color: var(--ink);
}
.brand h1 { margin: 0; font-family: var(--font-hand); font-size: 30px; line-height: 1.05; }
.brand h1 span { font-size: 15px; letter-spacing: 0.18em; vertical-align: middle; margin-left: 6px; color: var(--tangerine); }
.brand h1 .badge {
  font-size: 10px; letter-spacing: 0.06em; background: var(--ink); color: var(--cream);
  border-radius: 4px; padding: 2px 5px; margin-left: 6px; font-family: var(--font-ui);
}
.brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); letter-spacing: 0.04em; }

#drawBtn {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: max(22px, env(safe-area-inset-bottom)); z-index: 5;
  background: var(--ink); color: var(--cream);
  font-size: 16.5px; font-weight: 700; padding: 15px 26px;
  border-radius: var(--pill); box-shadow: var(--shadow);
  transition: transform 0.15s;
}
#drawBtn:active { transform: translateX(-50%) scale(0.94); }

/* ---------- 그리기 모드 (종이 이젤) ---------- */
#drawMode { position: absolute; inset: 0; background: #FFFDF8; z-index: 20; display: flex; flex-direction: column; }
#drawMode header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
}
#drawMode header b { font-family: var(--font-hand); font-size: 24px; }
#backBtn { font-size: 22px; padding: 6px 12px; }
#uploadBtn { background: var(--ink); color: var(--cream); font-weight: 700; font-size: 15px; padding: 10px 18px; border-radius: var(--pill); }

.chips { display: flex; gap: 10px; justify-content: center; padding: 6px 14px; flex-wrap: wrap; }
.shapeChip {
  width: 54px; height: 54px; border-radius: 16px; background: var(--chip);
  border: 2px solid transparent; display: flex; align-items: center; justify-content: center; padding: 0;
}
.shapeChip canvas { width: 44px; height: 44px; }
.shapeChip.sel { border-color: var(--ink); background: #fff; }
.colorChip { width: 32px; height: 32px; border-radius: 50%; border: 2.5px solid transparent; padding: 0; }
.colorChip.sel { border-color: var(--ink); }

#canvasWrap { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; min-height: 0; padding: 8px; overflow: hidden; }
#canvasStack { position: relative; border-radius: 20px; background: var(--paper); box-shadow: inset 0 0 0 1.5px var(--line); will-change: transform; }
#canvasStack canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 20px; }
#inkCanvas { touch-action: none; cursor: crosshair; }

.tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; padding: 10px 14px calc(14px + env(safe-area-inset-bottom)); }
.tools button { background: var(--chip); border-radius: var(--pill); padding: 10px 16px; font-size: 14.5px; font-weight: 600; }
.tools button.sel { background: var(--ink); color: var(--cream); }
#sizeChips { display: flex; gap: 6px; align-items: center; }
.sizeChip { width: 34px; height: 34px; border-radius: 50%; background: var(--chip); display: flex; align-items: center; justify-content: center; padding: 0; }
.sizeChip i { display: block; border-radius: 50%; background: var(--ink); }
.sizeChip.sel { background: var(--ink); }
.sizeChip.sel i { background: var(--paper); }

/* ---------- 얼굴 패널 ---------- */
#backdrop { position: absolute; inset: 0; background: rgba(43, 40, 87, 0.32); z-index: 30; }
#facePanel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--paper); border-radius: 26px 26px 0 0;
  box-shadow: 0 -10px 40px rgba(43, 40, 87, 0.28);
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  animation: sheetUp 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes sheetUp { from { transform: translateY(60%); } to { transform: translateY(0); } }
.panelTop { display: flex; align-items: center; gap: 16px; }
#panelImg { width: 96px; height: 96px; }
.panelGreet { font-family: var(--font-hand); font-size: 28px; line-height: 1.1; }
.panelLang { font-size: 12px; color: var(--muted); letter-spacing: 0.08em; margin-top: 3px; }
.panelRow { display: flex; gap: 10px; margin-top: 16px; align-items: center; }
#likeBtn { background: var(--like-bg); color: var(--like); font-size: 16px; font-weight: 700; padding: 11px 20px; border-radius: var(--pill); transition: transform 0.12s; }
#likeBtn:active { transform: scale(0.92); }
#reportBtn { margin-left: auto; color: var(--muted); font-size: 12.5px; text-decoration: underline; }
.msgRow { display: flex; gap: 8px; margin-top: 12px; }
#msgInput {
  flex: 1; min-width: 0; border: 1.5px solid var(--line); border-radius: var(--pill);
  padding: 11px 16px; font-size: 16px; font-family: inherit; outline: none; background: #FBF6EA;
}
#msgInput:focus { border-color: var(--ink); }
#msgSend { background: var(--ink); color: #fff; font-weight: 700; padding: 11px 18px; border-radius: var(--pill); }

/* ---------- 수신함 ---------- */
#inboxBtn {
  position: absolute; top: max(14px, env(safe-area-inset-top)); right: 16px; z-index: 5;
  background: #fff; border-radius: var(--pill); padding: 10px 14px; font-size: 18px;
  box-shadow: 0 4px 16px rgba(43, 40, 87, 0.16); transition: transform 0.15s;
}
#inboxBtn:active { transform: scale(0.92); }
#inboxBadge {
  position: absolute; top: -4px; right: -4px;
  background: var(--like); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: var(--pill); min-width: 18px; height: 18px; line-height: 18px;
  text-align: center; padding: 0 4px;
}
#inboxPanel {
  position: absolute; z-index: 31;
  top: calc(max(14px, env(safe-area-inset-top)) + 52px); right: 16px;
  width: min(320px, 86vw); max-height: 56vh;
  display: flex; flex-direction: column;
  background: rgba(255, 252, 244, 0.78);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 18px; box-shadow: 0 12px 36px rgba(43, 40, 87, 0.22);
  padding: 12px 12px 10px;
  transform-origin: top right;
  animation: inboxIn 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes inboxIn { from { opacity: 0; scale: 0.9; } to { opacity: 1; scale: 1; } }
#inboxPanel > b { font-family: var(--font-hand); font-size: 20px; padding: 0 4px; }
#inboxList { overflow-y: auto; overscroll-behavior: contain; margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.fbItem { display: flex; gap: 9px; align-items: flex-start; background: rgba(255, 255, 255, 0.6); border-radius: 12px; padding: 8px 10px; }
.fbItem img { width: 30px; height: 30px; flex-shrink: 0; }
.fbItem .txt { font-size: 13.5px; line-height: 1.35; word-break: break-word; }
.fbItem.like .txt { color: var(--like); font-weight: 700; }
.fbItem .time { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.fbEmpty { color: var(--muted); font-size: 13.5px; padding: 8px 4px 10px; }

/* ---------- 공통 ---------- */
#toast {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--cream); padding: 11px 20px; border-radius: var(--pill);
  box-shadow: 0 6px 22px rgba(43, 40, 87, 0.3);
  font-size: 14.5px; z-index: 50; opacity: 0; transition: opacity 0.25s;
  pointer-events: none; white-space: nowrap; max-width: 92vw;
}
#toast.show { opacity: 1; }

.heartFly { position: absolute; font-size: 22px; z-index: 40; pointer-events: none; animation: heartFly 1s ease-out forwards; }
@keyframes heartFly {
  from { opacity: 1; transform: translate(-50%, 0) scale(0.6); }
  to { opacity: 0; transform: translate(-50%, -90px) scale(1.4); }
}
