:root {
  --bg: #2a1336; --bg2: #3b1d4a; --panel: #50285f; --line: rgba(255,255,255,0.14);
  --text: #fff4fb; --dim: #d8b9d8; --accent: #ffd34d; --pink: #ff6fb1; --go: #6ee7a0; --red: #ff5a6e;
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #5a2a6e, var(--bg) 70%);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  background: rgba(255,255,255,0.1); border: 1px solid var(--line); color: var(--text);
  text-decoration: none; font-size: 0.85rem; font-weight: 600;
}
.back-btn:hover { background: rgba(255,255,255,0.18); }
.total { margin-left: auto; font-weight: 700; }
.total small { color: var(--dim); font-weight: 500; }
.ham-count { font-weight: 700; }
.tools { display: flex; gap: 6px; }
.mini { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,0.1); font-weight: 700; }

.screen { flex: 1; overflow-y: auto; padding: 4px 16px 32px; }
.logo { text-align: center; margin: 4px 0 12px; }
.logo-candy { font-size: 3rem; display: inline-block; animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-8deg); } 50% { transform: translateY(-8px) rotate(8deg); } }
.logo h1 { margin: 2px 0 4px; font-size: 1.6rem; letter-spacing: -0.5px; background: linear-gradient(90deg, #ff8fc4, #ffd34d, #8fe3ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { margin: 0; color: var(--dim); font-size: 0.9rem; }

.tabs { display: flex; gap: 6px; justify-content: center; margin: 0 auto 12px; max-width: 720px; }
.tab { flex: 1; max-width: 160px; border: 1px solid var(--line); background: var(--bg2); border-radius: 999px; padding: 8px 6px; font-weight: 700; font-size: 0.9rem; }
.tab.on { background: var(--pink); color: #3a0a22; border-color: var(--pink); }

.zones, .chal, .rec { max-width: 720px; margin: 0 auto; display: grid; gap: 14px; }
.zone { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.zone h2 { margin: 0 0 2px; font-size: 1.05rem; display: flex; gap: 8px; align-items: baseline; }
.zone h2 small { margin-left: auto; color: var(--accent); font-size: 0.85rem; }
.zone p { margin: 0 0 10px; color: var(--dim); font-size: 0.82rem; }
.lv-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lv-btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 7px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 62px;
}
.lv-btn:hover:not(:disabled) { border-color: var(--pink); }
.lv-btn b { font-size: 0.95rem; }
.lv-btn span { font-size: 0.75rem; }
.lv-btn i { font-style: normal; font-size: 0.72rem; letter-spacing: 1px; color: var(--accent); }
.lv-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.lv-btn.cleared { background: #63306f; }
.lv-btn.perfect { background: #6b5320; border-color: #b8952f; }

.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.card h2 { margin: 0 0 4px; font-size: 1.1rem; }
.card p { margin: 0 0 10px; color: var(--dim); font-size: 0.86rem; line-height: 1.5; }
.card .meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.85rem; margin-bottom: 10px; }
.card .meta b { color: var(--accent); }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--panel); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.3rem; color: var(--accent); }
.stat span { font-size: 0.78rem; color: var(--dim); }

#play { flex: 1; display: flex; flex-direction: column; justify-content: center; min-height: 0; padding: 0 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); max-width: 560px; width: 100%; margin: 0 auto; }
.p-head { display: flex; align-items: center; gap: 8px; }
.p-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-title b { color: var(--accent); }
.moves { margin-left: auto; display: flex; flex-direction: column; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 2px 12px; min-width: 64px; }
.moves small { font-size: 0.66rem; color: var(--dim); }
.moves b { font-size: 1.35rem; line-height: 1.1; }
.moves.low b { color: var(--red); animation: blink 0.7s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.45; } }

.goals { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.goal { display: flex; align-items: center; gap: 5px; background: rgba(255,255,255,0.08); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px 3px 4px; font-weight: 800; font-size: 0.95rem; }
.goal canvas, .goal .gi { width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.goal.done { border-color: var(--go); }
.goal.done b { color: var(--go); }
.goal.bump { animation: gbump 0.25s; }
@keyframes gbump { 50% { transform: scale(1.12); } }

.scorebar { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.sb-score { min-width: 70px; font-weight: 800; font-size: 1.05rem; color: var(--accent); text-align: right; }
.sb-track { position: relative; flex: 1; height: 10px; border-radius: 99px; background: rgba(255,255,255,0.12); }
.sb-fill { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--pink), var(--accent)); transition: width 0.3s ease-out; }
.sb-star { position: absolute; top: 50%; transform: translate(-50%, -50%); font-style: normal; font-size: 1rem; color: rgba(255,255,255,0.3); text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.sb-star.on { color: var(--accent); }

.board { flex: 1; min-height: 0; position: relative; margin-top: 8px; }
.board canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.msg {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  font-size: 1.9rem; font-weight: 900; color: #fff; text-align: center; pointer-events: none; white-space: nowrap;
  text-shadow: 0 3px 0 #b8327a, 0 0 18px rgba(255,111,177,0.8);
  animation: pop 0.9s ease-out forwards;
}
.msg small { display: block; font-size: 0.9rem; font-weight: 700; text-shadow: 0 2px 0 rgba(0,0,0,0.5); }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } 20% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 35% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1); } }

.toolbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; padding-top: 8px; }
.tool {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 6px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 1.15rem; min-height: 52px;
}
.tool span { font-size: 0.68rem; color: var(--dim); }
.tool.on { background: #8a5a12; border-color: var(--accent); }
.tool:disabled { opacity: 0.4; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 16px; font-weight: 700; }
.btn.small { padding: 6px 10px; font-size: 0.82rem; }
.btn.primary { background: #d63f86; border-color: var(--pink); }
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.45; }

.modal { position: fixed; inset: 0; background: rgba(20,0,20,0.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.panel { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 18px; max-width: 440px; width: 100%; max-height: 90vh; overflow-y: auto; }
.panel h2 { margin: 0 0 10px; }
.panel p, .panel li { color: #f3e3f2; font-size: 0.9rem; line-height: 1.55; }
.panel ul { padding-left: 18px; margin: 6px 0; }
.panel .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.panel .goals { margin: 8px 0; }
.result { text-align: center; }
.result .big { font-size: 1.8rem; font-weight: 900; color: var(--accent); margin: 4px 0; }
.stars { font-size: 2.4rem; letter-spacing: 6px; margin: 4px 0; }
.stars .off { filter: grayscale(1); opacity: 0.3; }
.stars span { display: inline-block; animation: starin 0.4s backwards; }
.stars span:nth-child(2) { animation-delay: 0.25s; } .stars span:nth-child(3) { animation-delay: 0.5s; }
@keyframes starin { from { transform: scale(0) rotate(-90deg); } }
.legend { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; font-size: 0.86rem; margin: 8px 0; }
.legend canvas { width: 34px; height: 34px; }
.legend .gi { font-size: 1.4rem; text-align: center; }
.err h2 { color: var(--red); }
.noscript { padding: 20px; text-align: center; }

@media (max-width: 420px) {
  .back-txt { display: none; }
  .lv-grid { gap: 6px; }
  .topbar { gap: 8px; }
}

/* 업적 */
.card h2 small { color: var(--accent); font-size: 0.85rem; margin-left: 6px; }
.ach-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.ach-list li { display: flex; gap: 10px; align-items: center; background: var(--panel); border-radius: 12px; padding: 8px 10px; opacity: 0.55; }
.ach-list li.on { opacity: 1; border: 1px solid rgba(255, 211, 77, 0.45); }
.ach-list .ai { font-size: 1.4rem; width: 1.6rem; text-align: center; flex: none; }
.ach-list b { display: block; font-size: 0.88rem; }
.ach-list small { color: var(--dim); font-size: 0.74rem; line-height: 1.35; }
.ach-got { margin: 10px auto 0; padding: 10px; border-radius: 12px; background: rgba(255, 211, 77, 0.14); border: 1px solid rgba(255, 211, 77, 0.45); display: flex; flex-direction: column; gap: 4px; animation: gbump 0.4s; }
.ach-got small { color: var(--accent); font-weight: 700; }

/* 시작 부스터 */
.boosts { margin: 10px 0 0; }
.boosts .bh { margin: 0 0 6px; font-weight: 700; }
.boosts .bh small { display: block; color: var(--dim); font-weight: 500; font-size: 0.78rem; }
.boost-row { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.boost { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 84px; padding: 6px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 0.8rem; font-weight: 700; }
.boost small { display: block; color: var(--dim); font-weight: 500; }
.boost.on { border-color: var(--accent); background: #6b5320; box-shadow: 0 0 0 2px rgba(255, 211, 77, 0.35); }
.boost:disabled { opacity: 0.4; cursor: not-allowed; }
