:root {
  --bg: #f7f7fa;
  --ink: #2b2b33;
  --muted: #8a8a99;
  --accent: #ff6b4a;
  --accent2: #ffd23f;
  --line: #e3e3ea;
  --gold: #f5b50a;
  --silver: #b6bcc6;
  --bronze: #cd8b52;
  --card: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.wrap {
  max-width: 940px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.topbar { text-align: center; margin-bottom: 18px; }

.logo {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: -1px;
  margin: 0;
}
.logo span { color: var(--accent); }

.tagline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.stage {
  position: relative;
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  background: #fff;
  aspect-ratio: 3 / 1;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(2px);
  transition: opacity 0.2s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.panel { text-align: center; padding: 24px; }
.panel h2 { font-size: 28px; margin: 0 0 6px; }
.panel p { color: var(--muted); margin: 0 0 16px; }

.btn {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  padding: 12px 22px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
  font-family: inherit;
}
.btn:hover { background: #ff5733; }
.btn:active { transform: scale(0.96); }
.btn.ghost { background: #eef0f4; color: var(--ink); }
.btn.ghost:hover { background: #e3e6ec; }
.btn.small { padding: 8px 16px; font-size: 13px; }

.hud {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 16px 0 8px;
}
.score-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 20px;
  text-align: center;
  min-width: 96px;
}
.score-box .label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 2px;
}
.score-box span:last-child,
#score, #best {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.leaderboard {
  margin-top: 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}
.leaderboard h3 { margin: 0 0 14px; font-size: 18px; }
.lb-sub { color: var(--muted); font-size: 13px; font-weight: 500; }

.lb-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  counter-reset: rank;
}
.lb-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.lb-list li:last-child { border-bottom: none; }
.lb-list .rank {
  width: 28px;
  height: 28px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #f0f0f4;
  font-weight: 800;
  font-size: 13px;
}
.lb-list li:nth-child(1) .rank { background: var(--gold); color: #fff; }
.lb-list li:nth-child(2) .rank { background: var(--silver); color: #fff; }
.lb-list li:nth-child(3) .rank { background: var(--bronze); color: #fff; }
.lb-list .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .pts { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }
.lb-list .when { color: var(--muted); font-size: 12px; flex: none; }
.lb-empty { color: var(--muted); justify-content: center; }

.foot {
  text-align: center;
  margin-top: 28px;
  color: var(--muted);
  font-size: 13px;
}

/* 모달 */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 30, 0.5);
  z-index: 50;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-card {
  background: #fff;
  border-radius: 18px;
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal-card h3 { margin: 0 0 4px; font-size: 24px; }
.final-score { color: var(--muted); margin: 0 0 18px; }
.final-score b { color: var(--accent); font-size: 20px; }
.modal-card label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
#nickInput {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  text-align: center;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}
#nickInput:focus { border-color: var(--accent); }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.modal-actions .btn { flex: 1; }
.save-msg { font-size: 13px; margin: 12px 0 0; min-height: 18px; }
.save-msg.ok { color: #1aa260; }
.save-msg.err { color: var(--accent); }

@media (max-width: 600px) {
  .logo { font-size: 32px; }
  .panel h2 { font-size: 22px; }
}
