:root {
  --bg: #1b1530;
  --panel: #2a2147;
  --text: #fff8e7;
  --muted: #b8aed6;
  --gold: #f5b82e;
  --red: #e2564a;
  --green: #4ec98a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif; }
body { overflow: hidden; }

.screen { display: none; position: fixed; inset: 0; padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  flex-direction: column; align-items: stretch; gap: 12px; overflow-y: auto; }
.screen.active { display: flex; }

h1 { text-align: center; margin: 0; font-size: 28px; color: var(--gold); text-shadow: 0 3px 0 #7a4b00; }
h2 { text-align: center; margin: 4px 0 8px; font-size: 22px; }
.sub { text-align: center; margin: 0; color: var(--muted); }
.hint { text-align: center; color: var(--muted); font-size: 14px; margin: 4px 0; }
.gps-line { text-align: center; color: var(--muted); font-size: 12px; margin-top: auto; }

#s-title { justify-content: center; }
.title-art { font-size: 84px; text-align: center; animation: float 3s ease-in-out infinite; user-select: none; }
.title-art span { font-size: 48px; vertical-align: top; }
@keyframes float { 50% { transform: translateY(-10px); } }

.btn { appearance: none; border: 0; border-radius: 14px; padding: 15px 16px; font-size: 17px; font-weight: 700;
  background: var(--panel); color: var(--text); box-shadow: 0 4px 0 #120d22; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #120d22; }
.btn.primary { background: var(--gold); color: #2b1a00; box-shadow: 0 4px 0 #9a6a00; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); font-weight: 500; }
.btn.small { padding: 8px; font-size: 14px; }
.btn:disabled { opacity: .55; }
.btn.wrong { background: var(--red); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* 캐릭터 */
.char-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.char-card { border: 2px solid transparent; border-radius: 16px; background: var(--panel); color: var(--text);
  padding: 16px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.char-card:active { border-color: var(--gold); }
.char-emoji { font-size: 52px; }
.char-card small { color: var(--muted); font-size: 12px; }
.char-card em { color: var(--gold); font-style: normal; font-size: 12px; }

/* 대화 */
.dialog-screen { justify-content: flex-end; background: linear-gradient(#2d2350, var(--bg)); }
.dialog-who { font-size: 110px; text-align: center; margin-bottom: auto; margin-top: 18vh; }
.dialog-who.pop { animation: pop .35s; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.dialog-box { position: relative; background: #fff8e7; color: #2b1a00; border: 4px solid var(--gold); border-radius: 16px;
  padding: 18px 18px 30px; min-height: 130px; font-size: 18px; line-height: 1.55; }
.dialog-box p { margin: 0; white-space: pre-line; }
.dialog-next { position: absolute; right: 14px; bottom: 8px; font-size: 12px; color: #9a6a00; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* 지도 */
#s-map { padding: 0; gap: 0; }
.hud { display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 10px) 12px 10px; background: var(--panel); }
.hud-char { font-size: 36px; }
.hud-info { flex: 1; min-width: 0; }
#hud-target { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-dist { font-size: 26px; font-weight: 800; color: var(--gold); }
.hud-walk { font-size: 12px; color: var(--muted); text-align: right; }
.hud-walk b { color: var(--text); }
#map { flex: 1; min-height: 200px; background: #2c3a2f; }
.inventory { display: flex; justify-content: center; gap: 8px; padding: 8px; background: var(--panel); }
.slot { width: 40px; height: 40px; border-radius: 10px; background: #1b1530; display: grid; place-items: center; font-size: 22px; color: var(--muted); }
.slot.got { background: #4a3a10; box-shadow: inset 0 0 0 2px var(--gold); }
.map-actions { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px); background: var(--panel); }
.debug-only { display: none; }
body.debug .debug-only { display: block; }

.pin { font-size: 26px; line-height: 36px; text-align: center; filter: drop-shadow(0 2px 2px rgba(0,0,0,.5)); }
.pin.current { animation: bounce 1s infinite; }
.pin.me { font-size: 30px; }
@keyframes bounce { 50% { transform: translateY(-8px); } }

/* 미션 */
.question { font-size: 20px; line-height: 1.5; text-align: center; white-space: pre-line; background: var(--panel); padding: 18px; border-radius: 14px; margin: 0; }
.choices { display: grid; gap: 10px; }
input, textarea { width: 100%; font-size: 18px; padding: 14px; border-radius: 12px; border: 2px solid var(--panel); background: #fff8e7; color: #2b1a00; }
textarea { font-size: 12px; font-family: monospace; }
.timer { font-size: 96px; font-weight: 800; text-align: center; color: var(--gold); }

.boss { display: flex; justify-content: center; align-items: center; gap: 16px; }
.boss-emoji { font-size: 72px; }
.vs { font-weight: 900; color: var(--red); }
.boss.hit .boss-emoji:first-child { animation: shake .4s; filter: brightness(2); }
.hpbar { position: relative; height: 24px; background: #120d22; border-radius: 12px; overflow: hidden; }
.hpbar i { position: absolute; inset: 0 auto 0 0; background: var(--red); transition: width .4s; }
.hpbar span { position: relative; display: block; text-align: center; font-size: 13px; line-height: 24px; font-weight: 700; }

/* 보상 */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stats div { background: var(--panel); border-radius: 12px; padding: 10px 4px; text-align: center; }
.stats b { display: block; font-size: 18px; }
.stats small { color: var(--muted); font-size: 11px; }
.coupon { background: #fff8e7; color: #2b1a00; border: 3px dashed var(--gold); border-radius: 16px; padding: 18px; text-align: center; }
.coupon-title { font-weight: 800; font-size: 18px; }
.coupon-code { font-size: 40px; font-weight: 900; letter-spacing: 6px; margin: 8px 0; color: #9a3a00; }
.coupon-state { font-size: 13px; color: #7a6a4a; }
.coupon.used { opacity: .5; }
.coupon.used .coupon-code { text-decoration: line-through; }

.gps-box { background: var(--panel); padding: 14px; border-radius: 12px; line-height: 1.7; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 120px); transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,.85); color: #fff; padding: 12px 18px; border-radius: 24px; font-size: 15px; opacity: 0;
  transition: .25s; pointer-events: none; max-width: calc(100% - 32px); text-align: center; z-index: 9999; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- v2: 포인트 / 상점 / 교환권 ---------- */
#s-loading, #s-signup { justify-content: center; }
.points-badge { align-self: flex-end; background: var(--panel); color: var(--gold); font-weight: 800; padding: 8px 14px; border-radius: 20px; }
.month-tag { text-align: center; margin: 0; color: var(--gold); font-weight: 700; letter-spacing: 2px; font-size: 14px; }
.menu-row { display: flex; gap: 8px; }
.menu-row .btn { flex: 1; }
.earned { text-align: center; font-size: 44px; font-weight: 900; color: var(--gold); text-shadow: 0 3px 0 #7a4b00; }
.earned small { font-size: 16px; color: var(--muted); text-shadow: none; }
.points-line { text-align: center; color: var(--muted); }
.points-line b { color: var(--gold); font-size: 22px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 0; color: var(--text); border-radius: 14px; padding: 12px; text-align: left; font: inherit; }
.item.dim { opacity: .5; }
.item-emoji { font-size: 34px; width: 44px; text-align: center; }
.item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item-info small { color: var(--muted); font-size: 12px; }
.item .btn.small { padding: 10px 12px; white-space: nowrap; }
.tag { font-size: 12px; padding: 4px 8px; border-radius: 10px; background: #1b1530; color: var(--gold); white-space: nowrap; }
.delta { font-weight: 800; font-size: 18px; }
.delta.plus { color: var(--green); } .delta.minus { color: var(--red); }

.ticket-screen { justify-content: center; }
.ticket { background: #fff; color: #222; border-radius: 18px; padding: 20px 12px; text-align: center; }
.ticket-emoji { font-size: 48px; }
.ticket-name { font-size: 22px; font-weight: 800; }
.ticket-meta { font-size: 13px; color: #777; margin-bottom: 8px; }
#tk-barcode { max-width: 100%; height: auto; }
.ticket-state { font-weight: 700; color: #2a8a55; }
.ticket-screen.used #tk-barcode { opacity: .2; }
.ticket-screen.used .ticket-state { color: #999; }

/* ---------- v3: 휴대폰 인증 ---------- */
.auth-step { display: flex; flex-direction: column; gap: 10px; }
.auth-step[hidden] { display: none; }
.agree { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.agree input { width: 22px; height: 22px; }
.privacy { font-size: 13px; color: var(--muted); }
.privacy p { margin: 6px 0 0; line-height: 1.6; background: var(--panel); padding: 10px; border-radius: 10px; }
.gps-line + .gps-line { margin-top: 0; }
.gps-line a { color: var(--muted); }

/* ---------- v4: 회원 탈퇴 ---------- */
.warn-box { background: var(--panel); border: 2px solid var(--red); border-radius: 14px; padding: 14px 16px; line-height: 1.6; }
.warn-box p { margin: 0; }
.warn-box ul { margin: 8px 0; padding-left: 20px; }
.warn-box b { color: var(--gold); }
.muted-s { font-size: 12px; color: var(--muted); }
.btn.danger { background: var(--red); color: #fff; box-shadow: 0 4px 0 #8a2a22; }

/* ---------- v5: 비회원 ---------- */
body:not(.guest) .guest-only, body.guest .member-only { display: none !important; }
.or-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin-top: 6px; }
.or-line::before, .or-line::after { content: ''; flex: 1; height: 1px; background: #3a3060; }
