/*
VOICE  : 아이 놀이책. 굵은 갈색 테두리 + 색종이 + 크레파스.
IDEA   : 딸내미 책상 위 색종이 놀이 — 버튼·그림이 테두리 굵은 종이 스티커처럼 붙어 있음.
PICTURE: 찾기 화면은 두 장의 종이 그림이 화면을 꽉 채움. 처음 화면은 색종이 카드 3장.
COLOUR : 따뜻한 종이색 바탕, 잉크 갈색, 색종이(노랑·주황·민트·연보라·분홍).
TYPE   : 주아(Jua) 하나, 크게.
*/
@font-face {
  font-family: 'Jua';
  src: url('../fonts/jua-sub.woff2') format('woff2');
  font-display: swap;
}
:root {
  --bg: #fff6e5;
  --ink: #3b2a20;
  --sub: #8a6a52;
  --paper: #fffdf8;
  --yellow: #ffd54a;
  --orange: #ff9a3c;
  --mint: #5fd0b0;
  --lilac: #a98bff;
  --pink: #ff7aa2;
  --green: #45c46a;
  --b: clamp(46px, 4.6vmin + 22px, 66px);
  --bw: 3px;
  --sh: 0 4px 0 var(--ink);
  --gap: clamp(8px, 1.6vmin, 14px);
  font-family: 'Jua', 'Apple SD Gothic Neo', 'Noto Sans KR', system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; min-width: 0; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  background-image: radial-gradient(rgba(59, 42, 32, .07) 1.5px, transparent 1.7px);
  background-size: 22px 22px;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
svg.i { width: 62%; height: 62%; flex: none; }

.screen {
  position: fixed;
  inset: 0;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* 종이 스티커 버튼 */
.btn {
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  box-shadow: var(--sh);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .08s, box-shadow .08s;
}
.btn:active, .tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.sq { width: var(--b); height: var(--b); flex: none; border-radius: 16px; }
.btn.sq.big { --b: clamp(66px, 11vmin, 90px); border-radius: 22px; }
.btn.chip { height: 48px; padding: 0 16px 0 10px; border-radius: 999px; gap: 6px; font-size: 19px; white-space: nowrap; }
.btn.chip svg.i { width: 32px; height: 32px; }
.btn.ok { background: var(--green); color: #fff; }
.btn.on { background: var(--yellow); transform: translateY(-3px); box-shadow: 0 7px 0 var(--ink); }
.btn:disabled { opacity: .4; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- 처음 화면 ---------- */
#home { justify-content: center; }
.home-top { position: absolute; top: max(12px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); right: max(14px, env(safe-area-inset-right)); display: flex; justify-content: space-between; align-items: center; z-index: 1; }
.home-top .btn.sq { --b: 50px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: clamp(18px, 4vmin, 40px); }
.logo { text-align: center; display: flex; flex-direction: column; align-items: center; }
.logo h1 { margin: 0; font-weight: 400; font-size: clamp(54px, 11vmin, 96px); line-height: 1; letter-spacing: -1px; color: var(--ink); text-shadow: 0 5px 0 var(--yellow); }
.tape {
  position: relative;
  z-index: 1;
  margin-bottom: -6px;
  transform: rotate(-4deg);
  background: var(--pink);
  color: #fff;
  font-size: clamp(18px, 3.2vmin, 26px);
  padding: 2px 16px 4px;
  border: var(--bw) solid var(--ink);
  border-radius: 8px;
  white-space: nowrap;
}
.tiles { display: flex; gap: clamp(14px, 3vmin, 30px); justify-content: center; }
.tile {
  width: clamp(150px, 28vmin, 250px);
  aspect-ratio: 1 / 1.08;
  border: 4px solid var(--ink);
  border-radius: 28px;
  box-shadow: 0 7px 0 var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: clamp(26px, 4.4vmin, 36px);
  color: var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.tile:nth-child(1) { transform: rotate(-3deg); }
.tile:nth-child(2) { transform: rotate(1.5deg) translateY(-6px); }
.tile:nth-child(3) { transform: rotate(-1deg); }
.tile .art { width: 62%; height: 58%; }
.tile b { font-weight: 400; background: var(--paper); border: var(--bw) solid var(--ink); border-radius: 999px; padding: 0 18px 2px; }
.c-orange { background: var(--orange); }
.c-mint { background: var(--mint); }
.c-lilac { background: var(--lilac); }
.levels { display: flex; gap: 10px; }
.levels button {
  height: 52px;
  padding: 0 16px;
  border-radius: 999px;
  border: var(--bw) solid var(--ink);
  background: var(--paper);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 19px;
  color: var(--sub);
  box-shadow: 0 3px 0 var(--ink);
}
.levels .dots { display: flex; gap: 3px; }
.levels i { width: 11px; height: 11px; border-radius: 50%; background: #e8d6bd; border: 2px solid #c9b293; }
.levels button.on { background: var(--yellow); color: var(--ink); transform: translateY(-2px); box-shadow: 0 5px 0 var(--ink); }
.levels button.on i { background: var(--pink); border-color: var(--ink); }

@media (orientation: portrait) {
  .tiles { flex-direction: column; gap: 16px; }
  .tile { width: min(82vw, 380px); aspect-ratio: auto; height: clamp(92px, 13.5vh, 140px); flex-direction: row; justify-content: flex-start; padding: 0 22px; gap: 14px; border-radius: 24px; }
  .tile .art { width: auto; height: 78%; aspect-ratio: 1; }
  .tile:nth-child(2) { transform: rotate(1deg); }
  .levels { gap: 6px; }
  .levels button { padding: 0 10px; font-size: 16px; height: 46px; gap: 5px; }
  .levels i { width: 8px; height: 8px; border-width: 1.5px; }
}

/* ---------- 상단 막대 ---------- */
.bar { display: flex; align-items: center; gap: var(--gap); flex: none; }
.bar h2 { margin: 0; flex: 1; text-align: center; font-weight: 400; font-size: clamp(24px, 4vmin, 32px); }
.bar-gap { flex: 1; }
.stage { position: relative; flex: 1; min-height: 0; }
.stage canvas, .pic {
  border: var(--bw) solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 5px 0 var(--ink);
  background: #fff;
  touch-action: none;
}
.stage > canvas { position: absolute; box-sizing: content-box; }

/* ---------- 그리기 ---------- */
#draw { flex-direction: row; }
#drawBar { flex: none; display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: var(--gap); padding: 2px 4px 8px; }
#drawBar .colors, #drawBar .tools { display: grid; grid-template-columns: repeat(2, var(--b)); gap: var(--gap); }
.swatch { width: var(--b); height: var(--b); border-radius: 50%; border: var(--bw) solid var(--ink); box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .18), 0 3px 0 var(--ink); transition: transform .1s; }
.swatch.on { transform: translateY(-4px) scale(1.08); box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .18), 0 0 0 4px var(--paper), 0 0 0 7px var(--ink); }
.sz { display: block; border-radius: 50%; background: var(--ink); }
.sz.s1 { width: 12px; height: 12px; }
.sz.s2 { width: 26px; height: 26px; }
.paper-chip { display: block; width: 56%; height: 56%; border-radius: 6px; border: var(--bw) solid var(--ink); transform: rotate(-6deg); }
#drawStage canvas { cursor: crosshair; }
@media (orientation: portrait) {
  #draw { flex-direction: column; }
  #drawBar { --b: min(50px, calc((100vw - 24px - 42px) / 8)); --gap: 6px; flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 4px 0 6px; }
  #drawBar .colors { grid-template-columns: repeat(8, var(--b)); order: -1; width: 100%; justify-content: center; }
  #drawBar .tools { grid-template-columns: repeat(6, var(--b)); }
}

/* ---------- 고르기 ---------- */
.grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(140px, 24vmin, 230px), 1fr));
  gap: clamp(14px, 2.4vmin, 22px);
  align-content: start;
  padding: 10px 6px 24px;
  -webkit-overflow-scrolling: touch;
}
.card {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  border: var(--bw) solid var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  background: #fff;
  overflow: hidden;
  display: grid;
  place-items: center;
}
.card:nth-child(3n+1) { transform: rotate(-1.2deg); }
.card:nth-child(3n+2) { transform: rotate(.8deg); }
.card:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.card canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.card.make { gap: 4px; font-size: 20px; align-content: center; }
.card.make svg { width: 46%; height: 52%; }
.card.make.c-orange { background: var(--orange); }
.card.make.c-lilac { background: var(--lilac); }
.card .del {
  position: absolute;
  top: 6px;
  right: 6px;
  height: 32px;
  min-width: 32px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--paper);
  border: 2px solid var(--ink);
  font-size: 15px;
  display: grid;
  place-items: center;
}
.card .del.armed { background: #e53935; color: #fff; }
.card .mine { position: absolute; left: 6px; top: 6px; background: var(--yellow); border: 2px solid var(--ink); border-radius: 999px; padding: 0 9px 1px; font-size: 14px; }

/* ---------- 찾기 ---------- */
.progress { flex: 1; display: flex; justify-content: center; }
.progress .slots { display: flex; gap: 4px; padding: 5px 12px; background: var(--paper); border: var(--bw) solid var(--ink); border-radius: 999px; box-shadow: var(--sh); }
.progress svg { width: clamp(30px, 5vmin, 42px); height: clamp(30px, 5vmin, 42px); filter: grayscale(1) opacity(.28); transition: filter .3s; }
.progress svg.got { filter: none; animation: popin .5s; }
@keyframes popin { 0% { transform: scale(.3); } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
.btn.hint { background: #fff3a6; }
.pic { position: absolute; overflow: hidden; }
.pic canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------- 아빠 ---------- */
.edit-bar { flex-wrap: wrap; }
.seg { flex: 1; display: flex; justify-content: center; gap: 0; }
.seg button { height: 48px; padding: 0 14px 0 8px; display: inline-flex; align-items: center; gap: 4px; font-size: 18px; border: var(--bw) solid var(--ink); background: var(--paper); margin-left: calc(var(--bw) * -1); box-shadow: 0 4px 0 var(--ink); }
.seg button:first-child { border-radius: 999px 0 0 999px; margin-left: 0; }
.seg button:last-child { border-radius: 0 999px 999px 0; }
.seg button svg.i { width: 30px; height: 30px; }
.seg button.on { background: var(--yellow); }
.btn.chip.ok b { background: #fff; color: var(--ink); border: 2px solid var(--ink); border-radius: 999px; min-width: 30px; height: 30px; display: grid; place-items: center; font-weight: 400; }
.edit-sub { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; flex: none; min-height: 50px; align-items: center; }
.edit-sub .swatch { --b: 42px; }
.edit-sub .stk { width: 50px; height: 50px; border-radius: 14px; background: var(--paper); border: var(--bw) solid var(--ink); box-shadow: 0 3px 0 var(--ink); display: grid; place-items: center; overflow: hidden; }
.edit-sub .stk canvas { width: 100%; height: 100%; }
.edit-sub .stk.on { background: var(--yellow); transform: translateY(-3px); }
.edit-tip { margin: 0; text-align: center; color: var(--sub); font-size: 16px; flex: none; }
@media (max-width: 600px) {
  .seg { order: 9; flex-basis: 100%; }
  .edit-bar .bar-gap { display: none; }
  .btn.chip { font-size: 17px; }
  .edit-bar > .btn.chip { margin-left: auto; }
}

/* ---------- 넘겨주기 ---------- */
#handoff { align-items: center; justify-content: center; }
.handoff { text-align: center; display: flex; flex-direction: column; align-items: center; }
.handoff .gift { width: clamp(120px, 26vmin, 190px); height: clamp(120px, 26vmin, 190px); animation: bob 1.4s ease-in-out infinite; }
.handoff h2 { font-weight: 400; font-size: clamp(40px, 8vmin, 64px); margin: 4px 0; }
.handoff p { font-size: clamp(22px, 4vmin, 30px); margin: 0 0 26px; color: var(--sub); }
.handoff p b { color: var(--pink); font-size: 1.5em; font-weight: 400; }
.btn.go { width: clamp(110px, 22vmin, 150px); height: clamp(110px, 22vmin, 150px); border-radius: 50%; border-width: 4px; box-shadow: 0 8px 0 var(--ink); }
@keyframes bob { 50% { transform: translateY(-12px) rotate(4deg); } }

/* ---------- 축하 ---------- */
.overlay { position: fixed; inset: 0; background: rgba(255, 246, 229, .88); display: grid; place-items: center; z-index: 10; padding: 16px; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.win-card { position: relative; text-align: center; background: var(--paper); border: 4px solid var(--ink); border-radius: 32px; padding: clamp(18px, 4vmin, 36px) clamp(22px, 6vmin, 56px); box-shadow: 0 10px 0 var(--ink); animation: popin .5s; transform: rotate(-1deg); }
.win-stars { display: flex; justify-content: center; align-items: flex-end; gap: 4px; }
.win-stars svg { width: clamp(56px, 11vmin, 84px); height: clamp(56px, 11vmin, 84px); animation: popin .6s backwards; }
.win-stars svg:nth-child(2) { width: clamp(72px, 14vmin, 108px); height: clamp(72px, 14vmin, 108px); animation-delay: .15s; }
.win-stars svg:nth-child(3) { animation-delay: .3s; }
.win-card h2 { font-weight: 400; font-size: clamp(40px, 8vmin, 64px); margin: 2px 0 6px; color: var(--pink); text-shadow: 0 3px 0 var(--ink); }
.win-next { display: flex; justify-content: center; gap: 6px; min-height: 22px; margin-bottom: 18px; align-items: center; color: var(--sub); font-size: 18px; }
.win-next i { width: 16px; height: 16px; border-radius: 50%; background: var(--pink); border: 2px solid var(--ink); display: inline-block; }
.win-btns { display: flex; gap: 16px; justify-content: center; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
