:root {
  --bg: #0b1324; --panel: #111c33; --panel2: #172442; --line: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9; --dim: #94a3b8; --accent: #38bdf8; --accent2: #7dd3fc; --ok: #34d399; --bad: #f87171; --gold: #facc15;
  --r: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #1e2a52 0%, #0b1324 60%, #050912 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(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.3); color: #7dd3fc;
  text-decoration: none; font-size: 0.85rem; font-weight: 700;
}
.back-btn:hover { background: rgba(56, 189, 248, 0.22); }
.total { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.tools { display: flex; gap: 6px; }
.mini { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-weight: 800; }

/* ── 메뉴 ── */
.screen { flex: 1; overflow-y: auto; padding: 4px 16px 32px; }
.logo { text-align: center; margin: 2px 0 12px; }
.logo-bubbles { display: inline-flex; gap: 6px; align-items: center; height: 36px; }
.logo-bubbles i {
  width: 24px; height: 24px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0%, rgba(125,211,252,0.6) 32%, rgba(14,116,144,0.8) 75%, #082f49 100%);
  box-shadow: 0 3px 6px rgba(0,0,0,0.4); animation: bob 2.2s ease-in-out infinite;
}
.logo-bubbles i:nth-child(2) { animation-delay: 0.2s; background: radial-gradient(circle at 35% 30%, #fff 0%, #fde047 32%, #ca8a04 75%, #713f12 100%); }
.logo-bubbles i:nth-child(3) { animation-delay: 0.4s; width: 30px; height: 30px; }
.logo-bubbles i:nth-child(4) { animation-delay: 0.6s; background: radial-gradient(circle at 35% 30%, #fff 0%, #c4b5fd 32%, #6d28d9 75%, #2e1065 100%); }
.logo-bubbles i:nth-child(5) { animation-delay: 0.8s; }
@keyframes bob { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-5px) scale(0.92); } }
.logo h1 { margin: 6px 0 4px; font-size: 1.6rem; letter-spacing: -0.5px; }
.logo h1 span { background: linear-gradient(135deg, #e0f2fe, #38bdf8, #a78bfa); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { margin: 0 auto; color: var(--dim); font-size: 0.88rem; max-width: 420px; line-height: 1.5; }
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; max-width: 720px; margin: 0 auto 12px; }
.tab { padding: 9px 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 0.8rem; font-weight: 800; white-space: nowrap; }
.tab.on { border-color: var(--accent); color: var(--accent2); box-shadow: 0 0 0 1px var(--accent) inset, 0 4px 14px rgba(56,189,248,0.2); }
.panel-wrap { max-width: 720px; margin: 0 auto; display: grid; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.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); }

.skins { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
@media (min-width: 560px) { .skins { grid-template-columns: repeat(3, 1fr); } }
.skin {
  display: flex; gap: 8px; align-items: center; text-align: left; padding: 8px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel2); min-height: 72px;
}
.skin canvas { width: 40px; height: 40px; flex: none; }
.skin b { display: block; font-size: 0.86rem; }
.skin small { color: var(--dim); font-size: 0.7rem; line-height: 1.3; display: block; }
.skin.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.skin.locked { opacity: 0.5; filter: grayscale(0.8); }

.lv-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (min-width: 560px) { .lv-grid { grid-template-columns: repeat(8, 1fr); } }
.lv-btn {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 7px 3px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 92px; text-align: center;
}
.lv-btn:hover:not(:disabled) { border-color: var(--accent); }
.lv-btn b { font-size: 0.92rem; }
.lv-btn.clear { border-color: rgba(52,211,153,0.45); background: #11281f; }
.lv-btn.locked { opacity: 0.4; }
.lv-name { font-size: 0.7rem; font-weight: 700; line-height: 1.2; }
.lv-goal { font-size: 0.62rem; color: var(--dim); line-height: 1.25; }
.lv-stars { color: var(--gold); letter-spacing: 1px; margin-top: auto; font-size: 0.8rem; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats3 div { background: var(--panel2); 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: var(--panel2); 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); }
.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: var(--panel2); opacity: 0.45; filter: grayscale(1); }
.ach-item.on { opacity: 1; filter: none; border-color: rgba(250,204,21,0.45); background: #2a2410; }
.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; }
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 10px; font-size: 0.78rem; color: var(--dim); margin: 0 0 10px; padding: 0; list-style: none; }
.legend b { color: var(--text); }

.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 9px 14px; font-weight: 800; }
.btn:hover { filter: brightness(1.12); }
.btn.primary { background: linear-gradient(160deg, #7dd3fc, #38bdf8 50%, #0284c7); color: #04131f; border-color: transparent; box-shadow: 0 4px 14px rgba(56,189,248,0.3); }
.btn.on { border-color: var(--accent); color: var(--accent2); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn.big { width: 100%; padding: 12px; font-size: 1.05rem; }
.btn.danger-text { color: var(--bad); }
.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: max(6px, env(safe-area-inset-bottom)); min-height: 0; }
.p-head { width: 100%; max-width: 560px; display: flex; align-items: center; gap: 6px; }
.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: 560px; display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 4px; justify-content: center; }
.chip { background: var(--panel); 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 { border-color: rgba(56,189,248,0.4); }
.chip.combo small { color: var(--gold); font-weight: 800; }
.chip.combo.hot { border-color: var(--gold); box-shadow: 0 0 10px rgba(250,204,21,0.35); }
.chip.combo.fever { border-color: #f472b6; color: #f9a8d4; box-shadow: 0 0 14px rgba(244,114,182,0.5); }
.timebar { position: relative; width: 100%; max-width: 560px; height: 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); overflow: hidden; margin-bottom: 4px; }
.timebar i { position: absolute; inset: 0 auto 0 0; width: 100%; background: linear-gradient(90deg, #38bdf8, #a78bfa); transition: width 0.1s linear; }
.timebar.low i { background: linear-gradient(90deg, #f87171, #fb923c); }
.timebar span { position: relative; display: block; text-align: center; font-size: 0.68rem; font-weight: 900; line-height: 12px; text-shadow: 0 1px 2px #000; }
.board-wrap { position: relative; flex: 1; width: 100%; max-width: 560px; min-height: 0; }
.board-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; }
.toast { position: absolute; top: 40%; left: 50%; transform: translateX(-50%); background: rgba(15,23,42,0.92); border: 1px solid var(--line); color: #fff; padding: 8px 16px; border-radius: 999px; font-size: 0.9rem; font-weight: 800; pointer-events: none; white-space: nowrap; }
.paused { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; background: rgba(11,19,36,0.8); border-radius: 14px; }
.paused b { font-size: 1.4rem; }
.zen-bar { width: 100%; max-width: 560px; display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-top: 6px; }
.hint { margin: 4px 0 0; font-size: 0.72rem; color: var(--dim); text-align: center; }
@media (max-height: 620px) { .hint { display: none; } }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(2,6,23,0.7); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-box { background: var(--panel); border: 1px solid var(--line); 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.5); }
.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: #334155; }
.final { font-size: 2.4rem; font-weight: 900; color: var(--accent2); }
.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: #2a2410; border: 1px solid rgba(250,204,21,0.45); 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: #020617; padding: 8px; border-radius: 8px; max-height: 120px; overflow: auto; }
.noscript { text-align: center; padding: 40px; }
.popup { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: #2a2410; border: 1px solid rgba(250,204,21,0.5); border-radius: 999px; padding: 8px 16px; font-weight: 800; font-size: 0.86rem; z-index: 20; animation: up 2.6s ease forwards; pointer-events: none; white-space: nowrap; }
@keyframes up { 0% { opacity: 0; transform: translate(-50%, 10px); } 10%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

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