/* 방구석 보석공: 밝고 깨끗한 구슬 공방 톤(연한 라벤더 바탕 + 보라 강조) */
:root {
  --sans: "Pretendard Variable", Pretendard, -apple-system, system-ui, sans-serif;
  --disp: "Bagel Fat One", "Pretendard Variable", sans-serif;
  --bg: #EFE9FA; --bg2: #FBF9FF; --gold: #5A3CDC; --gold2: #4329B8; --ink: #2A2140; --sub: #6E6588; --line: rgba(90, 60, 220, .26);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-tap-highlight-color: transparent; }
body { background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg) 70%); word-break: keep-all; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--gold); }
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.screen.show { display: flex; }

/* 버튼 */
.big-btn, .ghost-btn, .row-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 100%; min-height: 56px; border-radius: 16px; padding: 10px 14px; text-align: center; transition: transform .08s, filter .15s; }
.big-btn { border: 0; color: #fff; background: linear-gradient(180deg, #7C62F0, var(--gold) 55%, var(--gold2)); box-shadow: 0 4px 0 #33208F, 0 10px 22px rgba(70, 50, 120, .25); }
.big-btn.sm { min-height: 46px; box-shadow: 0 3px 0 #33208F; }
.ghost-btn { border: 1.5px solid var(--line); background: rgba(255, 255, 255, .7); }
.big-btn b, .ghost-btn b, .row-btn b { font-weight: 800; font-size: 17px; }
.big-btn small, .ghost-btn small, .row-btn small { font-size: 12.5px; opacity: .78; font-weight: 500; }
.big-btn:active, .ghost-btn:active, .row-btn:active, .tool:active, .card:active { transform: translateY(2px); filter: brightness(.94); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.link-btn { border: 0; background: none; color: var(--sub); font-size: 14px; padding: 10px; text-decoration: underline; text-underline-offset: 3px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1.5px solid var(--line); background: rgba(255, 255, 255, .7); font-size: 20px; line-height: 1; display: grid; place-items: center; flex: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }

/* 시작 화면 */
#home { overflow-y: auto; align-items: center; }
.home-card { width: 100%; max-width: 420px; margin: auto; padding: 22px 20px 26px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.brand-row { display: inline-flex; align-items: baseline; gap: 7px; padding: 5px 13px; border-radius: 99px; border: 1px solid var(--line); font-size: 12px; color: var(--sub); }
.brand-ppl { font-weight: 900; color: var(--gold); letter-spacing: .04em; }
.logo-gems { width: 300px; max-width: 86%; height: auto; margin-top: 8px; }
h1 .t1 { display: block; white-space: nowrap; font: 400 clamp(38px, 12vw, 56px)/1.1 var(--disp); color: var(--gold); text-shadow: 0 3px 0 #CFC4F2, 0 10px 26px rgba(90, 60, 220, .18); }
h1 .t2 { display: block; margin: 8px 0 10px; font-size: 15px; font-weight: 500; color: var(--sub); }
.row-btn { flex-direction: row; justify-content: flex-start; gap: 12px; border: 1.5px solid var(--gold); background: rgba(90, 60, 220, .1); text-align: left; }
.row-btn canvas { width: 48px; height: 48px; border-radius: 10px; background: #FFFFFF; flex: none; }
.row-btn span { display: flex; flex-direction: column; gap: 2px; }
.fine { margin-top: 8px; font-size: 12px; color: #8279A0; line-height: 1.7; }

/* 목록(그림 고르기·도감) */
.bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px 8px; width: 100%; max-width: 640px; margin: 0 auto; }
.bar h2 { flex: 1; font-size: 17px; font-weight: 800; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar h2 small { display: block; font-size: 12px; font-weight: 500; color: var(--sub); margin-top: 1px; }
.bar-side { min-width: 44px; text-align: right; font-size: 13px; color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }
.scroll { flex: 1; overflow-y: auto; padding: 4px 14px 28px; width: 100%; max-width: 640px; margin: 0 auto; }
.group-h { display: flex; align-items: baseline; gap: 8px; margin: 18px 2px 8px; font-size: 15px; font-weight: 800; color: var(--gold); }
.group-h small { font-size: 12.5px; font-weight: 500; color: var(--sub); }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.card { position: relative; border: 1.5px solid var(--line); background: rgba(255, 255, 255, .7); border-radius: 14px; padding: 8px 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; transition: transform .08s; }
.card canvas { width: 100%; aspect-ratio: 1; border-radius: 9px; background: #FFFFFF; }
.card .name { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.card .meta { font-size: 11.5px; color: var(--sub); font-variant-numeric: tabular-nums; }
.card.done { border-color: var(--gold); }
.card.done::after { content: "✓"; position: absolute; top: 5px; right: 5px; width: 20px; height: 20px; border-radius: 50%; background: var(--gold); color: #fff; font-size: 12px; font-weight: 900; display: grid; place-items: center; }
.card.brand { background: rgba(90, 60, 220, .09); }
.empty { text-align: center; color: var(--sub); padding: 40px 10px; line-height: 1.7; }
.album-top { text-align: center; color: var(--sub); font-size: 14px; margin: 10px 0 2px; line-height: 1.6; }
.album-bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .7); overflow: hidden; margin: 10px 2px 4px; }
.album-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold2), #9C88F5); border-radius: 99px; }

/* 퍼즐 */
#play { align-items: center; }
#play .bar { max-width: 560px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 0 10px 6px; max-width: 560px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px 3px 4px; border-radius: 99px; border: 1px solid var(--line); background: rgba(255, 255, 255, .7); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chip img { width: 22px; height: 22px; }
.chip.ok { border-color: var(--gold); color: var(--gold); background: rgba(90, 60, 220, .12); }
.board-wrap { position: relative; flex: 1; width: 100%; max-width: 560px; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.zoom-box { position: absolute; right: 8px; top: 6px; z-index: 2; display: flex; flex-direction: column; gap: 6px; }
.zoom-btn { width: 40px; height: 40px; border-radius: 12px; border: 1.5px solid var(--line); background: rgba(255, 255, 255, .92); color: var(--gold); font-size: 22px; font-weight: 800; line-height: 1; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(70, 50, 120, .15); }
.zoom-btn:disabled { opacity: .35; }
.toast { position: absolute; left: 50%; bottom: 4px; transform: translate(-50%, 6px); z-index: 2; width: max-content; max-width: 92%; padding: 8px 14px; border-radius: 12px; background: rgba(42, 33, 64, .94); color: #fff; border: 0; font-size: 13.5px; line-height: 1.45; text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.stuck { position: absolute; left: 12px; right: 12px; bottom: 6px; padding: 14px; border-radius: 16px; background: #fff; border: 1.5px solid var(--gold); box-shadow: 0 10px 30px rgba(70, 50, 120, .25); display: flex; flex-direction: column; gap: 10px; }
.stuck p { font-size: 14px; line-height: 1.5; color: var(--sub); }
.stuck p b { display: block; color: var(--ink); font-size: 15.5px; margin-bottom: 2px; }
.stuck .ghost-btn, .stuck .big-btn { min-height: 46px; font-weight: 800; font-size: 14.5px; }
.tools { display: flex; align-items: stretch; gap: 8px; padding: 6px 12px 12px; width: 100%; max-width: 560px; }
.tool { flex: 1; min-height: 52px; border-radius: 14px; border: 1.5px solid var(--line); background: rgba(255, 255, 255, .7); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 12.5px; font-weight: 700; transition: transform .08s; }
.tool i { font-style: normal; font-size: 18px; line-height: 1; color: var(--gold); }
.tool:disabled { opacity: .4; }
.tool.warn { border-color: #F28A2E; color: #B4550F; }
.moves { min-width: 54px; display: flex; align-items: baseline; justify-content: center; align-self: center; gap: 2px; font-size: 12.5px; color: var(--sub); }
.moves b { font: 800 22px/1 var(--sans); color: var(--gold); font-variant-numeric: tabular-nums; }

/* 완성 */
#done { overflow-y: auto; align-items: center; background: rgba(239, 233, 250, .96); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.done-card { width: 100%; max-width: 420px; margin: auto; padding: 18px 20px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.done-kicker { font-size: 14px; font-weight: 700; color: var(--sub); letter-spacing: .02em; }
.done-art { width: min(100%, 300px); aspect-ratio: 1; border-radius: 20px; background: #FFFFFF; border: 1.5px solid var(--gold); box-shadow: 0 0 0 6px rgba(90, 60, 220, .08), 0 18px 40px rgba(70, 50, 120, .22); overflow: hidden; }
.done-art canvas { width: 100%; height: 100%; display: block; }
#doneTitle, #viewTitle { font: 400 34px/1.15 var(--disp); color: var(--gold); margin-top: 4px; }
.done-stat { font-size: 14.5px; color: var(--ink); line-height: 1.6; }
.done-stat b { color: var(--gold); font-variant-numeric: tabular-nums; }
.brand-note { width: 100%; padding: 12px 14px; border-radius: 14px; border: 1.5px dashed var(--gold); background: rgba(90, 60, 220, .08); font-size: 14.5px; line-height: 1.55; display: flex; flex-direction: column; gap: 6px; }
.brand-note .coupon { font-weight: 800; color: var(--gold); letter-spacing: .04em; }
.brand-note a { font-weight: 700; font-size: 14px; }
.ad-box { width: 100%; min-height: 100px; margin-top: 6px; border-radius: 12px; background: rgba(255, 255, 255, .7); position: relative; }
.ad-label { position: absolute; top: 4px; left: 8px; font-size: 10.5px; color: var(--sub); }

/* 대화 상자 */
dialog { border: 1.5px solid var(--gold); border-radius: 20px; background: #fff; color: var(--ink); width: min(92vw, 400px); max-height: 92dvh; padding: 20px; }
dialog[open] { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
dialog::backdrop { background: rgba(42, 33, 64, .5); }
#how h2 { font: 400 26px/1.2 var(--disp); color: var(--gold); }
#how ol { margin: 4px 0; padding-left: 20px; text-align: left; font-size: 14.5px; line-height: 1.6; color: var(--sub); display: flex; flex-direction: column; gap: 7px; }
#how ol b { color: var(--ink); display: block; }
.how-note { font-size: 13.5px; color: var(--sub); line-height: 1.6; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
