:root {
  --bg: #0b0f1c; --panel: #141b2e; --panel2: #1b2440; --line: rgba(148, 197, 255, 0.16);
  --text: #eef4ff; --dim: #93a3c2; --accent: #f5b942; --accent2: #ffd98a; --cyan: #5cc8ff; --ok: #4ade80; --bad: #f87171;
  --r: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% -10%, #1d2a4d 0%, #0b0f1c 55%, #070a13 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; opacity: 0.45; }
[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; }
.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; }
.screen > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.logo { text-align: center; margin: 2px auto 12px; }
#logoCanvas { width: 192px; height: 60px; image-rendering: pixelated; border-radius: 8px; background: #0b0f1c; box-shadow: 0 0 0 1px var(--line); }
h1 { margin: 6px 0 2px; font-size: 1.55rem; letter-spacing: -0.02em; }
h1 span { color: var(--accent); }
.tagline { margin: 0; color: var(--dim); font-size: 0.9rem; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.tab { padding: 9px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; font-size: 0.86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--accent); color: #1f1404; border-color: var(--accent); }
.dim { color: var(--dim); }
.small { font-size: 0.82rem; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin-bottom: 12px; }
.card h3 { margin: 0 0 4px; font-size: 1.05rem; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card h3 small { color: var(--dim); font-weight: 600; }
.card h3 .meta { margin-left: auto; color: var(--dim); font-size: 0.85rem; }
.card p { margin: 4px 0 8px; }
.lock-msg { color: var(--accent2); font-weight: 700; font-size: 0.9rem; }
.card.locked .lvls { opacity: 0.4; }
.lvls { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.lvl {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 4px 8px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel2); min-height: 96px;
}
.lvl:not(:disabled):hover { border-color: var(--accent); transform: translateY(-1px); }
.lvl .li { font-size: 1.6rem; line-height: 1; }
.lvl .ln { font-size: 0.78rem; font-weight: 800; color: var(--dim); }
.lvl .lt { font-size: 0.82rem; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lvl .ls { color: var(--accent2); font-size: 0.75rem; letter-spacing: 1px; }
.lvl.done { border-color: rgba(245, 185, 66, 0.45); }

.big-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 10px;
  border-radius: var(--r); border: 1px solid rgba(245, 185, 66, 0.5); background: linear-gradient(135deg, rgba(245,185,66,0.2), rgba(245,185,66,0.05));
}
.big-btn .bi { font-size: 1.6rem; }
.big-btn b { display: block; }
.big-btn small { color: var(--dim); }
.big-btn.alt { border-color: var(--line); background: var(--panel); }
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.presets .big-btn { margin: 0; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.cal div { text-align: center; padding: 6px 0; border-radius: 8px; background: var(--panel2); font-size: 0.78rem; color: var(--dim); }
.cal div.on { background: rgba(245, 185, 66, 0.3); color: var(--accent2); font-weight: 800; }
.cal div.today { box-shadow: inset 0 0 0 2px var(--cyan); }
.cal div.h { background: none; font-weight: 700; }

.dex { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.dex div { padding: 8px; border-radius: 10px; background: var(--panel2); font-size: 0.82rem; }
.dex div b { display: block; font-size: 0.9rem; }
.dex div.no { opacity: 0.45; }
.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.ach div { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 10px; background: var(--panel2); font-size: 0.82rem; }
.ach div i { font-style: normal; font-size: 1.4rem; }
.ach div.no { opacity: 0.4; filter: grayscale(1); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.stats div { padding: 8px; border-radius: 10px; background: var(--panel2); text-align: center; font-size: 0.8rem; color: var(--dim); }
.stats b { display: block; color: var(--text); font-size: 1.15rem; }

/* ── 플레이 ── */
#play { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 10px max(8px, env(safe-area-inset-bottom)); gap: 6px; }
.p-head { display: flex; align-items: center; gap: 8px; max-width: 760px; width: 100%; margin: 0 auto; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 9px 14px; font-weight: 700; }
.btn.small { padding: 6px 12px; }
.btn.primary { background: var(--accent); color: #1f1404; border-color: var(--accent); }
.p-title { flex: 1; min-width: 0; line-height: 1.2; }
.p-title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-title small { color: var(--dim); font-size: 0.78rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { padding: 5px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 0.85rem; white-space: nowrap; }
.chip .st { color: var(--accent2); letter-spacing: 1px; margin-left: 4px; }
.goals { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 760px; width: 100%; margin: 0 auto; }
.goal { display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 0.82rem; }
.goal .bar { width: 64px; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.12); overflow: hidden; }
.goal .bar i { display: block; height: 100%; background: var(--cyan); }
.goal.ok { border-color: rgba(74, 222, 128, 0.6); }
.goal.ok .bar i { background: var(--ok); }
.goal.bad { border-color: rgba(248, 113, 113, 0.6); }
.board-wrap { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; }
#board { image-rendering: pixelated; image-rendering: crisp-edges; border-radius: 10px; box-shadow: 0 0 0 1px var(--line), 0 12px 32px rgba(0,0,0,0.5); touch-action: none; cursor: crosshair; background: #0b0f1c; }
.toast { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(10, 14, 28, 0.92); border: 1px solid var(--accent); color: var(--accent2); padding: 8px 14px; border-radius: 12px; font-weight: 700; font-size: 0.88rem; pointer-events: none; max-width: 90%; text-align: center; }
.paused-tag { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); background: rgba(10, 14, 28, 0.85); color: var(--dim); padding: 4px 10px; border-radius: 999px; font-size: 0.75rem; pointer-events: none; white-space: nowrap; }
.palette { display: flex; gap: 5px; overflow-x: auto; max-width: 760px; width: 100%; margin: 0 auto; padding: 2px 2px 4px; scrollbar-width: thin; }
.pal { flex: none; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 52px; padding: 5px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 0.72rem; font-weight: 700; }
.pal .pi { font-size: 1.1rem; line-height: 1.1; }
.pal .pc { width: 22px; height: 4px; border-radius: 2px; }
.pal .pn { color: var(--dim); font-weight: 600; }
.pal.on { border-color: var(--accent); background: rgba(245, 185, 66, 0.16); }
.pal.empty { opacity: 0.4; }
.toolbar { display: flex; gap: 6px; justify-content: center; align-items: stretch; max-width: 760px; width: 100%; margin: 0 auto; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
.size { width: 38px; border: 0; background: none; display: grid; place-items: center; }
.size i { display: block; width: var(--d); height: var(--d); border-radius: 50%; background: var(--dim); }
.size.on { background: rgba(245, 185, 66, 0.2); }
.size.on i { background: var(--accent); }
.tbtn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; min-width: 52px; padding: 4px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 1rem; font-weight: 800; line-height: 1.1; }
.tbtn span { font-size: 0.66rem; color: var(--dim); font-weight: 600; }
.tbtn.on { border-color: var(--accent); }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(3, 6, 14, 0.72); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 18px; max-width: 440px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.6); }
.modal-box h2 { margin: 0 0 8px; font-size: 1.25rem; }
.modal-box p { margin: 6px 0; line-height: 1.5; }
.modal-box ul { margin: 6px 0; padding-left: 20px; line-height: 1.55; }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.stars-big { font-size: 2.2rem; letter-spacing: 6px; text-align: center; margin: 4px 0; color: var(--accent2); }
.stars-big .off { opacity: 0.2; }
.ink-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.ink-list span { padding: 3px 8px; border-radius: 999px; background: var(--panel2); font-size: 0.85rem; }
.err { font-family: ui-monospace, monospace; font-size: 0.75rem; background: #000; padding: 8px; border-radius: 8px; white-space: pre-wrap; word-break: break-all; max-height: 160px; overflow: auto; color: #fca5a5; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.slot { border: 1px solid var(--line); border-radius: 12px; background: var(--panel2); padding: 6px; display: flex; flex-direction: column; gap: 4px; align-items: center; font-size: 0.75rem; }
.slot canvas { width: 64px; height: 80px; image-rendering: pixelated; border-radius: 6px; background: #0b0f1c; }
.slot .sb { display: flex; gap: 4px; }
.slot .sb button { padding: 3px 7px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); font-size: 0.72rem; }
.noscript { text-align: center; padding: 40px; }

@media (max-width: 520px) {
  .back-txt { display: none; }
  .tab { font-size: 0.74rem; }
  .tbtn { min-width: 44px; padding: 3px 5px; }
  .size { width: 32px; }
  .goal .bar { width: 44px; }
}
