:root {
  --bg: #fde7d3; --bg2: #fffaf3; --panel: #fff; --line: rgba(146, 64, 14, 0.16);
  --text: #3b2414; --dim: #8a6a55; --accent: #e11d48; --green: #16a34a; --gold: #d97706; --ok: #059669; --bad: #dc2626;
  --r: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: linear-gradient(160deg, #fce7f3 0%, #fde7d3 45%, #dcfce7 100%);
  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; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
[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.75); border: 1px solid var(--line); color: var(--text);
  text-decoration: none; font-size: 0.85rem; font-weight: 700;
}
.back-btn:hover { background: #fff; }
.total { margin-left: auto; font-weight: 800; }
.total small { color: var(--dim); font-weight: 500; }
.tools { display: flex; gap: 6px; }
.mini { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,0.75); font-weight: 800; }

/* ── 메뉴 ── */
.screen { flex: 1; overflow-y: auto; padding: 4px 16px 32px; }
.logo { text-align: center; margin: 2px 0 12px; }
.logo-fruits { display: inline-flex; gap: 2px; font-size: 1.7rem; }
.logo-fruits span { display: inline-block; animation: bob 2.2s ease-in-out infinite; }
.logo-fruits span:nth-child(2) { animation-delay: 0.15s; } .logo-fruits span:nth-child(3) { animation-delay: 0.3s; }
.logo-fruits span:nth-child(4) { animation-delay: 0.45s; } .logo-fruits span:nth-child(5) { animation-delay: 0.6s; font-size: 2.1rem; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
.logo h1 { margin: 4px 0 4px; font-size: 1.6rem; letter-spacing: -0.5px; }
.logo h1 span { color: var(--green); }
.tagline { margin: 0; color: var(--dim); font-size: 0.9rem; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-width: 720px; margin: 0 auto 12px; }
.tab { padding: 9px 2px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.7); font-size: 0.82rem; font-weight: 800; white-space: nowrap; }
.tab.on { background: #fff; border-color: var(--accent); color: var(--accent); box-shadow: 0 3px 10px rgba(225,29,72,0.15); }
.panel-wrap { max-width: 720px; margin: 0 auto; display: grid; gap: 12px; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; box-shadow: 0 4px 14px rgba(146,64,14,0.06); }
.card h2 { margin: 0 0 4px; font-size: 1.05rem; display: flex; gap: 8px; align-items: baseline; }
.card h2 small { margin-left: auto; color: var(--gold); font-size: 0.85rem; white-space: nowrap; }
.card p { margin: 0 0 10px; color: var(--dim); font-size: 0.84rem; line-height: 1.5; }
.card p b { color: var(--text); }
.card.resume { border-color: var(--green); background: #f0fdf4; }
.lv-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) { .lv-grid { grid-template-columns: repeat(6, 1fr); } }
.lv-btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 100px; text-align: center;
}
.lv-btn b { font-size: 0.95rem; }
.lv-btn.clear { border-color: rgba(5,150,105,0.4); background: #f0fdf4; }
.lv-btn.locked { opacity: 0.45; }
.lv-name { font-size: 0.74rem; font-weight: 700; }
.lv-goal { font-size: 0.66rem; color: var(--dim); line-height: 1.25; }
.lv-stars { color: var(--gold); letter-spacing: 1px; margin-top: auto; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats3 div { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.stats3 small { display: block; color: var(--dim); font-size: 0.72rem; }
.stats3 b { font-size: 1.05rem; }
.rule { display: flex; gap: 10px; align-items: center; background: #fff; border: 1px dashed var(--accent); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.rule > span { font-size: 1.8rem; }
.rule small { display: block; color: var(--dim); }
.plain { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 4px; font-size: 0.86rem; }
.plain li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 2px; border-bottom: 1px dashed var(--line); }
.dex { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.dex-item { text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.dex-item canvas { width: 48px; height: 48px; display: block; margin: 0 auto; }
.dex-item small { font-size: 0.7rem; font-weight: 700; }
.dex-item.locked small { color: var(--dim); }
.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.ach-item { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 12px; border: 1px solid var(--line); background: #fff; opacity: 0.5; filter: grayscale(1); }
.ach-item.on { opacity: 1; filter: none; border-color: rgba(217,119,6,0.4); background: #fffbeb; }
.ach-item > span { font-size: 1.3rem; }
.ach-item b { display: block; font-size: 0.82rem; }
.ach-item small { color: var(--dim); font-size: 0.72rem; }

.btn { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 9px 14px; font-weight: 800; }
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: linear-gradient(160deg, #f43f5e, #e11d48); color: #fff; border-color: transparent; box-shadow: 0 4px 12px rgba(225,29,72,0.3); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn.big { width: 100%; padding: 12px; font-size: 1.05rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ── 플레이 ── */
#play { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 0 10px; padding-bottom: env(safe-area-inset-bottom); min-height: 0; }
.p-head { width: 100%; max-width: 480px; display: flex; align-items: center; gap: 8px; }
.p-title { flex: 1; text-align: center; font-weight: 800; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud { width: 100%; max-width: 480px; display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; justify-content: center; }
.chip { background: rgba(255,255,255,0.85); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 0.8rem; white-space: nowrap; }
.chip b { font-variant-numeric: tabular-nums; }
.chip.goal { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip.goal span.ok { color: var(--ok); text-decoration: line-through; }
.board-wrap { position: relative; width: 100%; max-width: 480px; display: flex; justify-content: center; }
.board-wrap canvas { display: block; border-radius: 14px; box-shadow: 0 0 0 5px #b45309, 0 0 0 8px #78350f, 0 12px 26px rgba(120,53,15,0.3); touch-action: none; background: #fff7ed; }
.board-wrap.shake { animation: shake 0.3s; }
@keyframes shake { 20% { transform: translate(-4px, 2px); } 40% { transform: translate(4px, -2px); } 60% { transform: translate(-3px, 1px); } 80% { transform: translate(2px, 0); } }
.warn-banner { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); background: var(--bad); color: #fff; font-weight: 900; padding: 6px 14px; border-radius: 999px; animation: blink 0.5s infinite alternate; pointer-events: none; }
@keyframes blink { to { opacity: 0.55; } }
.toast { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); background: rgba(59,36,20,0.9); color: #fff; padding: 7px 14px; border-radius: 999px; font-size: 0.84rem; font-weight: 700; pointer-events: none; white-space: nowrap; }
.controls { display: flex; gap: 10px; align-items: stretch; justify-content: center; margin: 10px 0 6px; }
.tool, .next-box { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 76px; padding: 4px 10px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255,255,255,0.85); font-size: 0.75rem; font-weight: 800; }
.tool canvas, .next-box canvas { width: 42px; height: 42px; }
.tool i { font-style: normal; font-size: 1.6rem; line-height: 42px; }
.tool.used { opacity: 0.5; }
.tool.on { border-color: #0ea5e9; background: #e0f2fe; box-shadow: 0 0 0 2px #0ea5e9; }
.tool:disabled { opacity: 0.4; }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(59,36,20,0.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-box { background: var(--bg2); border-radius: 20px; padding: 18px; max-width: 420px; width: 100%; max-height: 90vh; overflow-y: auto; text-align: center; box-shadow: 0 20px 40px rgba(0,0,0,0.25); }
.modal-box h2 { margin: 0 0 8px; }
.modal-box p { color: var(--dim); font-size: 0.9rem; line-height: 1.5; }
.modal-box .plain { text-align: left; }
.big-stars { font-size: 2.4rem; color: var(--gold); letter-spacing: 4px; }
.big-stars i { font-style: normal; color: #e7d5c5; }
.final { font-size: 2.4rem; font-weight: 900; color: var(--accent); }
.new { color: var(--ok) !important; font-weight: 800; }
.ach-new { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.ach-new span { background: #fffbeb; border: 1px solid rgba(217,119,6,0.4); border-radius: 999px; padding: 4px 10px; font-size: 0.82rem; font-weight: 800; }
.help { text-align: left; padding-left: 18px; font-size: 0.88rem; line-height: 1.55; margin: 0 0 12px; }
.help li { margin-bottom: 4px; }
.err { text-align: left; white-space: pre-wrap; font-size: 0.75rem; background: #fff; padding: 8px; border-radius: 8px; max-height: 120px; overflow: auto; }
.noscript { text-align: center; padding: 40px; }

@media (max-width: 380px) {
  .back-txt { display: none; }
  .tab { font-size: 0.74rem; }
}
