:root { --bs: var(--kit-btn-scale, 1); --ink: #2f3550; --muted: #7a809c; --accent: #8b7cf6; --pink: #ff8fb8; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { font-family: "Pretendard", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; background: #eaf6ff; color: var(--ink); word-break: keep-all; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.hidden { display: none !important; }

#stage { position: fixed; inset: 0; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.top { position: fixed; top: 0; left: 0; right: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 10px) 14px 8px; pointer-events: none; }
.top > * { pointer-events: auto; }
.top h1 { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: -0.5px; color: #4b4f73; text-shadow: 0 2px 0 rgba(255, 255, 255, .8); white-space: nowrap; }
.top h1 b { color: var(--accent); }
body.playing .top { display: none; }

.screen { position: fixed; inset: 0; z-index: 10; }
#home { display: flex; flex-direction: column; padding: calc(env(safe-area-inset-top) + 58px) 16px calc(env(safe-area-inset-bottom) + 14px); pointer-events: none; }
#home > * { pointer-events: auto; }
.hero { text-align: center; }
.best { margin: 0 auto; display: inline-block; padding: 6px 14px; border-radius: 99px; background: rgba(255, 255, 255, .78); font-weight: 800; font-size: 14px; color: #c2477a; box-shadow: 0 4px 14px rgba(90, 80, 150, .1); }
.best:empty { display: none; }
.spacer { flex: 1; min-height: 120px; pointer-events: none !important; }
.panel { width: 100%; max-width: 440px; margin: 0 auto; padding: 14px; border-radius: 24px; background: rgba(255, 255, 255, .9); border: 1px solid #ece8f4; box-shadow: 0 14px 40px rgba(80, 70, 140, .16); display: grid; gap: 8px; max-height: 62vh; overflow-y: auto; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.big { padding: calc(13px * var(--bs)) 12px; border-radius: calc(16px * var(--bs)); border: 0; font: inherit; font-weight: 900; font-size: calc(16px * var(--bs)); cursor: pointer; transition: transform .1s; }
.big:active { transform: scale(.97); }
.big.primary { color: #fff; background: linear-gradient(135deg, #ff8fb8, #8b7cf6); box-shadow: 0 8px 20px rgba(139, 124, 246, .32); font-size: calc(19px * var(--bs)); padding: calc(15px * var(--bs)) 12px; }
.big.ghost { background: #fff; color: var(--accent); border: 1.5px solid #e4def5; }
.howto { border-radius: 16px; background: #faf8ff; border: 1px solid #ece8f4; padding: 8px 12px; }
.howto summary { cursor: pointer; font-weight: 900; font-size: 14px; color: #5b5f86; padding: 2px 0; }
.howto ul { margin: 6px 0 2px; padding-left: 18px; font-size: 13.5px; line-height: 1.6; color: #565c7c; }
.howto li { margin: 2px 0; }
.gear { margin: 0; font-size: 12.5px; color: var(--muted); text-align: center; }
.gear b { color: #5b5f86; }

/* 게임 화면 */
#play { pointer-events: none; }
#play button { pointer-events: auto; }
.quit, .sound { position: absolute; top: calc(env(safe-area-inset-top) + 10px); width: calc(44px * var(--bs)); height: calc(44px * var(--bs)); border-radius: 50%; border: 0; background: rgba(255, 255, 255, .85); color: #6b6f92; font-size: calc(18px * var(--bs)); font-weight: 900; box-shadow: 0 4px 12px rgba(60, 50, 110, .15); cursor: pointer; display: grid; place-items: center; padding: 0; }
.quit { left: 12px; }
.sound { left: 12px; top: calc(env(safe-area-inset-top) + 18px + 44px * var(--bs)); font-size: calc(16px * var(--bs)); }
.hud { position: absolute; top: calc(env(safe-area-inset-top) + 18px); left: 50%; transform: translateX(-50%); text-align: center; color: #fff; text-shadow: 0 2px 10px rgba(60, 50, 120, .35); }
.hud b { display: block; font-size: 56px; font-weight: 900; line-height: 1; letter-spacing: -1px; }
.hud small { display: block; margin-top: 4px; font-size: 14px; font-weight: 800; opacity: .95; }
.pops { position: absolute; left: 0; right: 0; top: 34%; text-align: center; }
.pop { position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; font-weight: 900; font-size: 26px; color: #ff4f8b; -webkit-text-stroke: 5px #fff; paint-order: stroke fill; text-shadow: 0 4px 14px rgba(120, 60, 120, .3); animation: pop 0.9s ease-out forwards; }
.pop.gold { color: #f08c00; }
.pop.blue { color: #3b82f6; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.7); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -40px) scale(1); } }
.tap-hint { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 26px); margin: 0; text-align: center; font-size: 16px; font-weight: 800; color: #fff; text-shadow: 0 2px 8px rgba(60, 50, 120, .4); animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .45; } }
.count { position: absolute; inset: 0; display: grid; place-items: center; font-size: 110px; font-weight: 900; color: #fff; text-shadow: 0 6px 30px rgba(139, 124, 246, .6); }
.banner { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 70px); transform: translateX(-50%); padding: 12px 18px; border-radius: 18px; background: rgba(255, 255, 255, .92); box-shadow: 0 10px 30px rgba(60, 50, 110, .2); text-align: center; font-weight: 800; font-size: 15px; line-height: 1.5; width: max-content; max-width: calc(100% - 32px); }
.banner b { color: #c2477a; }

/* 친구 탑 (오른쪽) */
.rivals { position: absolute; right: 8px; top: calc(env(safe-area-inset-top) + 10px); display: grid; gap: 6px; width: 86px; }
.rv { padding: 5px 6px 6px; border-radius: 14px; background: rgba(255, 255, 255, .86); box-shadow: 0 4px 12px rgba(60, 50, 110, .14); border-top: 3px solid var(--pc); text-align: center; }
.rv canvas { display: block; width: 100%; height: 54px; }
.rv b { display: block; font-size: 18px; font-weight: 900; line-height: 1.1; }
.rv small { display: block; font-size: 11px; font-weight: 800; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv.dead { opacity: .62; filter: grayscale(.7); }
.rv.dead b::after { content: ' 끝'; font-size: 11px; color: #c2477a; }
.rv.me { outline: 2px solid var(--pc); }

/* 결과 */
.res-big { text-align: center; margin: 4px 0 10px; }
.res-big b { display: block; font-size: 54px; font-weight: 900; line-height: 1; color: var(--accent); }
.res-big small { color: var(--muted); font-weight: 800; }
.res-new { display: inline-block; margin-top: 6px; padding: 3px 10px; border-radius: 99px; background: #ffe0ea; color: #c23a5e; font-weight: 900; font-size: 13px; }
.rank { display: grid; gap: 6px; margin: 8px 0; }
.rk { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 8px; align-items: center; padding: 9px 12px; border-radius: 14px; background: #faf9fd; border: 1px solid #ece8f4; border-left: 5px solid var(--pc); }
.rk.me { background: #f3f0ff; }
.rk i { font-style: normal; font-weight: 900; font-size: 18px; text-align: center; }
.rk b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk span { font-weight: 900; }
.rk em { font-style: normal; font-size: 12px; font-weight: 800; color: #c98200; min-width: 44px; text-align: right; }
.res-actions .kit-btn { padding: calc(12px * var(--bs)) 14px; font-size: calc(15px * var(--bs)); }

.load-err { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 30; padding: 16px 20px; border-radius: 18px; background: #fff; box-shadow: 0 10px 30px rgba(60, 50, 110, .2); text-align: center; font-weight: 800; line-height: 1.6; }

/* 휴대폰 가로: 단추 판을 오른쪽에 */
@media (orientation: landscape) and (max-height: 560px) {
  #home { flex-direction: row; align-items: stretch; gap: 12px; padding-top: calc(env(safe-area-inset-top) + 52px); }
  .hero { position: absolute; left: 16px; top: calc(env(safe-area-inset-top) + 54px); }
  .spacer { min-height: 0; }
  .panel { width: min(400px, 52vw); max-height: none; margin: 0; align-self: stretch; }
  .hud b { font-size: 44px; }
  .hud { top: calc(env(safe-area-inset-top) + 8px); }
  .rivals { grid-template-columns: repeat(3, 76px); width: auto; }
  .rv canvas { height: 40px; }
  .count { font-size: 80px; }
}
@media (min-width: 900px) and (min-height: 600px) {
  #home { flex-direction: row; align-items: center; padding-left: 40px; padding-right: 40px; }
  .hero { position: absolute; left: 50%; transform: translateX(-50%); top: 70px; }
  .panel { width: 420px; max-height: calc(100vh - 120px); margin: 0 0 0 auto; }
  .spacer { min-height: 0; }
  .rivals { width: 110px; right: 16px; }
  .rv canvas { height: 70px; }
}
