:root {
  --ink: #5b4a5f;
  --ink-soft: #9a8a9d;
  --bg1: #fff6e9;
  --bg2: #ffe4ee;
  --panel: #fffaf6;
  --pink: #ff8fab;
  --pink-d: #e0678b;
  --mint: #6fd6b0;
  --mint-d: #43ae8a;
  --gold: #ffcb4d;
  --gold-d: #d9a22a;
  --line: #f1e3e8;
  --hud-ink: #5b4a5f;
  --shadow: 0 8px 24px rgba(140, 80, 110, .16);
}
body.dark-ui { --hud-ink: #fff6fb; }
body.dark-ui .tagline, body.dark-ui .best-line { color: #f3eaff; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: 'Jua', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(var(--bg1), var(--bg2));
  touch-action: manipulation;
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; }

#app {
  position: fixed; inset: 0;
  max-width: 540px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}

/* ── HUD */
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px 0;
  color: var(--hud-ink);
  height: 68px; flex: none;
}
.stat { display: flex; flex-direction: column; line-height: 1; }
.stat .num { font-size: 30px; }
.stat.small .num { font-size: 18px; opacity: .85; }
.label { font-size: 12px; opacity: .7; margin-bottom: 3px; }
.next { display: flex; flex-direction: column; align-items: center; margin-left: auto; }
.next .label { margin-bottom: 0; }
#nextCanvas {
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255, 255, 255, .55);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .9);
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 14px; border: 0;
  background: rgba(255, 255, 255, .75); font-size: 16px; color: var(--ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .06); cursor: pointer; flex: none;
}
.icon-btn:active { transform: translateY(2px); }

.coin-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .8); border-radius: 999px;
  padding: 5px 12px 5px 6px; font-size: 17px; color: var(--ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .06);
}
.coin-pill .plus {
  border: 0; background: var(--mint); color: #fff; width: 22px; height: 22px;
  border-radius: 50%; font-size: 16px; line-height: 1; margin-left: 2px; cursor: pointer;
}
.coin-pill.bump { animation: bump .35s; }
i.coin {
  display: inline-block; width: 22px; height: 22px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 30%, #fff5c4, #ffd452 45%, #f0a92a);
  box-shadow: inset 0 0 0 2px #e9a52a;
  position: relative; vertical-align: middle;
}
i.coin::after {
  content: ''; position: absolute; left: 7px; top: 5px; width: 8px; height: 12px;
  border-radius: 50%; border: 2px solid rgba(200, 130, 20, .55); border-top-color: transparent; border-bottom-color: transparent;
}

#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#game { position: absolute; inset: 0; display: block; touch-action: none; }
#stage.shake { animation: shake .5s; }

#comboText {
  position: absolute; left: 50%; top: 22%; transform: translate(-50%, 0) scale(0);
  font-size: 34px; color: #fff; pointer-events: none; white-space: nowrap;
  text-shadow: 0 3px 0 var(--pink-d), 0 0 18px rgba(255, 143, 171, .8);
}
#comboText.show { animation: comboPop .9s ease-out forwards; }

#hint {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: rgba(255, 255, 255, .92); padding: 8px 16px; border-radius: 999px;
  font-size: 15px; pointer-events: none; opacity: 0; transition: opacity .3s;
  box-shadow: var(--shadow); white-space: nowrap;
}
#hint.show { opacity: 1; }

#discover {
  position: absolute; left: 50%; top: 10px; transform: translate(-50%, -140%);
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 22px; padding: 8px 18px 8px 8px;
  box-shadow: var(--shadow); transition: transform .45s cubic-bezier(.2, 1.4, .4, 1);
  pointer-events: none; z-index: 5;
}
#discover.show { transform: translate(-50%, 0); }
.disc-txt { display: flex; flex-direction: column; line-height: 1.2; white-space: nowrap; }
.disc-txt small { color: var(--pink-d); font-size: 13px; }
.disc-txt b { font-size: 20px; font-weight: normal; }
.disc-reward { font-size: 13px; color: var(--gold-d); }

#itembar {
  display: flex; gap: 10px; justify-content: center;
  padding: 8px 14px 12px; flex: none;
}
.item {
  position: relative; flex: 1; max-width: 130px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; border-radius: 18px; padding: 8px 4px 7px;
  background: rgba(255, 255, 255, .85); cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .07);
}
.item:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .07); }
.item .ico { font-size: 24px; line-height: 1; }
.item .nm { font-size: 12px; color: var(--ink-soft); }
.item .cnt {
  position: absolute; top: -6px; right: -4px; min-width: 22px; height: 22px;
  background: var(--pink); color: #fff; font-weight: normal; font-size: 13px;
  border-radius: 999px; display: grid; place-items: center; padding: 0 6px;
  box-shadow: 0 2px 0 var(--pink-d);
}
.item .cnt.zero { background: var(--mint); box-shadow: 0 2px 0 var(--mint-d); }
.item.active { background: #fff1c9; box-shadow: 0 0 0 3px var(--gold), 0 4px 0 rgba(0, 0, 0, .07); }

/* ── 버튼 */
.btn {
  font-size: 19px; border: 0; border-radius: 18px; padding: 13px 20px;
  background: #fff; color: var(--ink); cursor: pointer;
  box-shadow: 0 5px 0 #ecdde3; transition: transform .06s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #ecdde3; }
.btn:disabled { opacity: .45; }
.btn.primary { background: linear-gradient(#ffa6bd, #ff819f); color: #fff; box-shadow: 0 5px 0 var(--pink-d); }
.btn.primary:active { box-shadow: 0 1px 0 var(--pink-d); }
.btn.ad { background: linear-gradient(#8de6c6, #5fcca5); color: #fff; box-shadow: 0 5px 0 var(--mint-d); flex-direction: column; gap: 0; }
.btn.ad small { font-size: 12px; opacity: .9; }
.btn.ad.alt { background: linear-gradient(#ffe38f, #ffcb4d); color: #7a5810; box-shadow: 0 5px 0 var(--gold-d); }
.btn.ghost { background: transparent; box-shadow: none; color: var(--ink-soft); font-size: 15px; }
.btn.big { font-size: 28px; padding: 16px 70px; border-radius: 26px; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.small { font-size: 15px; padding: 8px 14px; border-radius: 14px; box-shadow: 0 3px 0 #ecdde3; }
.btn.small.primary { box-shadow: 0 3px 0 var(--pink-d); }
.link { border: 0; background: none; color: var(--ink-soft); font-size: 15px; margin-top: 12px; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }
.row { display: flex; gap: 10px; width: 100%; margin-top: 12px; }
.row .btn { flex: 1; }

/* ── 홈 */
.screen {
  position: absolute; inset: 0; z-index: 20;
  display: none; flex-direction: column; align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 24px;
  background: linear-gradient(var(--bg1), var(--bg2));
  overflow-y: auto;
}
.screen.show { display: flex; animation: fadeIn .35s; }
.home-top { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.logo { margin-top: 5vh; display: flex; flex-direction: column; align-items: center; line-height: .95; }
.logo .l1 {
  font-size: clamp(46px, 14vw, 66px); color: #fff;
  text-shadow: 0 4px 0 var(--pink-d), 0 8px 0 rgba(224, 103, 139, .3);
  -webkit-text-stroke: 2px var(--pink-d); paint-order: stroke fill;
  animation: float 3s ease-in-out infinite;
}
.logo .l2 {
  font-size: clamp(34px, 10vw, 48px); color: var(--mint-d);
  text-shadow: 0 3px 0 #fff; animation: float 3s ease-in-out .4s infinite;
}
.tagline { color: var(--ink-soft); margin: 14px 0 0; font-size: 16px; text-align: center; }
#homeCanvas { width: min(92%, 420px); height: 150px; margin: 6px 0 4px; }
.best-line { font-size: 17px; margin-bottom: 16px; }
.best-line b { color: var(--pink-d); font-weight: normal; font-size: 22px; }
#btnPlay { animation: breathe 2.2s ease-in-out infinite; }
.home-menu { display: flex; gap: 10px; margin-top: 26px; width: 100%; max-width: 420px; }
.menu-btn {
  position: relative; flex: 1; border: 0; border-radius: 20px; padding: 12px 0 10px;
  background: rgba(255, 255, 255, .85); font-size: 15px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .06);
}
.menu-btn span { font-size: 26px; }
.menu-btn:active { transform: translateY(3px); }
.dot { position: absolute; top: 6px; right: 12px; width: 11px; height: 11px; border-radius: 50%; background: #ff5b7f; border: 2px solid #fff; display: none; }
.dot.on { display: block; animation: bump 1.2s infinite; }

/* ── 모달 */
.modal {
  position: absolute; inset: 0; z-index: 40; display: none;
  align-items: center; justify-content: center; padding: 16px;
  background: rgba(70, 40, 60, .35); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.modal.top { z-index: 60; }
.modal.show { display: flex; animation: fadeIn .2s; }
.panel {
  width: 100%; max-width: 400px; max-height: 100%;
  background: var(--panel); border-radius: 28px; padding: 18px;
  box-shadow: 0 20px 50px rgba(80, 30, 60, .3);
  display: flex; flex-direction: column;
  animation: popIn .35s cubic-bezier(.2, 1.4, .4, 1);
}
.panel.center { align-items: center; text-align: center; }
.panel h2 { margin: 0; font-weight: normal; font-size: 24px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.close { border: 0; background: #f4e8ec; width: 36px; height: 36px; border-radius: 12px; font-size: 16px; cursor: pointer; }
.panel-body { overflow-y: auto; margin-top: 10px; touch-action: pan-y; }
.sub { color: var(--ink-soft); font-size: 14px; margin: 6px 0 0; }
.pre { white-space: pre-line; font-size: 18px; line-height: 1.5; margin: 6px 0 4px; }
.fine { color: var(--ink-soft); font-size: 12px; text-align: center; margin-top: 16px; line-height: 1.6; }
.big-ico { font-size: 54px; }

.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.col-cell {
  background: #fff; border-radius: 18px; padding: 8px 4px 10px; text-align: center;
  box-shadow: 0 3px 0 var(--line); cursor: pointer;
}
.col-cell canvas { display: block; margin: 0 auto; }
.col-cell .nm { font-size: 14px; }
.col-cell.locked .nm { color: #c9bcc6; }
.col-cell .lv { font-size: 11px; color: var(--ink-soft); }
.col-detail { grid-column: 1 / -1; background: #fff3f6; border-radius: 16px; padding: 10px 14px; font-size: 14px; line-height: 1.5; }

.shop-sec { font-size: 16px; margin: 14px 0 8px; color: var(--ink-soft); }
.shop-sec:first-child { margin-top: 0; }
.prod {
  position: relative; display: flex; align-items: center; gap: 12px;
  background: #fff; border-radius: 18px; padding: 12px; margin-bottom: 10px;
  box-shadow: 0 3px 0 var(--line);
}
.prod.hero { background: linear-gradient(135deg, #fff1f5, #fff8e6); box-shadow: 0 0 0 2px var(--pink), 0 3px 0 var(--line); }
.prod .pi { font-size: 32px; width: 44px; text-align: center; }
.prod .pt { flex: 1; display: flex; flex-direction: column; }
.prod .pt b { font-weight: normal; font-size: 17px; }
.prod .pt small { color: var(--ink-soft); font-size: 13px; }
.prod .badge {
  position: absolute; top: -8px; left: 12px; background: var(--pink); color: #fff;
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
}
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.theme-card {
  border-radius: 18px; padding: 12px; text-align: center; cursor: pointer; border: 0;
  box-shadow: 0 3px 0 var(--line); display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.theme-card .ti { font-size: 30px; }
.theme-card.sel { box-shadow: 0 0 0 3px var(--mint), 0 3px 0 var(--line); }
.theme-card .tp { font-size: 13px; display: flex; align-items: center; gap: 4px; }
.theme-card .tp i.coin { width: 16px; height: 16px; }
.theme-card .tp i.coin::after { display: none; }

.daily-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.day {
  background: #fff; border-radius: 16px; padding: 8px 2px; text-align: center; font-size: 12px;
  box-shadow: 0 3px 0 var(--line); display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 84px;
}
.day .dn { color: var(--ink-soft); }
.day .dr { font-size: 22px; }
.day .dv { font-size: 12px; }
.day.done { opacity: .5; }
.day.done .dr::after { content: ' ✓'; font-size: 14px; color: var(--mint-d); }
.day.today { box-shadow: 0 0 0 3px var(--pink), 0 3px 0 var(--line); background: #fff5f8; }
.day.big { grid-column: span 2; background: linear-gradient(135deg, #fff7da, #ffe9f1); }

.mission {
  display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 16px;
  padding: 10px 12px; margin-bottom: 8px; box-shadow: 0 3px 0 var(--line);
}
.mission .mt { flex: 1; font-size: 15px; }
.bar { height: 8px; background: #f3e6ea; border-radius: 99px; margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #8de6c6, #5fcca5); border-radius: 99px; }
.mission .mp { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.mission .claimed { color: var(--mint-d); font-size: 14px; }

.toggles { display: flex; gap: 8px; width: 100%; margin: 12px 0 4px; }
.tg {
  flex: 1; border: 0; border-radius: 16px; padding: 10px 0; background: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 13px;
  box-shadow: 0 3px 0 var(--line);
}
.tg span { font-size: 22px; }
.tg.off { opacity: .45; }

/* 게임 오버 */
.go-title { color: var(--pink-d); }
.go-new { margin-top: 8px; background: #fff1c9; color: #b07d10; padding: 4px 12px; border-radius: 999px; font-size: 14px; display: none; }
.go-new.show { display: inline-block; animation: bump .8s infinite; }
.go-score { font-size: 64px; line-height: 1.1; margin-top: 6px; }
.go-best { color: var(--ink-soft); font-size: 15px; }
.go-best b { font-weight: normal; color: var(--ink); }
.go-reward { display: flex; align-items: center; gap: 6px; font-size: 22px; margin: 10px 0 4px; }
.go-reward b { font-weight: normal; }

/* 광고 시뮬레이터 */
#adSim {
  position: absolute; inset: 0; z-index: 80; display: none; align-items: center; justify-content: center;
  background: #1d1a22;
}
#adSim.show { display: flex; }
.ad-box { color: #fff; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.ad-tag { font-size: 13px; background: rgba(255, 255, 255, .15); padding: 4px 10px; border-radius: 8px; }
.ad-art { font-size: 90px; animation: float 2s ease-in-out infinite; }
.ad-text { font-size: 18px; opacity: .85; line-height: 1.5; }
.ad-timer { font-size: 40px; }

#toast {
  position: absolute; left: 50%; bottom: 110px; transform: translate(-50%, 20px);
  background: rgba(70, 45, 65, .9); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 15px; opacity: 0; transition: all .3s; pointer-events: none; z-index: 90;
  width: max-content; max-width: 90%; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes bump { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.18); } }
@keyframes comboPop {
  0% { transform: translate(-50%, 0) scale(.3); opacity: 0; }
  25% { transform: translate(-50%, -6px) scale(1.15); opacity: 1; }
  70% { transform: translate(-50%, -14px) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -30px) scale(1); opacity: 0; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px) rotate(-1deg); }
  40% { transform: translateX(8px) rotate(1deg); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
