:root {
  --bg: #0b1020; --panel: #121a2e; --panel2: #18223b; --line: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9; --dim: #94a3b8; --accent: #f59e0b; --accent2: #fbbf24; --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%, #1e293b 0%, #0b1020 60%, #05070f 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; }
.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: var(--panel); font-weight: 800; }

/* ── 메뉴 ── */
.screen { flex: 1; overflow-y: auto; padding: 4px 16px 32px; }
.logo { text-align: center; margin: 2px 0 12px; }
.logo-sand { display: inline-flex; gap: 4px; align-items: flex-end; height: 34px; }
.logo-sand i { width: 18px; border-radius: 4px 4px 2px 2px; animation: pile 2.4s ease-in-out infinite; }
.logo-sand i:nth-child(1) { background: #38bdf8; height: 14px; }
.logo-sand i:nth-child(2) { background: #f59e0b; height: 24px; animation-delay: 0.2s; }
.logo-sand i:nth-child(3) { background: #ef4444; height: 32px; animation-delay: 0.4s; }
.logo-sand i:nth-child(4) { background: #22c55e; height: 22px; animation-delay: 0.6s; }
.logo-sand i:nth-child(5) { background: #a855f7; height: 12px; animation-delay: 0.8s; }
@keyframes pile { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(0.7); } }
.logo-sand i { transform-origin: bottom; }
.logo h1 { margin: 6px 0 4px; font-size: 1.6rem; letter-spacing: -0.5px; }
.logo h1 span { background: linear-gradient(135deg, #facc15, #f59e0b, #ef4444); -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(4, 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.82rem; 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(245,158,11,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); }
.card.resume { border-color: var(--ok); background: #0f2a24; }
.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(--panel2); border-radius: 12px; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 100px; text-align: center;
}
.lv-btn:hover:not(:disabled) { border-color: var(--accent); }
.lv-btn b { font-size: 0.95rem; }
.lv-btn.clear { border-color: rgba(52,211,153,0.45); background: #11281f; }
.lv-btn.locked { opacity: 0.4; }
.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: 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; }

.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, #fbbf24, #f59e0b 50%, #d97706); color: #1c1203; border-color: transparent; box-shadow: 0 4px 14px rgba(245,158,11,0.3); }
.btn.danger-text { 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: max(6px, env(safe-area-inset-bottom)); min-height: 0; }
.p-head { width: 100%; max-width: 480px; 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: 480px; display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; 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 { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; border-color: rgba(245,158,11,0.4); }
.chip.goal span.ok { color: var(--ok); text-decoration: line-through; }
.chip.low { border-color: var(--bad); color: var(--bad); }
.arena { flex: 1; min-height: 0; width: 100%; max-width: 480px; display: flex; gap: 8px; justify-content: center; align-items: stretch; }
.side { display: flex; flex-direction: column; gap: 6px; width: 66px; flex: none; }
.box { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 3px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 0.7rem; font-weight: 800; color: var(--dim); }
.box canvas { width: 58px; height: 44px; }
.box canvas.sm { width: 46px; height: 34px; opacity: 0.8; }
.box.hold:hover:not(:disabled) { border-color: var(--accent); }
.box.hold.used { opacity: 0.5; }
.box.hold:disabled { opacity: 0.3; }
.box.lines b { font-size: 1.15rem; color: var(--text); }
.board-wrap { position: relative; flex: 0 1 auto; display: flex; justify-content: center; align-items: flex-start; min-height: 0; }
.board-wrap canvas { display: block; border-radius: 10px; box-shadow: 0 0 0 3px #334155, 0 0 0 6px #1e293b, 0 0 30px rgba(245,158,11,0.15); touch-action: none; background: #101422; }
.toast { position: absolute; top: 34%; left: 50%; transform: translateX(-50%); background: rgba(15,23,42,0.92); border: 1px solid var(--line); color: #fff; padding: 7px 14px; border-radius: 999px; font-size: 0.86rem; 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,16,32,0.78); border-radius: 10px; }
.paused b { font-size: 1.4rem; }
.controls { width: 100%; max-width: 480px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 8px 0 2px; }
.cbtn { height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-size: 1.25rem; font-weight: 900; touch-action: manipulation; }
.cbtn:active, .cbtn.on { background: #334155; transform: scale(0.96); }
.cbtn.wide { grid-column: 1 / -1; height: 46px; font-size: 1rem; background: linear-gradient(160deg, #fbbf24, #d97706); color: #1c1203; border-color: transparent; }
.hint { margin: 4px 0 0; font-size: 0.72rem; color: var(--dim); text-align: center; }
@media (hover: hover) and (pointer: fine) { .controls { display: none; } .hint { display: block; } }
@media (max-height: 640px) { .hint { display: none; } .cbtn { height: 42px; } .cbtn.wide { height: 40px; } }

/* ── 모달 ── */
.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; }

@media (max-width: 380px) {
  .back-txt { display: none; }
  .tab { font-size: 0.74rem; }
  .side { width: 58px; }
  .box canvas { width: 50px; height: 38px; }
}
