:root {
  --bg: #060813; --bg2: #0f1328; --panel: #161b36; --line: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9; --dim: #94a3b8; --accent: #38bdf8; --pink: #f472b6; --gold: #fbbf24; --ok: #34d399; --bad: #f43f5e;
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% -10%, #1e1450, 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-ball {
  width: 34px; height: 34px; margin: 0 auto; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #cbd5e1 45%, #475569);
  box-shadow: 0 0 18px rgba(56,189,248,0.7); animation: bounce 1.6s cubic-bezier(.4,0,.6,1) infinite;
}
@keyframes bounce { 0%, 100% { transform: translate(-40px, 0); } 50% { transform: translate(40px, -10px); } }
.logo h1 { margin: 6px 0 4px; font-size: 1.6rem; letter-spacing: -0.5px; text-shadow: 0 0 18px rgba(56,189,248,0.45); }
.logo h1 span { background: linear-gradient(135deg, var(--accent), var(--pink)); -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(3, 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.85rem; font-weight: 700; white-space: nowrap; }
.tab.on { background: rgba(56,189,248,0.16); border-color: var(--accent); color: #bae6fd; }
.panel-wrap { max-width: 720px; margin: 0 auto; display: grid; gap: 12px; }
@media (min-width: 760px) { .panel-wrap.two { grid-template-columns: 1fr 1fr; } }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.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; }
.card p { margin: 0 0 10px; color: var(--dim); font-size: 0.84rem; line-height: 1.5; }
.card p b { color: var(--text); }
.sub { margin: 12px 0 4px; font-size: 0.9rem; color: #cbd5e1; }
.table-card { border-color: color-mix(in srgb, var(--c1) 45%, transparent); background: linear-gradient(160deg, color-mix(in srgb, var(--c1) 14%, var(--bg2)), var(--bg2) 60%); }
.tc-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.tc-ico { font-size: 2rem; filter: drop-shadow(0 0 8px var(--c1)); }
.tc-head h2 { margin: 0; }
.tc-best { color: var(--dim); font-size: 0.8rem; }
.tc-stars { margin-left: auto; color: var(--gold); font-weight: 800; }
.missions { list-style: none; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 0.78rem; color: var(--dim); }
.missions li.done { color: var(--gold); }
.big-btn {
  display: block; width: 100%; padding: 13px; border-radius: 14px; border: 0; font-weight: 800; font-size: 1.02rem;
  background: linear-gradient(135deg, var(--c1, #38bdf8), var(--c2, #a855f7)); color: #fff; box-shadow: 0 6px 22px rgba(56,189,248,0.25);
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.mod { display: flex; align-items: center; gap: 12px; background: var(--panel); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.mod-ico { font-size: 1.6rem; }
.mod b { display: block; }
.mod span { color: var(--dim); font-size: 0.8rem; }
.daily-rec, .stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 12px; }
.stat-grid { grid-template-columns: repeat(3, 1fr); margin: 8px 0 0; }
.daily-rec div, .stat-grid div { background: var(--panel); border-radius: 12px; padding: 10px 6px; text-align: center; }
.daily-rec small, .stat-grid small { display: block; color: var(--dim); font-size: 0.74rem; }
.daily-rec b, .stat-grid b { font-size: 1.15rem; color: var(--gold); }
.stat-grid.small b { font-size: 1rem; }
.stat-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.stat-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: center; }
.stat-table td.num { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-table td.dim { color: var(--dim); font-size: 0.78rem; }

.btn {
  padding: 10px 16px; border-radius: 12px; border: 0; font-weight: 800;
  background: linear-gradient(135deg, #38bdf8, #a855f7); 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 10px max(8px, env(safe-area-inset-bottom)); width: 100%; max-width: 720px; margin: 0 auto; }
.p-head { display: flex; align-items: stretch; gap: 8px; }
.dmd {
  flex: 1; min-width: 0; border-radius: 10px; padding: 4px 10px; text-align: center;
  background: #120a02; border: 1px solid rgba(251,146,60,0.45);
  background-image: radial-gradient(rgba(251,146,60,0.12) 1px, transparent 1.2px); background-size: 4px 4px;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; color: #fb923c; text-shadow: 0 0 8px rgba(251,146,60,0.8);
}
.dmd.flash { animation: dmdFlash 0.5s steps(2) 3; }
@keyframes dmdFlash { 50% { background-color: #3b1d06; color: #fde68a; } }
.dmd-score { font-size: 1.35rem; font-weight: 900; line-height: 1.15; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.dmd-msg { font-size: 0.78rem; min-height: 1.1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: system-ui, sans-serif; font-weight: 700; }
.p-side { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.chip { padding: 3px 9px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); font-size: 0.78rem; color: var(--dim); white-space: nowrap; }
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }

.board-wrap { position: relative; flex: 1; min-height: 240px; touch-action: none; overflow: hidden; margin-top: 6px; }
#cv { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border-radius: 12px; box-shadow: 0 0 0 1px var(--line), 0 0 30px rgba(56,189,248,0.15); }

.controls { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; margin-top: 6px; }
.pad {
  height: 54px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2); font-size: 1.3rem; font-weight: 900; color: #bae6fd;
  touch-action: none;
}
.pad:active { background: rgba(56,189,248,0.2); }
.pad.nudge { font-size: 0.85rem; padding: 0 14px; color: var(--dim); }
.keys { text-align: center; color: var(--dim); font-size: 0.72rem; margin: 6px 0 0; }
@media (hover: none) { .keys { display: none; } }
@media (max-height: 640px) { .keys { display: none; } .pad { height: 44px; } }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(2, 6, 23, 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.over h2 { letter-spacing: 3px; color: #fb923c; text-shadow: 0 0 12px rgba(251,146,60,0.7); }
.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; }
.dialog .row.col { flex-direction: column; }
.big-num { font-size: 2.2rem; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.new-ms { margin: 8px 0; color: var(--gold); font-weight: 700; font-size: 0.88rem; display: grid; gap: 4px; }
.help { text-align: left; padding-left: 18px; margin: 0; font-size: 0.86rem; 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; }
