:root { --ink: #2b2140; --cream: #fff4e0; --pink: #ff5d8f; --yellow: #ffd23f; --mint: #5ee0c4; --purple: #3d2c5e; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--purple); color: var(--ink);
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#game { position: fixed; inset: 0; display: block; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }

/* ---------- 오버레이 ---------- */
.ov { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.ov.dim { background: rgba(43,33,64,0.6); }
.box { text-align: center; width: 100%; max-width: 520px; margin: auto; }
.panel { background: var(--cream); border: 5px solid var(--ink); border-radius: 26px; padding: 20px 18px; box-shadow: 0 8px 0 var(--ink); }
.panel.wide { max-width: 720px; }
h2 { margin: 0 0 12px; font-size: 32px; font-weight: 900; letter-spacing: 1px; color: var(--ink); }
.logo { margin: 0 0 6px; line-height: 0.95; font-size: clamp(44px, 12.5vw, 112px); font-weight: 900; letter-spacing: 2px; }
.logo span { display: block; color: var(--yellow); -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; text-shadow: 0 8px 0 var(--ink); animation: bob 1.6s ease-in-out infinite; }
.logo span + span { color: var(--pink); animation-delay: 0.2s; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-1.5deg); } }
.tag { color: #fff; font-weight: 800; font-size: 18px; margin: 14px 0 18px; text-shadow: 0 2px 0 var(--ink); }
.btn { display: block; width: 100%; max-width: 300px; margin: 10px auto; padding: 13px 16px; font-size: 20px; font-weight: 900; color: var(--ink);
  background: #fff; border: 4px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink); transition: transform 0.08s; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:hover { background: #fffbe8; }
.btn.big { background: var(--yellow); font-size: 26px; padding: 16px; }
.btn.big:hover { background: #ffe066; }
.btn.ghost { background: transparent; box-shadow: none; border-color: rgba(43,33,64,0.4); font-size: 17px; }
.btn.ad { background: var(--mint); }
.row { display: flex; gap: 10px; justify-content: center; max-width: 420px; margin: 0 auto; }
.row .btn { margin: 6px 0; }
.row.small { flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip { padding: 7px 13px; border: 3px solid var(--ink); border-radius: 999px; background: #fff; font-weight: 800; font-size: 14px; color: var(--ink); box-shadow: 0 3px 0 var(--ink); }
.chip.off { opacity: 0.5; text-decoration: line-through; }
.best { color: #fff; font-weight: 800; margin-top: 12px; min-height: 20px; text-shadow: 0 2px 0 var(--ink); font-size: 15px; }
.topbar { position: fixed; top: 12px; right: 14px; z-index: 2; }
.coins { display: inline-block; background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 5px 14px; font-weight: 900; font-size: 18px; box-shadow: 0 3px 0 var(--ink); }
.phead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.phead h2 { margin: 0; }
.how { text-align: left; padding-left: 4px; list-style: none; font-size: 16px; line-height: 1.6; margin: 0 0 10px; }
.how li { margin: 6px 0; }

/* 캐릭터·상점 칸 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 8px 0 10px; }
.cell { background: #fff; border: 4px solid var(--ink); border-radius: 18px; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.cell.sel { background: #fff3b0; }
.cell .face { width: 56px; height: 56px; border-radius: 50%; border: 4px solid var(--ink); position: relative; }
.cell .face::before, .cell .face::after { content: ''; position: absolute; top: 15px; width: 10px; height: 13px; background: #fff; border: 2px solid var(--ink); border-radius: 50%; }
.cell .face::before { left: 8px; } .cell .face::after { right: 8px; }
.cell b { font-size: 18px; }
.cell .perk { font-size: 13px; color: #5a4a70; min-height: 34px; line-height: 1.3; }
.cell .ic { font-size: 34px; line-height: 1; }
.cell .pips { letter-spacing: 2px; font-size: 13px; color: #b9a8d0; }
.cell .pips i { font-style: normal; color: var(--pink); }
.cell button { width: 100%; padding: 7px; border: 3px solid var(--ink); border-radius: 12px; background: var(--yellow); font-weight: 900; font-size: 15px; color: var(--ink); }
.cell button:disabled { background: #e5dcef; color: #8a7aa0; cursor: default; }

/* 레벨업 카드 */
#lu-title { font-size: clamp(40px, 10vw, 64px); color: var(--yellow); -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink); }
.pop-in { animation: popin 0.35s cubic-bezier(.2,1.6,.4,1); }
@keyframes popin { from { transform: scale(0.3); opacity: 0; } }
#cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 6px 0 14px; }
.card { width: 158px; min-height: 196px; background: var(--cream); border: 5px solid var(--ink); border-radius: 22px; padding: 12px 10px; box-shadow: 0 6px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; animation: popin 0.35s backwards; transition: transform 0.1s; color: var(--ink); }
.card:nth-child(2) { animation-delay: 0.07s; } .card:nth-child(3) { animation-delay: 0.14s; }
.card:hover { transform: translateY(-6px) rotate(-1deg); }
.card .ic { font-size: 46px; line-height: 1.1; }
.card b { font-size: 17px; line-height: 1.15; }
.card .lv { font-size: 13px; font-weight: 900; padding: 2px 10px; border-radius: 999px; background: var(--ink); color: #fff; }
.card .lv.new { background: var(--pink); }
.card p { margin: 0; font-size: 13px; color: #5a4a70; line-height: 1.3; }
.card .key { margin-top: auto; font-size: 11px; color: #a090b8; }
@media (max-height: 520px) { .card { width: 140px; min-height: 160px; padding: 8px; } .card .ic { font-size: 34px; } #lu-title { font-size: 36px; margin-bottom: 4px; } }

/* 결과 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 10px; }
.stats div { background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 8px 4px; }
.stats b { display: block; font-size: 24px; font-weight: 900; }
.stats span { font-size: 12px; color: #5a4a70; font-weight: 700; }
.earn { font-size: 22px; font-weight: 900; margin: 4px 0 4px; }
.earn small { display: block; font-size: 13px; color: #5a4a70; font-weight: 700; }
.kitlist { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 0 0 8px; }
.kitlist span { background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 3px 8px; font-weight: 900; font-size: 14px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#xpbar { position: absolute; top: 0; left: 0; right: 0; height: 18px; background: rgba(43,33,64,0.75); border-bottom: 3px solid var(--ink); }
#xpfill { height: 100%; width: 0; background: linear-gradient(90deg, #4cc9f0, #52d273); transition: width 0.15s; }
#lvl { position: absolute; left: 50%; top: 0; transform: translateX(-50%); font-weight: 900; font-size: 13px; color: #fff; line-height: 18px; text-shadow: 0 1px 0 var(--ink); }
#hud-top { position: absolute; top: 24px; left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: flex-start; }
#hud-l { max-width: 40%; display: flex; flex-direction: column; gap: 5px; }
#hpbar { position: relative; transform-origin: left center; width: min(240px, 36vw); height: 22px; background: #5a4a70; border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; }
#hpfill { height: 100%; width: 100%; background: linear-gradient(90deg, #52d273, #8be08f); transition: width 0.15s; }
#hpbar.mid #hpfill { background: linear-gradient(90deg, #ffb703, #ffd23f); }
#hpbar.low #hpfill { background: linear-gradient(90deg, #e63946, #ff5d8f); }
#hpbar.low { animation: lowhp 0.6s ease-in-out infinite; }
@keyframes lowhp { 50% { transform: scale(1.06); box-shadow: 0 0 14px #ff3355; } }
#hptxt { position: absolute; inset: 0; text-align: center; line-height: 16px; font-weight: 900; font-size: 13px; color: #fff; text-shadow: 0 1px 0 var(--ink), 0 0 3px var(--ink); }
#kit { display: flex; flex-wrap: wrap; gap: 3px; }
#kit span { background: rgba(255,244,224,0.92); border: 2.5px solid var(--ink); border-radius: 10px; font-size: 16px; padding: 1px 4px; font-weight: 900; }
#kit span sub { font-size: 10px; }
#timer { font-size: 30px; font-weight: 900; color: #fff; -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; }
#hud-r { display: flex; gap: 6px; align-items: center; pointer-events: auto; }
#hud-r span { background: rgba(255,244,224,0.92); border: 3px solid var(--ink); border-radius: 999px; padding: 2px 10px; font-weight: 900; font-size: 15px; }
.ico { width: 40px; height: 40px; border: 3px solid var(--ink); border-radius: 12px; background: #fff; font-weight: 900; font-size: 15px; color: var(--ink); box-shadow: 0 3px 0 var(--ink); }
#bossbar { position: absolute; top: 78px; left: 50%; transform: translateX(-50%); width: min(460px, 80vw); text-align: center; }
#bossbar b { color: #fff; font-size: 16px; font-weight: 900; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; letter-spacing: 1px; }
#bossbar .track { height: 16px; background: #5a4a70; border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; margin-top: 2px; }
#bossfill { height: 100%; width: 100%; background: linear-gradient(90deg, #e63946, #ff8fab); transition: width 0.1s; }
#banner { position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-size: clamp(34px, 8vw, 60px); font-weight: 900; color: var(--yellow);
  -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; opacity: 0; }
#banner.show { animation: banner 1.8s ease-out; }
@keyframes banner { 0% { opacity: 0; transform: scale(2.2); } 15% { opacity: 1; transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-30px); } }

/* ---------- 터치 ---------- */
#touch { position: fixed; inset: 0; z-index: 9; }
#joy { position: absolute; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%; background: rgba(255,255,255,0.18); border: 4px solid rgba(43,33,64,0.45); left: 110px; top: calc(100% - 110px); pointer-events: none; opacity: 0.6; }
#joy.on { opacity: 1; }
#knob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: rgba(255,255,255,0.85); border: 4px solid var(--ink); }
#b-dash { position: absolute; right: max(22px, env(safe-area-inset-right)); bottom: max(26px, env(safe-area-inset-bottom)); width: 92px; height: 92px; border-radius: 50%;
  border: 5px solid var(--ink); background: var(--mint); font-weight: 900; font-size: 18px; color: var(--ink); box-shadow: 0 5px 0 var(--ink); }
#b-dash.cd { background: #b8c7cf; }
#b-dash:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
@media (max-width: 560px) { #timer { font-size: 24px; } #hud-r span { font-size: 13px; padding: 2px 7px; } #kit span { font-size: 13px; } .logo span { -webkit-text-stroke: 5px var(--ink); } }
@media (max-height: 520px) {
  .logo { font-size: 54px; } .logo span { display: inline; -webkit-text-stroke: 4px var(--ink); text-shadow: 0 4px 0 var(--ink); margin: 0 6px; }
  .tag { margin: 6px 0 8px; font-size: 15px; }
  .btn { padding: 8px 12px; font-size: 17px; margin: 6px auto; } .btn.big { padding: 10px; font-size: 21px; }
  .row.small { margin-top: 8px; } .best { margin-top: 6px; }
  .panel { padding: 12px; } h2 { font-size: 24px; margin-bottom: 6px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; } .cell { padding: 6px; } .cell .perk { min-height: 0; }
}
