:root {
  --cass: #0047bb;
  --cass-deep: #002a7a;
  --navy: #001a4d;
  --sky: #6ec0ff;
  --yellow: #ffce00;
  --ink: #0d1b33;
  --muted: #5b6b86;
  --line: #d8e2f2;
  --bg: #f2f6fd;
  --ok: #18a058;
  --danger: #d6334a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--navy); overscroll-behavior: none; }
body { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
#app { position: fixed; inset: 0; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; overflow-y: auto; }

/* ---------- 공통 컴포넌트 ---------- */
.btn {
  display: block; width: 100%; min-height: 56px; border: 0; border-radius: 16px;
  font-size: 18px; font-weight: 800; letter-spacing: -0.2px; padding: 14px 18px;
  transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--yellow); color: var(--navy); box-shadow: 0 6px 18px rgba(255, 206, 0, .35); }
.btn.ghost { background: transparent; color: var(--cass); border: 2px solid currentColor; margin-top: 10px; min-height: 50px; font-size: 16px; }
.btn.ghost.light { color: #fff; }
.btn.small { min-height: 40px; width: auto; display: inline-block; font-size: 14px; padding: 8px 14px; border-radius: 12px; }
.link { background: none; border: 0; padding: 6px 2px; color: inherit; text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; background: rgba(255,255,255,.16); color: #fff; max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { border: 0; padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 800; background: #fff; color: var(--cass); min-height: 40px; }
.pill b { color: var(--cass-deep); margin-left: 2px; }
.glass { background: rgba(0, 26, 77, .55); color: #fff; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.pill.glass b { color: var(--yellow); }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(0, 26, 77, .55); color: #fff; font-size: 18px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(12px + var(--safe-t)) 16px 8px; }
.notice { background: #eef4ff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 13px; line-height: 1.5; color: var(--ink); }
.notice.warn { background: #fff7d6; border-color: #f0d36b; }
.notice a { color: var(--cass); font-weight: 700; display: inline-block; margin-top: 4px; }
.fineprint { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 8px 0 12px; }
.bottom-actions { padding: 16px 16px calc(20px + var(--safe-b)); }

/* ---------- A. 시작 ---------- */
.intro { background: radial-gradient(120% 70% at 50% 0%, #1a63e0 0%, var(--cass) 45%, var(--cass-deep) 100%); color: #fff; }
.intro-hero { flex: 1; padding: 8px 24px 0; display: flex; flex-direction: column; justify-content: center; }
.hero-thumbs { display: flex; justify-content: center; gap: 4px; margin-bottom: 10px; min-height: 96px; }
.hero-thumbs img { width: 96px; height: 96px; filter: drop-shadow(0 8px 10px rgba(0,0,0,.25)); }
.intro h1 { font-size: 40px; line-height: 1.12; letter-spacing: -1px; margin: 4px 0 12px; font-weight: 900; }
.intro .lead { font-size: 16px; line-height: 1.55; opacity: .92; margin: 0 0 18px; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.steps li { background: rgba(255,255,255,.12); border-radius: 14px; padding: 10px 8px; font-size: 13px; font-weight: 700; text-align: center; line-height: 1.35; }
.steps b { display: block; color: var(--yellow); font-size: 18px; }
.intro-bottom { padding: 18px 16px calc(14px + var(--safe-b)); background: #fff; color: var(--ink); border-radius: 24px 24px 0 0; margin-top: 18px; }
.intro-bottom .notice { margin-bottom: 12px; }
.adult { display: flex; align-items: center; gap: 12px; font-size: 17px; font-weight: 800; min-height: 48px; cursor: pointer; }
.adult input { width: 26px; height: 26px; accent-color: var(--cass); margin: 0; }
.intro-bottom .btn.primary { background: var(--cass); color: #fff; box-shadow: 0 6px 18px rgba(0, 71, 187, .3); }
.intro-links { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; margin-top: 10px; color: var(--muted); }
.intro-links .link { color: var(--muted); }
.version { text-align: center; color: #9aa7bd; font-size: 11px; margin: 6px 0 0; user-select: none; }

/* ---------- B-1. 카메라 안내 ---------- */
.permission, .error { background: #fff; }
.perm-body, .err-body { flex: 1; padding: calc(48px + var(--safe-t)) 24px 0; }
.perm-icon { width: 88px; height: 88px; border-radius: 28px; background: #e8f0ff; color: var(--cass); display: grid; place-items: center; }
.perm-body h2, .err-body h2 { font-size: 26px; letter-spacing: -.6px; margin: 22px 0 14px; }
.perm-list { padding-left: 20px; margin: 0; line-height: 1.6; font-size: 16px; }
.perm-list li { margin-bottom: 10px; }
.perm-hint { background: var(--bg); border-radius: 12px; padding: 12px 14px; font-size: 14px; color: var(--muted); }

/* ---------- 오류 ---------- */
.err-icon { width: 72px; height: 72px; border-radius: 50%; background: #ffe7ea; color: var(--danger); display: grid; place-items: center; font-size: 40px; font-weight: 900; }
.err-body p { line-height: 1.6; font-size: 16px; }
.err-body ol { padding-left: 20px; line-height: 1.6; font-size: 15px; }
.err-code { color: #9aa7bd; font-size: 12px; font-family: ui-monospace, Menlo, monospace; }

/* ---------- AR ---------- */
.ar { background: #000; overflow: hidden; }
.ar-stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.ar-video { position: absolute; object-fit: fill; z-index: 0; }
.ar-mask { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; pointer-events: none; }
.ar-canvas { position: absolute; inset: 0; z-index: 2; width: 100% !important; height: 100% !important; }
.ar-hud { position: absolute; inset: 0; z-index: 3; pointer-events: none; display: flex; flex-direction: column; }
.ar-hud button, .ar-hud a, .ar-hud .tips { pointer-events: auto; }
.topbar.dark { color: #fff; }

.scan-guide { position: relative; margin: auto; width: min(46vw, 210px); aspect-ratio: 0.5; max-height: 52vh; transition: opacity .25s ease; }
.scan-guide .c { position: absolute; width: 44px; height: 44px; border: 5px solid #fff; border-radius: 6px; filter: drop-shadow(0 0 6px rgba(0,0,0,.4)); }
.scan-guide .tl { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.scan-guide .tr { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.scan-guide .bl { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.scan-guide .br { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.scan-line { position: absolute; left: 8%; right: 8%; height: 3px; background: linear-gradient(90deg, transparent, var(--yellow), transparent); animation: scan 2.2s ease-in-out infinite; }
@keyframes scan { 0%, 100% { top: 10%; } 50% { top: 88%; } }
.ar[data-state="found"] .scan-guide,
.ar[data-state="transforming"] .scan-guide,
.ar[data-state="collected"] .scan-guide,
.ar[data-state="loading"] .scan-guide { opacity: 0; }
.ar[data-state="lost"] .scan-guide .c { border-color: var(--yellow); }

.status {
  margin: 0 12px calc(14px + var(--safe-b)); padding: 14px 16px 16px; border-radius: 20px;
  background: rgba(255,255,255,.96); color: var(--ink); box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.status-badge { display: inline-block; font-size: 12px; font-weight: 900; padding: 4px 10px; border-radius: 999px; background: #e8f0ff; color: var(--cass); margin-bottom: 6px; }
.status-title { font-size: 20px; font-weight: 900; letter-spacing: -.4px; line-height: 1.3; }
.status-sub { font-size: 14px; color: var(--muted); margin-top: 4px; line-height: 1.45; }
.tap-dots { display: none; gap: 8px; margin-top: 10px; }
.tap-dots i { flex: 1; height: 10px; border-radius: 6px; background: #e1e8f5; transition: background .2s ease; }
.tap-dots i.on { background: var(--cass); }
.ar[data-state="found"] .tap-dots, .ar[data-state="lost"] .tap-dots.keep { display: flex; }
.ar[data-state="found"] .status-badge { background: var(--cass); color: #fff; }
.ar[data-state="lost"] .status-badge { background: #fff1c2; color: #7a5800; }
.ar[data-state="collected"] .status { display: none; }
.tips { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; line-height: 1.5; }
.tips ul { margin: 6px 0 0; padding-left: 18px; }
.tips a { color: var(--cass); font-weight: 700; }

.tap-ring { position: absolute; z-index: 4; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; border: 3px solid rgba(255,255,255,.85); pointer-events: none; animation: ring .45s ease-out forwards; }
.tap-ring.hit { border-color: var(--yellow); border-width: 5px; }
@keyframes ring { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
.tap-pop { position: absolute; z-index: 4; pointer-events: none; font-weight: 900; font-size: 28px; color: var(--yellow); text-shadow: 0 2px 8px rgba(0,0,0,.6); animation: pop .7s ease-out forwards; transform: translate(-50%, -50%); }
@keyframes pop { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -60px; } }

.sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; background: #fff; border-radius: 24px 24px 0 0; padding: 18px 16px calc(16px + var(--safe-b)); box-shadow: 0 -10px 30px rgba(0,0,0,.25); animation: up .35s cubic-bezier(.2,.9,.3,1.2); }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.collect-head { display: flex; justify-content: space-between; align-items: center; }
.burst { background: var(--yellow); color: var(--navy); font-weight: 900; padding: 6px 14px; border-radius: 999px; font-size: 15px; }
#collect-dup { font-size: 13px; font-weight: 800; color: var(--cass); }
.collect-row { display: flex; gap: 14px; align-items: center; margin: 10px 0 14px; }
.collect-row img { width: 96px; height: 96px; flex: none; background: var(--bg); border-radius: 18px; }
.collect-row h2 { margin: 0; font-size: 26px; letter-spacing: -.5px; }
.collect-row p { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.collect-row .collect-count { color: var(--cass); font-weight: 800; }
.collect .btn.primary { background: var(--cass); color: #fff; box-shadow: none; }

.overlay { position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; gap: 14px; padding: 24px; color: #fff; }
.overlay.center { align-items: center; justify-content: center; text-align: center; background: var(--navy); }
.overlay.dim { background: rgba(0, 20, 60, .88); }
.overlay .btn { max-width: 340px; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255,255,255,.25); border-top-color: var(--yellow); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 모달 ---------- */
.modal { position: fixed; inset: 0; z-index: 10; background: rgba(0, 10, 35, .6); display: flex; align-items: flex-end; justify-content: center; }
.modal-card { background: #fff; width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; border-radius: 24px 24px 0 0; padding: 16px 16px calc(18px + var(--safe-b)); animation: up .3s ease-out; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 22px; letter-spacing: -.4px; }
.modal-head .icon-btn { background: var(--bg); color: var(--ink); }
.dex-summary { color: var(--muted); font-size: 14px; margin: 6px 0 12px; }
.dex-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.dex-card { border-radius: 18px; background: var(--bg); padding: 10px 6px 12px; text-align: center; position: relative; }
.dex-card img { width: 100%; max-width: 110px; aspect-ratio: 1; }
.dex-card .nm { font-weight: 900; font-size: 15px; margin-top: 2px; }
.dex-card .st { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dex-card.got { background: #e8f0ff; }
.dex-card.got .st { color: var(--cass); font-weight: 800; }
.dex-card .cnt { position: absolute; top: 8px; right: 8px; background: var(--cass); color: #fff; font-weight: 900; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.dex-card .fallback { width: 80px; height: 80px; margin: 10px auto; border-radius: 50%; }

.log-summary { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.log-summary span { font-size: 12px; background: var(--bg); border-radius: 8px; padding: 4px 8px; font-family: ui-monospace, Menlo, monospace; }
.log-actions { display: flex; gap: 8px; align-items: center; }
.log-actions select { flex: 1; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); padding: 0 10px; font: inherit; font-size: 14px; background: #fff; }
.log-list { margin-top: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 11px; line-height: 1.45; }
.log-item { border-top: 1px solid var(--line); padding: 6px 0; word-break: break-all; }
.log-item b { color: var(--cass); }
.log-item .t { color: var(--muted); }

/* ---------- 디버그 ---------- */
.debug { position: fixed; z-index: 20; left: 8px; top: calc(64px + var(--safe-t)); max-width: calc(100vw - 16px); background: rgba(0,0,0,.72); color: #9effa8; border-radius: 10px; padding: 8px 10px; font-family: ui-monospace, Menlo, monospace; font-size: 11px; pointer-events: auto; }
.debug pre { margin: 0; white-space: pre-wrap; }
.debug-actions { display: flex; gap: 6px; margin-top: 6px; }
.debug-actions button { font-size: 11px; background: #223; color: #fff; border: 1px solid #556; border-radius: 6px; padding: 4px 8px; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); background: rgba(0,10,35,.9); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 700; max-width: calc(100vw - 32px); text-align: center; }

@media (min-width: 640px) {
  .intro-bottom, .bottom-actions { max-width: 520px; width: 100%; margin-left: auto; margin-right: auto; }
  .status, .sheet { max-width: 520px; margin-left: auto; margin-right: auto; }
  .sheet { left: 0; right: 0; }
}
