:root {
  --bg: #fff7f2;
  --card: #ffffff;
  --ink: #4b2c3f;
  --ink-soft: #9a8089;
  --line: #f3e3dc;
  --peach: #fec9b8;
  --yellow: #ffd785;
  --yellow-deep: #e9a93b;
  --green: #cfeed6;
  --blue: #d9ebff;
  --purple: #e6d8ff;
  --good: #58b98a;
  --bad: #ef5b6b;
  --wall: #5a3d4a;
  --shadow: 0 2px 0 #ecd9d0, 0 6px 14px rgba(122, 78, 60, .10);
  --text: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --display: "Jua", var(--text);
}
/* 언어별 글꼴: Jua에는 일본어·중국어 글자가 없다 (글꼴 파일은 i18n.js가 필요할 때만 받는다) */
html[lang="ja"] { --text: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif; --display: "M PLUS Rounded 1c", var(--text); }
html[lang="zh"] { --text: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif; --display: "ZCOOL KuaiLe", var(--text); }
html[lang="ja"] h1, html[lang="ja"] h2, html[lang="ja"] h3 { font-weight: 800; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--text);
  -webkit-user-select: none; user-select: none; overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
img { -webkit-user-drag: none; }
svg.ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.cat { display: block; object-fit: contain; }
#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; }
#app.tabbed { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }

/* 공통 부품 */
.topbar { display: flex; align-items: center; gap: 8px; min-height: 46px; margin-bottom: 8px; }
.topbar h2 { flex: 1; margin: 0; font: 400 21px var(--display); text-align: center; }
.topbar .side { width: 92px; display: flex; gap: 6px; }
.topbar .side.right { justify-content: flex-end; }
.iconbtn { width: 44px; height: 44px; border-radius: 15px; background: var(--card); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; }
.iconbtn:active, .tool:active, .pillbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #ecd9d0; }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 15px 18px; border-radius: 999px; font: 400 19px var(--display);
  background: linear-gradient(#ffe39a, #ffcb57); color: #5a3a12; box-shadow: inset 0 2px 0 rgba(255, 255, 255, .6), 0 4px 0 var(--yellow-deep), 0 8px 14px rgba(233, 169, 59, .25); }
.btn:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .6), 0 1px 0 var(--yellow-deep); }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: 0 3px 0 #ead6cc, 0 6px 12px rgba(122, 78, 60, .08); }
.btn.small { padding: 10px 14px; font-size: 16px; }
.btn small { font-size: 14px; opacity: .75; }
.muted { color: var(--ink-soft); }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.pill svg.ic { width: 18px; height: 18px; }
.pill img { width: 20px; height: 20px; }
.stars { display: inline-flex; gap: 1px; }
.stars i { width: 1em; height: 1em; background: #e6d7d0; clip-path: polygon(50% 0, 62% 35%, 100% 38%, 71% 60%, 81% 97%, 50% 76%, 19% 97%, 29% 60%, 0 38%, 38% 35%); }
.stars i.on { background: #ffbe3b; }

/* 하단 탭 */
.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 520px; display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(255, 255, 255, .96); border-radius: 22px 22px 0 0; box-shadow: 0 -4px 18px rgba(122, 78, 60, .12); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); z-index: 5; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; border-radius: 14px; font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.tab img, .tab svg.ic { width: 34px; height: 34px; }
.tab.on { color: var(--ink); background: #fff1cf; }

/* 홈 */
.home { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.hero { position: relative; margin: calc(-12px - env(safe-area-inset-top)) -16px 0; height: min(52dvh, 430px); background: linear-gradient(160deg, #ffe9dc, #fff7f2 55%, #e9f5ea) center/cover no-repeat; border-radius: 0 0 28px 28px; overflow: hidden; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255, 247, 242, .82) 0, rgba(255, 247, 242, .35) 38%, rgba(255, 247, 242, 0) 60%); pointer-events: none; }
.hero .logo { position: absolute; z-index: 1; top: calc(22px + env(safe-area-inset-top)); left: 22px; text-align: center; color: #5b2a4e; }
.hero .logo img, .hero .logo svg { width: 46px; height: 46px; display: block; margin: 0 auto -4px; }
.hero .logo h1 { margin: 0; font: 400 54px/1 var(--display); letter-spacing: -1px; }
.hero .logo em { display: block; font-style: normal; font-weight: 800; font-size: 17px; margin-top: 2px; }
.hero .logo p { margin: 8px 0 0; font-size: 13px; font-weight: 600; line-height: 1.4; }
.hero .fallback { position: absolute; right: 18px; bottom: 10px; width: 150px; height: 150px; }
.hero .corner { position: absolute; z-index: 2; top: calc(14px + env(safe-area-inset-top)); right: 14px; display: flex; gap: 8px; }
.card { background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 14px 16px; text-align: left; display: flex; align-items: center; gap: 12px; width: 100%; }
.card .grow { flex: 1; min-width: 0; }
.card b { display: block; font: 400 18px var(--display); margin-bottom: 2px; }
.card span.sub { font-size: 13px; color: var(--ink-soft); }
.card > img, .card > svg.ic { width: 46px; height: 46px; flex: none; }
.badge { display: inline-block; padding: 5px 12px; border-radius: 999px; background: var(--peach); color: #a14a2c; font-size: 13px; font-weight: 800; white-space: nowrap; }
.badge.done { background: var(--green); color: #2c7a55; }
.chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.footnote { margin-top: auto; text-align: center; font-size: 12px; color: var(--ink-soft); padding-top: 4px; }

/* 스테이지 맵 */
.map { position: relative; flex: 1; min-height: 480px; margin: 0 -16px; border-radius: 26px 26px 0 0; overflow: hidden; background: center/cover no-repeat; }
.map.w1 { background-color: #d9f0c9; } .map.w2 { background-color: #ffd9e4; } .map.w3 { background-color: #cfe6c9; }
.map.w4 { background-color: #cfe8ff; } .map.w5 { background-color: #ddd3f7; } .map.w6 { background-color: #e3effb; }
.map.locked::after { content: ""; position: absolute; inset: 0; background: rgba(255, 247, 242, .55); }
.map .title { position: absolute; z-index: 2; top: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; }
.map .title .name { background: rgba(255, 255, 255, .93); border-radius: 18px; padding: 8px 18px; text-align: center; box-shadow: var(--shadow); font: 400 19px/1.25 var(--display); white-space: nowrap; }
.map .title .name small { display: block; font: 700 12px/1.2 "Pretendard", sans-serif; color: var(--ink-soft); }
.map .reward { position: absolute; z-index: 2; right: 12px; bottom: 12px; background: rgba(255, 255, 255, .93); border-radius: 16px; box-shadow: var(--shadow); padding: 6px 10px; display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.map .reward .cat { width: 38px; height: 38px; }
.map .reward.locked .cat { filter: brightness(0) opacity(.2); }
.node { position: absolute; z-index: 1; transform: translate(-50%, -50%); width: 70px; height: 52px; border-radius: 50%; background: #fff; box-shadow: 0 4px 0 #e2cfc6, 0 8px 12px rgba(90, 61, 74, .18);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font: 400 18px/1 var(--display); }
.node .stars { font-size: 11px; margin-top: 3px; }
.node.next { background: linear-gradient(#ffe39a, #ffcb57); box-shadow: 0 4px 0 var(--yellow-deep), 0 0 0 5px rgba(255, 255, 255, .7), 0 8px 14px rgba(90, 61, 74, .22); width: 78px; height: 58px; }
.node.next img, .node.next svg { width: 22px; height: 22px; margin-top: 2px; }
.node:disabled { background: #efe6e2; color: #b8a6a8; box-shadow: 0 3px 0 #d9cbc5; cursor: default; }
.node:not(:disabled):active { transform: translate(-50%, calc(-50% + 3px)); }

/* 컬렉션 */
.cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.catcard { background: var(--card); border: 3px solid transparent; border-radius: 20px; box-shadow: var(--shadow); padding: 10px 6px; text-align: center; }
.catcard .cat { width: 72px; height: 72px; margin: 0 auto 4px; }
.catcard b { display: block; font: 400 16px var(--display); }
.catcard span { font-size: 11px; color: var(--ink-soft); }
.catcard.sel { border-color: var(--yellow); background: #fff8e6; }
.catcard.locked .cat { filter: brightness(0) opacity(.16); }

/* 퍼즐 */
.game { flex: 1; display: flex; flex-direction: column; }
.status { display: flex; justify-content: center; gap: 10px; margin-bottom: 10px; }
.tip { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 10px 14px; font-size: 14px; line-height: 1.45; margin-bottom: 10px; }
.boardwrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 4px 0; }
.frame { width: min(100%, calc(100dvh - 330px)); min-width: 240px; padding: 8px; background: #fff; border-radius: 24px; box-shadow: var(--shadow); }
.board { width: 100%; aspect-ratio: 1; display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr);
  border: 2.5px solid var(--wall); border-radius: 16px; overflow: hidden; touch-action: none; background: var(--wall); }
.cell { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; }
.cell .cat { width: 86%; height: 86%; pointer-events: none; }
.anim .cell.catc .cat { animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.4); } 70% { transform: scale(1.12); } to { transform: scale(1); } }
.cell .x { width: 44%; height: 44%; pointer-events: none; stroke: rgba(75, 44, 63, .78); stroke-width: 3.4; fill: none; stroke-linecap: round; }
.cell .ax { width: 13%; height: 13%; border-radius: 50%; background: rgba(75, 44, 63, .26); pointer-events: none; }
.cell.bad::after { content: ""; position: absolute; inset: 5%; border: 3px solid var(--bad); border-radius: 50%; pointer-events: none; }
.cell.hl::before { content: ""; position: absolute; inset: 0; background: rgba(255, 255, 255, .5); pointer-events: none; }
.cell.tg::after { content: ""; position: absolute; inset: 9%; border: 3px dashed var(--wall); border-radius: 12px; pointer-events: none; }
.anim .cell.tg::after { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.86); } }
.board.dim .cell:not(.hl):not(.tg)::before { content: ""; position: absolute; inset: 0; background: rgba(75, 44, 63, .30); pointer-events: none; }

.hintbox { background: #fff; border-radius: 20px; box-shadow: var(--shadow); padding: 14px; margin-top: 10px; font-size: 14px; line-height: 1.5; }
.hintbox b { font: 400 17px var(--display); }
.hintbox .row { display: flex; gap: 8px; margin-top: 12px; }
.hintbox .row .btn { flex: 1; }
.toolbar { display: flex; justify-content: center; gap: 12px; margin-top: 14px; }
.tool { position: relative; width: 58px; height: 58px; border-radius: 18px; background: var(--card); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; }
.tool svg.ic { width: 28px; height: 28px; }
.tool .cat { width: 40px; height: 40px; }
.tool.on { background: linear-gradient(#ffe39a, #ffcb57); box-shadow: 0 3px 0 var(--yellow-deep), 0 6px 12px rgba(233, 169, 59, .25); }
.tool:disabled { opacity: .4; }
.tool .count { position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 999px; background: #f06a6a; color: #fff; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; }

/* 모달 */
.modal { position: fixed; inset: 0; background: rgba(75, 44, 63, .45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 10; }
.modal[hidden] { display: none; }
.sheet { background: var(--bg); border-radius: 28px; padding: 22px 20px; width: 100%; max-width: 380px; max-height: 90dvh; overflow: auto; text-align: center; }
.sheet h3 { margin: 4px 0 8px; font: 400 24px var(--display); }
.sheet p { margin: 6px 0; line-height: 1.5; font-size: 15px; }
.sheet > .cat { width: 104px; height: 104px; margin: 0 auto; }
.sheet .stack { display: grid; gap: 12px; margin-top: 18px; }
.sheet ol { text-align: left; padding-left: 20px; line-height: 1.6; font-size: 15px; margin: 8px 0; }
.sheet.clear { background: radial-gradient(circle at 50% 24%, #fff3c9 0, #fff7f2 46%); padding-top: 14px; }
.sheet.clear .party { width: 190px; height: 190px; margin: 0 auto -18px; display: block; object-fit: contain; }
.anim-on .sheet.clear .party { animation: hop .6s ease-out; }
@keyframes hop { from { transform: translateY(24px) scale(.8); opacity: 0; } 60% { transform: translateY(-8px) scale(1.04); opacity: 1; } to { transform: none; } }
.ribbon { position: relative; display: inline-block; margin: 0 auto; padding: 9px 30px 10px; background: linear-gradient(#ffe7a6, #ffcf63); color: #5a3a12; font: 400 23px var(--display); border-radius: 8px; box-shadow: 0 3px 0 var(--yellow-deep); transform: rotate(-2deg); }
.ribbon::before, .ribbon::after { content: ""; position: absolute; top: 8px; width: 22px; height: 100%; background: #f2b84a; z-index: -1; }
.ribbon::before { left: -14px; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 40% 50%); }
.ribbon::after { right: -14px; clip-path: polygon(0 0, 100% 0, 60% 50%, 100% 100%, 0 100%); }
.bigstars { display: flex; justify-content: center; gap: 6px; margin: 16px 0 12px; }
.bigstars img, .bigstars .stars { width: 52px; height: 52px; font-size: 52px; }
.bigstars .off { filter: grayscale(1) opacity(.28); }
.bigstars > :nth-child(2) { transform: translateY(-8px) scale(1.12); }
.rewards { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.setrow { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px; border-bottom: 1px solid var(--line); text-align: left; font-weight: 600; }
.switch { width: 50px; height: 30px; border-radius: 999px; background: #e3d3cc; position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--good); }
.switch.on::after { transform: translateX(20px); }
.tool .count[hidden] { display: none; }
.langsel { font: inherit; font-weight: 700; color: var(--ink); background: #fff7f0; border: 2px solid var(--line); border-radius: 12px; padding: 6px 10px; }

/* 모바일: 화면이 옆으로 밀리거나 확대되어 흔들리지 않게 한다 */
html { overflow-x: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { position: relative; width: 100%; max-width: 100%; touch-action: pan-x pan-y; } /* 스크롤만 허용하고 두 손가락 확대·두 번 탭 확대는 막는다 */
#app { overflow-x: clip; }
