/* 봉잡기 — 구구단 스피드와 같은 픽셀 틀(Galmuri, OFL) + 크림색 바탕. 봉 판은 캔버스 */
@font-face { font-family: 'Galmuri11'; src: url('/assets/fonts/Galmuri11.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Galmuri11'; font-weight: 700; src: url('/assets/fonts/Galmuri11-Bold.woff2') format('woff2'); font-display: swap; }

:root {
  --bg: #F6F3EC; --card: #FFFDF7; --ink: #1F2420; --muted: #7A7F78; --line: #E4DFD3;
  --accent: #3E9B3A; --accent-dark: #2B6E28; --danger: #D9483B; --gold: #E8A317;
  --px: 3px;   /* 픽셀 테두리 두께 */
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font-family: 'Galmuri11', -apple-system, 'Apple SD Gothic Neo', sans-serif; -webkit-font-smoothing: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
h1, h2 { margin: 0; font-weight: 700; }
b { font-weight: 700; }

/* 픽셀 상자: 모서리를 깎은 테두리 */
.card, .btn, .panel, .levels .lv, .pill {
  border: var(--px) solid var(--ink);
  box-shadow: 0 var(--px) 0 var(--ink);
}

.screen { display: none; min-height: 100%; }
.screen.active { display: block; }

/* ---------- 홈 ---------- */
#home { max-width: 480px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 28px); }
.hero { text-align: center; padding: 8px 0 16px; }
#heroCanvas { display: block; width: 240px; height: 150px; margin: 0 auto; image-rendering: pixelated; }
.hero h1 { font-size: 30px; margin-top: 12px; }
.tagline { color: var(--muted); margin: 6px 0 0; font-size: 14px; }

.btn { background: var(--card); padding: 12px 14px; font-weight: 700; font-size: 16px; }
.btn:active { transform: translateY(var(--px)); box-shadow: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.big { width: 100%; padding: 16px; font-size: 20px; margin: 4px 0 18px; }
.btn.ghost { padding: 8px 12px; font-size: 14px; }

.card { background: var(--card); padding: 14px; margin-bottom: 16px; }
.label { font-size: 12px; color: var(--muted); }
.nick { font-size: 18px; font-weight: 700; margin-top: 2px; }
.profile-top { display: flex; justify-content: space-between; align-items: center; }
.icon-btn { font-size: 22px; padding: 6px; }
.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 2px dashed var(--line); }
.num { font-size: 18px; font-weight: 700; margin-top: 2px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 8px; }
.section-head h2 { font-size: 17px; }
.hint { font-size: 12px; color: var(--muted); text-align: right; }

.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.levels .lv { background: var(--card); aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 2px 0 var(--ink); border-width: 2px; }
.levels .lv b { font-size: 17px; }
.levels .lv small { font-size: 11px; color: var(--muted); margin-top: 2px; }
.levels .lv.cleared { background: #E4F3DC; }
.levels .lv.selected { background: var(--accent); color: #fff; }
.levels .lv.selected small { color: #E4F3DC; }
.levels .lv.locked { opacity: .4; box-shadow: none; }
/* 4단계(초인) 칸은 검정·빨강 */
.levels .lv.s4 { border-color: #141414; }
.levels .lv.s4.cleared { background: #FFD9D6; }
.levels .lv.s4.selected { background: #141414; color: #FF6B5E; }

.ranking, .plays { list-style: none; margin: 0; padding: 0; }
.ranking li, .plays li { display: grid; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 2px dashed var(--line); font-size: 14px; }
.ranking li { grid-template-columns: 26px 1fr auto; }
.plays li { grid-template-columns: 76px 1fr auto; }
.ranking li:last-child, .plays li:last-child { border-bottom: 0; }
.ranking .rank { font-weight: 700; color: var(--muted); text-align: center; }
.ranking .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking li.me .who, .ranking li.me .rank { color: var(--accent-dark); font-weight: 700; }
.ranking .ms, .plays .ms { font-weight: 700; font-variant-numeric: tabular-nums; }
.ranking .mine-rank { display: block; text-align: right; color: var(--muted); font-size: 13px; border: 0; }
.ranking .empty, .plays .empty { display: block; text-align: center; color: var(--muted); padding: 14px 0; border: 0; }
.plays .when { color: var(--muted); font-size: 12px; }
.plays li.fail .what { color: var(--danger); }
.foot { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.foot a { color: inherit; }

/* ---------- 게임 ---------- */
#game { position: fixed; inset: 0; display: none; flex-direction: column; max-width: 480px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 12px); }
#game.active { display: flex; }
.topbar { display: flex; justify-content: space-between; align-items: center; }
.pill { background: var(--ink); color: var(--bg); padding: 6px 12px; font-size: 13px; font-weight: 700; box-shadow: none; }

/* 봉마다 한 칸: 잡음 초록 · 놓침 빨강 · 떨어지는 중 노랑 */
.dots { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.dots i { width: 14px; height: 14px; border: var(--px) solid var(--ink); background: var(--card); }
.dots i.ok { background: var(--accent); }
.dots i.miss { background: var(--danger); }
.dots i.now { background: var(--gold); }

.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; margin-top: 6px; }
#board { display: block; image-rendering: pixelated; touch-action: none; cursor: pointer; }

.overlay { position: fixed; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(246, 243, 236, .75); }
.overlay[hidden] { display: none; }
.panel { width: 100%; max-width: 440px; background: var(--card); padding: 22px 18px 18px; text-align: center; }
.kicker { font-size: 14px; color: var(--muted); font-weight: 700; }
.panel-title { font-size: 24px; margin: 6px 0 14px; }
.rules-list { text-align: left; margin: 0 auto; padding: 0 0 0 22px; max-width: 300px; font-size: 15px; line-height: 1.6; }
.big { font-size: 46px; font-weight: 700; margin: 6px 0; font-variant-numeric: tabular-nums; }
.big.fail { font-size: 28px; color: var(--danger); margin: 10px 0 6px; }
.sub { font-size: 14px; color: var(--muted); line-height: 1.6; }
.sub b { color: var(--ink); }
.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions .btn { flex: 1; }
.actions #homeBtn, .actions #rulesHomeBtn { flex: 0 0 auto; }
.actions [hidden] { display: none; }
.overlay.solid { background: var(--bg); }
.count-box { text-align: center; }
.count { font-size: 120px; font-weight: 700; color: var(--ink); line-height: 1; animation: pop .5s; }
.count-hint { margin-top: 16px; font-size: 18px; font-weight: 700; color: var(--muted); }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .count { animation: none; } }
