/* 수박게임 — 원본풍 크림/우드 테마, 모바일 우선 */
:root {
  --cream: #f8e8c8;
  --cream-light: #fff9ea;
  --wood: #a9743f;
  --wood-dark: #7a4a21;
  --wood-line: #e0c9a0;
  --ink: #3a2a20;
  --accent: #f07f2e;
  --accent-dark: #c75e14;
  --danger: #e0603a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: linear-gradient(180deg, #fdf1d6 0%, var(--cream) 100%);
  color: var(--ink);
  font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Segoe UI', sans-serif;
  word-break: keep-all;
  overflow-wrap: break-word;
  overscroll-behavior: none;
  min-height: 100dvh;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--wood-line);
  border-radius: 12px;
  background: #fff;
  font-size: 16px;
  color: var(--ink);
  outline: none;
}
input:focus { border-color: var(--wood); }

#app { min-height: 100dvh; }
.screen { display: flex; justify-content: center; min-height: 100dvh; }
.home-wrap, .game-wrap {
  width: 100%;
  max-width: 460px;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}

/* ---------- 홈 ---------- */
.logo-row { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
#logo-canvas { width: 76px; height: 76px; flex: none; }
.game-title {
  font-family: 'Jua', 'Malgun Gothic', sans-serif;
  font-size: 40px;
  margin: 0;
  color: var(--wood-dark);
  letter-spacing: 1px;
}
.game-sub { margin: 2px 0 0; color: var(--wood); font-size: 14px; }

.nick-box {
  background: var(--cream-light);
  border: 2px solid var(--wood-line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 14px;
}
.nick-label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 8px; color: var(--wood-dark); }
.nick-label small { font-weight: 400; color: var(--wood); }
.pin-details { margin-top: 10px; font-size: 13px; color: var(--wood); }
.pin-details summary { cursor: pointer; user-select: none; }
.pin-details input { margin-top: 8px; }
.pin-help { margin: 8px 0 0; font-size: 12px; line-height: 1.5; color: #9a7b52; }

.mode-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.mode-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--cream-light);
  border: 2px solid var(--wood-line);
  border-radius: 16px;
  padding: 12px 14px;
  transition: transform .08s ease, border-color .08s ease;
}
.mode-card:active { transform: scale(0.98); border-color: var(--wood); }
.mode-icon { width: 52px; height: 52px; flex: none; }
.mode-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.mode-text strong { font-family: 'Jua', sans-serif; font-size: 19px; color: var(--wood-dark); }
.mode-text span { font-size: 13px; color: #8a6a45; }
.mode-best { font-style: normal; font-size: 12px; color: var(--accent-dark); min-height: 15px; }
.mode-go { color: var(--wood); font-size: 16px; flex: none; }

.home-btns { display: flex; gap: 10px; }
.home-btns .btn { flex: 1; }
.home-foot { text-align: center; font-size: 12px; color: #a98c60; margin-top: 18px; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 2px solid var(--wood);
  background: var(--cream-light);
  color: var(--wood-dark);
  font-family: 'Jua', sans-serif;
  font-size: 16px;
  text-decoration: none;
  transition: transform .08s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.btn.ghost { border-color: var(--wood-line); background: transparent; }
.btn.tiny { padding: 4px 10px; font-size: 13px; border-radius: 8px; }

/* ---------- 게임 HUD ---------- */
.game-wrap { user-select: none; -webkit-user-select: none; padding-top: 12px; }
.hud { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.icon-btn {
  width: 40px; height: 40px;
  flex: none;
  border: none;
  border-radius: 12px;
  background: rgba(169, 116, 63, 0.14);
  font-size: 18px;
  color: var(--wood-dark);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(169, 116, 63, 0.28); }
.hud-mid { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.score-panel {
  background: var(--wood);
  border-radius: 14px;
  padding: 5px 16px;
  display: flex; flex-direction: column; align-items: center;
  min-width: 86px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15);
}
.score-label { font-size: 11px; color: #f3ddb8; }
#hud-score { font-family: 'Jua', sans-serif; font-size: 26px; color: #fff; line-height: 1.1; }
.speed-panel {
  display: flex; flex-direction: column; align-items: center;
  background: var(--cream-light);
  border: 2px solid var(--wood-line);
  border-radius: 14px;
  padding: 4px 12px;
}
#hud-time { font-family: 'Jua', sans-serif; font-size: 20px; color: var(--danger); line-height: 1.1; }
#hud-melons { font-size: 12px; color: var(--wood-dark); }
.next-box {
  flex: none;
  display: flex; flex-direction: column; align-items: center;
  background: var(--cream-light);
  border: 2px solid var(--wood-line);
  border-radius: 14px;
  padding: 3px 8px 5px;
}
.next-label { font-size: 10px; color: var(--wood); }
#next-canvas { width: 40px; height: 40px; }

.mode-chip {
  text-align: center;
  font-size: 12px;
  color: var(--wood);
  margin: 0 0 6px;
}
.mode-chip.m-speedrun { color: var(--danger); font-weight: 700; }
.mode-chip.m-daily { color: #4a7a2e; font-weight: 700; }

#stage { position: relative; width: 100%; }
#game-canvas {
  display: block;
  width: 100%;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(120, 80, 40, 0.18);
  touch-action: none;
}
#pause-overlay {
  position: absolute; inset: 0;
  background: rgba(60, 35, 15, 0.55);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-family: 'Jua', sans-serif;
  font-size: 30px;
  text-align: center;
  line-height: 1.5;
  z-index: 5;
}
#pause-overlay small { font-size: 15px; opacity: 0.85; }

#chain-strip {
  display: flex;
  align-items: center;
  gap: 1px;
  overflow-x: auto;
  padding: 8px 2px 2px;
  scrollbar-width: none;
}
#chain-strip::-webkit-scrollbar { display: none; }
.chain-fruit { width: 24px; height: 24px; flex: none; opacity: 0.55; }
.chain-fruit.reached { opacity: 1; }
.chain-arrow { color: #c4a06a; font-size: 10px; flex: none; }
.hint { font-size: 11px; color: #a98c60; text-align: center; margin: 6px 0 0; line-height: 1.5; }
@media (pointer: coarse) { .hint-kbd { display: none; } }

/* ---------- 오버레이 / 모달 ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(60, 35, 15, 0.45);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  z-index: 50;
}
.modal {
  background: var(--cream-light);
  border-radius: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 18px;
  box-shadow: 0 12px 40px rgba(60, 35, 15, 0.35);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { font-family: 'Jua', sans-serif; margin: 0; font-size: 24px; color: var(--wood-dark); }
.modal-head .icon-btn { background: transparent; font-size: 16px; }

/* 결과 */
.result-modal { text-align: center; }
.result-emoji { font-size: 54px; line-height: 1.2; }
.result-modal h2 { font-family: 'Jua', sans-serif; font-size: 28px; color: var(--wood-dark); margin: 6px 0 10px; }
.result-big { font-family: 'Jua', sans-serif; font-size: 46px; color: var(--accent-dark); line-height: 1.15; }
.result-sub { font-size: 13px; color: #8a6a45; margin-top: 2px; }
.result-rank { margin: 12px 0 4px; font-size: 16px; color: var(--wood-dark); min-height: 24px; }
.result-rank b { color: var(--danger); font-size: 19px; }
.rank-err { color: var(--danger); font-size: 13px; }
.result-badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; min-height: 8px; margin-bottom: 10px; }
.badge-chip {
  background: #ffe9b8;
  border: 1.5px solid #e8c476;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--wood-dark);
}
.badge-chip.new { animation: pop-in .4s ease; }
@keyframes pop-in { 0% { transform: scale(0); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.result-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* 랭킹 */
.board-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.board-tabs button, .board-period button {
  flex: 1;
  padding: 8px 4px;
  border: 2px solid var(--wood-line);
  background: transparent;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  color: #8a6a45;
}
.board-tabs button.active, .board-period button.active {
  background: var(--wood);
  border-color: var(--wood);
  color: #fff;
}
.board-period { display: flex; gap: 6px; margin-bottom: 8px; }
.board-period button { flex: none; padding: 5px 14px; font-size: 12px; }
.board-info { font-size: 12px; color: var(--wood); margin-bottom: 8px; text-align: center; }
.board-body { min-height: 120px; }
.board-loading, .board-empty { text-align: center; color: #a98c60; padding: 30px 0; font-size: 14px; line-height: 1.7; }
.board-table { width: 100%; border-collapse: collapse; }
.board-row td { padding: 8px 4px; border-bottom: 1.5px dashed var(--wood-line); font-size: 14px; }
.board-row.me td { background: #ffe9b8; }
.b-rank { width: 38px; text-align: center; font-family: 'Jua', sans-serif; font-size: 16px; color: var(--wood); }
.b-nick { font-weight: 700; color: var(--ink); }
.mini-badge { font-size: 12px; margin-left: 2px; }
.b-val { text-align: right; font-family: 'Jua', sans-serif; font-size: 16px; color: var(--accent-dark); white-space: nowrap; }
.b-date { width: 44px; text-align: right; font-size: 11px; color: #a98c60; }

/* 프로필 */
.profile-row { display: flex; gap: 8px; margin-bottom: 14px; }
.profile-row input { flex: 1; }
.profile-best { display: flex; gap: 8px; margin-bottom: 14px; }
.pb-cell {
  flex: 1;
  background: #f6ead0;
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  display: flex; flex-direction: column; gap: 3px;
}
.pb-mode { font-size: 11px; color: var(--wood); }
.pb-cell b { font-family: 'Jua', sans-serif; font-size: 18px; color: var(--wood-dark); }
.pb-rank { font-size: 11px; color: var(--danger); font-weight: 700; }
.badge-title { font-family: 'Jua', sans-serif; font-size: 18px; color: var(--wood-dark); margin: 4px 0 8px; }
.badge-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.badge-card {
  background: #f6ead0;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
  opacity: 0.45;
  filter: grayscale(0.8);
}
.badge-card.got { opacity: 1; filter: none; background: #ffe9b8; border-color: #e8c476; }
.badge-icon { font-size: 26px; }
.badge-name { font-weight: 700; font-size: 13px; color: var(--wood-dark); margin-top: 2px; }
.badge-desc { font-size: 11px; color: #9a7b52; margin-top: 2px; line-height: 1.4; }

/* 자랑 카드 */
.share-modal { text-align: center; display: flex; flex-direction: column; }
#share-img { max-width: 100%; max-height: 56dvh; width: auto; margin: 0 auto; border-radius: 12px; border: 2px solid var(--wood-line); }
.share-btns { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.share-tip { font-size: 12px; color: #a98c60; margin: 10px 0 0; }

/* 토스트 */
#toast {
  position: fixed;
  left: 50%; bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 100;
  max-width: 86vw;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

@media (min-width: 700px) {
  .home-wrap { max-width: 480px; padding-top: 40px; }
  .game-wrap { padding-top: 20px; }
  .badge-grid { grid-template-columns: repeat(4, 1fr); }
}