:root {
  --bg: #101626; --panel: #161e33; --panel2: #1d2740; --line: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9; --dim: #94a3b8; --accent: #a78bfa; --accent2: #c4b5fd; --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%, #26304d 0%, #101626 60%, #090d18 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-pz { display: inline-grid; grid-template-columns: 18px 18px; gap: 3px; }
.logo-pz i { width: 18px; height: 18px; border-radius: 4px; animation: pz 3s ease-in-out infinite; }
.logo-pz i:nth-child(1) { background: #f472b6; }
.logo-pz i:nth-child(2) { background: #fbbf24; animation-delay: 0.3s; }
.logo-pz i:nth-child(3) { background: #38bdf8; animation-delay: 0.6s; }
.logo-pz i:nth-child(4) { background: #a78bfa; animation-delay: 0.9s; }
@keyframes pz { 0%, 70%, 100% { transform: none; } 80% { transform: translate(-3px, -3px) rotate(-8deg); } }
.logo h1 { margin: 6px 0 4px; font-size: 1.6rem; letter-spacing: -0.5px; }
.logo h1 span { background: linear-gradient(135deg, #f9a8d4, #a78bfa, #38bdf8); -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: 760px; 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(167,139,250,0.2); }
.panel-wrap { max-width: 760px; 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; }
.resume-list { display: grid; gap: 6px; }
.resume-item { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,0.2); border-radius: 12px; padding: 6px 8px; }
.resume-item canvas { width: 54px; border-radius: 6px; flex: none; }
.resume-item div { flex: 1; min-width: 0; font-size: 0.82rem; }
.resume-item div b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resume-item div small { color: var(--dim); }
.pz-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 520px) { .pz-grid { grid-template-columns: repeat(3, 1fr); } }
.pz-btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 6px; display: flex; flex-direction: column; gap: 4px; text-align: left; }
.pz-btn:hover:not(:disabled) { border-color: var(--accent); }
.pz-btn.clear { border-color: rgba(52,211,153,0.45); }
.pz-btn.locked { opacity: 0.45; }
.thumb { position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; background: #0b1020; display: grid; place-items: center; }
.thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .lock { font-size: 1.6rem; }
.thumb .badge { position: absolute; left: 4px; top: 4px; background: rgba(2,6,23,0.75); border-radius: 999px; padding: 1px 7px; font-size: 0.68rem; font-weight: 800; }
.thumb .veil { position: absolute; inset: 0; background: linear-gradient(transparent 55%, rgba(2,6,23,0.6)); }
.pz-name { font-size: 0.8rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pz-meta { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--dim); }
.pz-stars { color: var(--gold); letter-spacing: 1px; }
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
@media (min-width: 520px) { .theme-grid { grid-template-columns: repeat(6, 1fr); } }
.theme-btn { border: 2px solid transparent; background: var(--panel2); border-radius: 10px; padding: 3px; font-size: 0.7rem; font-weight: 800; display: flex; flex-direction: column; gap: 2px; }
.theme-btn.on { border-color: var(--accent); }
.theme-btn .thumb { aspect-ratio: 3 / 2; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.seg button { flex: 1 0 auto; min-width: 56px; padding: 7px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); font-weight: 800; font-size: 0.82rem; }
.seg button.on { border-color: var(--accent); color: var(--accent2); background: #251f45; }
.lab { font-size: 0.78rem; color: var(--dim); font-weight: 800; margin: 4px 0 6px; }
.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); }
.daily-top { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 10px; }
@media (min-width: 520px) { .daily-top { grid-template-columns: 220px 1fr; align-items: center; } }
.daily-top .thumb { aspect-ratio: auto; }
.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, #c4b5fd, #a78bfa 50%, #7c3aed); color: #160b33; border-color: transparent; box-shadow: 0 4px 14px rgba(167,139,250,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; min-height: 0; padding: 0 8px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
.p-head { display: flex; align-items: center; gap: 6px; max-width: 1100px; width: 100%; margin: 0 auto; }
.p-title { flex: 1; font-weight: 800; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.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.over { border-color: var(--bad); }
.stage { position: relative; flex: 1; min-height: 0; margin: 6px 0; border-radius: 14px; overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #2a3350, #182036 70%); box-shadow: inset 0 0 0 1px var(--line); }
.stage canvas#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: grab; }
.stage canvas#cv.grabbing { cursor: grabbing; }
.preview { position: absolute; right: 10px; top: 10px; background: rgba(2,6,23,0.85); border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: flex; flex-direction: column; gap: 4px; align-items: center; z-index: 2; cursor: pointer; }
.preview canvas { display: block; border-radius: 8px; max-width: min(70vw, 420px); max-height: 40vh; }
.preview small { color: var(--dim); font-size: 0.7rem; }
.toast { position: absolute; top: 14px; 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; z-index: 3; }
.toolbar { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; max-width: 640px; width: 100%; margin: 0 auto; }
.tbtn { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-size: 1.1rem; touch-action: manipulation; }
.tbtn span { font-size: 0.66rem; font-weight: 800; color: var(--dim); }
.tbtn.on { border-color: var(--accent); background: #251f45; }
.tbtn.on span { color: var(--accent2); }
.tbtn:disabled { opacity: 0.35; }
.tbtn:active:not(:disabled) { transform: scale(0.96); }
.hint { margin: 4px 0 0; font-size: 0.72rem; color: var(--dim); text-align: center; }
@media (max-height: 600px) { .hint { display: none; } .tbtn span { 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; }
.done-img { width: 100%; border-radius: 10px; margin-bottom: 8px; display: block; }
.big-stars { font-size: 2.4rem; color: var(--gold); letter-spacing: 4px; }
.big-stars i { font-style: normal; color: #334155; }
.star-why { display: grid; gap: 2px; font-size: 0.8rem; color: var(--dim); margin: 4px 0 8px; }
.star-why .ok { color: var(--ok); }
.final { font-size: 2rem; font-weight: 900; color: var(--accent2); font-variant-numeric: tabular-nums; }
.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; }
}
