:root {
  --bg: #06120f; --bg2: #0d1f1b; --panel: #132a25; --line: rgba(148, 210, 190, 0.18);
  --text: #f0fdf9; --dim: #94b8ad; --accent: #34d399; --cyan: #22d3ee; --pink: #f472b6; --gold: #fbbf24; --bad: #f43f5e;
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% -10%, #0f3d33, var(--bg) 65%);
  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; }
[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.07); 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.14); }
.total { margin-left: auto; font-weight: 700; }
.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.07); font-weight: 700; }

/* ── 메뉴 ── */
.screen { flex: 1; overflow-y: auto; padding: 4px 16px 32px; }
.logo { text-align: center; margin: 2px 0 12px; }
.logo-balls { display: inline-flex; gap: 6px; }
.logo-balls i {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-weight: 900; font-size: 0.75rem;
  color: #111; box-shadow: 0 0 14px rgba(52,211,153,0.45), inset -4px -5px 8px rgba(0,0,0,0.35);
  animation: roll 2.6s ease-in-out infinite;
}
.logo-balls .b1 { background: radial-gradient(circle at 50% 50%, #fff 0 32%, #facc15 34%); }
.logo-balls .b8 { background: radial-gradient(circle at 50% 50%, #fff 0 32%, #111827 34%); animation-delay: 0.15s; }
.logo-balls .b11 { background: radial-gradient(circle at 50% 50%, #fff 0 32%, transparent 34%), linear-gradient(#f1f5f9 0 22%, #ef4444 22% 78%, #f1f5f9 78%); animation-delay: 0.3s; }
.logo-balls .b0 { background: #f8fafc; animation-delay: 0.45s; }
@keyframes roll { 0%, 100% { transform: translateX(0); } 40% { transform: translateX(-6px) rotate(-20deg); } 60% { transform: translateX(4px); } }
.logo h1 { margin: 6px 0 4px; font-size: 1.55rem; letter-spacing: -0.5px; text-shadow: 0 0 18px rgba(52,211,153,0.45); }
.logo h1 span { background: linear-gradient(135deg, var(--accent), var(--cyan)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.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: var(--bg2); font-size: 0.82rem; font-weight: 700; white-space: nowrap; }
.tab.on { background: rgba(52,211,153,0.16); border-color: var(--accent); color: #a7f3d0; }
.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; }
.card h2 { margin: 0 0 2px; font-size: 1.05rem; display: flex; gap: 8px; align-items: baseline; }
.card h2 small { margin-left: auto; color: var(--gold); font-size: 0.85rem; }
.card p { margin: 0 0 10px; color: var(--dim); font-size: 0.82rem; line-height: 1.45; }
.card p b { color: var(--text); }
.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: 86px;
}
.lv-btn:hover:not(:disabled) { border-color: var(--accent); }
.lv-btn b { font-size: 1rem; }
.lv-btn span { font-size: 0.7rem; color: var(--dim); text-align: center; line-height: 1.2; }
.lv-btn span.g { color: #a7f3d0; font-size: 0.66rem; }
.lv-btn i { font-style: normal; font-size: 0.78rem; letter-spacing: 1px; color: var(--gold); margin-top: auto; }
.lv-btn:disabled { opacity: 0.38; cursor: not-allowed; }
.lv-btn.cleared { background: #17392f; }
.resume {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid rgba(251,191,36,0.5);
  background: rgba(251,191,36,0.1); font-weight: 800; text-align: left; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap;
}
.resume span { font-weight: 500; font-size: 0.8rem; color: var(--dim); }
.diff-list { display: grid; gap: 8px; }
.diff {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); text-align: left; width: 100%;
}
.diff:hover { border-color: var(--accent); }
.diff .ico { font-size: 1.6rem; }
.diff b { display: block; font-size: 1rem; }
.diff span { color: var(--dim); font-size: 0.8rem; }
.diff .rec { margin-left: auto; text-align: right; color: var(--gold); font-weight: 700; font-size: 0.85rem; white-space: nowrap; }
.diff .rec small { display: block; color: var(--dim); font-weight: 500; }
.daily-rec, .stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 12px; }
.stat-grid { margin: 12px 0 0; }
.daily-rec div, .stat-grid div { background: var(--panel); border-radius: 12px; padding: 10px; text-align: center; }
.daily-rec small, .stat-grid small { display: block; color: var(--dim); font-size: 0.75rem; }
.daily-rec b, .stat-grid b { font-size: 1.25rem; color: var(--gold); }
.big-btn {
  display: block; width: 100%; padding: 14px; border-radius: 14px; border: 0; font-weight: 800; font-size: 1.05rem;
  background: linear-gradient(135deg, #10b981, #0891b2); color: #fff; box-shadow: 0 6px 22px rgba(16,185,129,0.3);
}
.stat-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.stat-table th, .stat-table td { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: center; }
.stat-table th { color: var(--dim); font-weight: 600; }

.btn {
  padding: 10px 16px; border-radius: 12px; border: 0; font-weight: 800;
  background: linear-gradient(135deg, #10b981, #0891b2); color: #fff;
}
.btn.ghost { background: rgba(255,255,255,0.08); border: 1px solid var(--line); }
.btn.danger { color: #fda4af; width: 100%; }
.btn.small { padding: 7px 11px; font-size: 0.85rem; background: rgba(255,255,255,0.08); border: 1px solid var(--line); font-weight: 700; }

/* ── 플레이 ── */
#play { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 12px max(10px, env(safe-area-inset-bottom)); max-width: 1100px; width: 100%; margin: 0 auto; }
.p-head { display: flex; align-items: center; gap: 8px; }
.p-title { flex: 1; text-align: center; font-weight: 800; font-size: 0.98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0 4px; }
.chip { position: relative; padding: 5px 10px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); font-size: 0.82rem; color: var(--dim); display: inline-flex; align-items: center; gap: 4px; }
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.chip.warn { border-color: var(--bad); }
.chip.warn b { color: #fda4af; }
.chip .stars { color: var(--gold); letter-spacing: 1px; }
.pl { display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); font-size: 0.82rem; min-width: 0; transition: border-color 0.2s, box-shadow 0.2s; }
.pl.on { border-color: var(--accent); box-shadow: 0 0 14px rgba(52,211,153,0.35); }
.pl b { white-space: nowrap; }
.pl .grp { color: var(--dim); font-size: 0.72rem; white-space: nowrap; }
.pl .dots { display: inline-flex; gap: 2px; flex-wrap: wrap; }
.dot { width: 13px; height: 13px; border-radius: 50%; display: inline-block; box-shadow: inset -2px -2px 3px rgba(0,0,0,0.35); }
.dot.gone { opacity: 0.18; }

.board-wrap { position: relative; flex: 1; min-height: 200px; touch-action: none; overflow: hidden; }
#cv { position: absolute; left: 0; top: 0; width: 100%; height: 100%; cursor: crosshair; }
.toast {
  position: absolute; left: 50%; top: 6px; transform: translateX(-50%); z-index: 9; pointer-events: none;
  background: rgba(6, 18, 15, 0.92); border: 1px solid var(--accent); border-radius: 999px; padding: 7px 14px;
  font-size: 0.85rem; font-weight: 700; white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis;
}
.toast.bad { border-color: var(--bad); color: #fecdd3; }
.toast.show { animation: tin 0.25s ease-out; }
@keyframes tin { from { opacity: 0; transform: translate(-50%, -8px); } }

.controls { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 6px; max-width: 640px; width: 100%; margin-left: auto; margin-right: auto; }
.controls.off { opacity: 0.45; pointer-events: none; }
.spin {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--line); position: relative;
  background: radial-gradient(circle at 35% 30%, #fff, #cbd5e1 70%, #94a3b8);
}
.spin span { position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #e11d48; box-shadow: 0 0 6px #e11d48; transition: transform 0.15s; }
.fine { flex: none; width: 42px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); font-size: 1.25rem; touch-action: none; }
.fine:active { background: var(--panel); }
.power {
  flex: 1; min-width: 90px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2);
  position: relative; overflow: hidden; touch-action: none; cursor: ew-resize;
}
.power .fill { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #10b981, #facc15 70%, #f43f5e); opacity: 0.85; }
.power span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 0.9rem; text-shadow: 0 1px 2px #000; pointer-events: none; }
.shot {
  flex: none; height: 46px; padding: 0 18px; border-radius: 12px; border: 0; font-weight: 900; font-size: 1rem;
  background: linear-gradient(135deg, #10b981, #0891b2); color: #fff; box-shadow: 0 4px 16px rgba(16,185,129,0.35);
}
.shot:active { transform: translateY(1px); }
.keys { text-align: center; color: var(--dim); font-size: 0.72rem; margin: 6px 0 0; }
@media (hover: none) { .keys { display: none; } }
@media (max-height: 560px) { .keys { display: none; } .hud { margin: 3px 0 2px; } .controls { margin-top: 3px; } }
@media (max-width: 380px) { .fine { width: 36px; } .shot { padding: 0 12px; } .spin { width: 42px; height: 42px; } }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(2, 10, 8, 0.72); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 18px; width: 100%; max-width: 420px;
  max-height: 90vh; overflow-y: auto; text-align: center; animation: tin2 0.22s ease-out;
}
@keyframes tin2 { from { transform: scale(0.92); opacity: 0; } }
.dialog h2 { margin: 0 0 8px; }
.dialog p { margin: 6px 0; color: var(--text); }
.dialog .dim { color: var(--dim); font-size: 0.85rem; }
.dialog .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.big-num { font-size: 2rem; font-weight: 900; color: var(--gold); }
.big-stars { font-size: 2.6rem; letter-spacing: 6px; }
.big-stars span { color: #334155; display: inline-block; }
.big-stars span.on { color: var(--gold); animation: starIn 0.4s ease-out both; text-shadow: 0 0 14px rgba(251,191,36,0.7); }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } }
.help { text-align: left; padding-left: 18px; margin: 0; font-size: 0.88rem; line-height: 1.55; color: var(--dim); }
.help b { color: var(--text); }
kbd { display: inline-block; min-width: 1.4em; padding: 0 4px; border-radius: 5px; border: 1px solid var(--line); background: var(--panel); font-size: 0.78rem; text-align: center; color: var(--text); }
.noscript { text-align: center; padding: 40px; }

/* 업적 */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.ach { display: flex; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,0.02); opacity: 0.5; min-width: 0; }
.ach.got { opacity: 1; border-color: rgba(250,204,21,0.45); }
.ach .ai { font-size: 1.3rem; flex: none; }
.ach b { display: block; font-size: 0.85rem; }
.ach small { display: block; color: var(--dim); font-size: 0.72rem; line-height: 1.3; }
.ach-new { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0; }
.ach-new span { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--gold); color: var(--gold); font-size: 0.82rem; }
.ach-pop {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 9; pointer-events: none;
  background: rgba(30, 22, 4, 0.92); border: 1px solid var(--gold); color: #fde68a; border-radius: 999px; padding: 6px 14px;
  font-size: 0.82rem; white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis; animation: tin 0.25s ease-out;
}
