/* 핀 뽑아라 냥
   해 질 녘 동굴 톤. 바탕은 짙은 밤색, 포인트는 엽전 금색과 부적 빨강. */
:root {
  --bg: #1d1520;
  --surface: #2e2230;
  --surface-2: #3d2d3c;
  --ink: #fff4ea;
  --sub: #d1b9b0;
  --line: #4a3846;
  --accent: #ffc93c;
  --accent-ink: #2e1a00;
  --red: #e8413a;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
  --game: "Jua", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --body: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color-scheme: dark;
}
body { background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.55; }
h1, h2, h3 { font-family: var(--game); font-weight: 400; margin: 0; text-wrap: balance; }
p { margin: 0; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.stage { max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 6px; }
.logo { font-family: var(--game); font-size: 18px; color: var(--ink); text-decoration: none; letter-spacing: 0.04em; }
.logo b { color: #ff4867; font-weight: 400; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); display: grid; place-items: center; }
.icon-btn svg { width: 20px; height: 20px; }

.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; padding: 8px 16px calc(env(safe-area-inset-bottom, 0px) + 16px); }
.screen.measuring > *, .screen.scrollable > * { flex-shrink: 0; }
.sub { color: var(--sub); }
.small { font-size: 13px; }
.center { text-align: center; }
.fine { font-size: 12px; color: var(--sub); text-align: center; }

.btn { min-height: 52px; border-radius: 16px; border: 0; padding: 10px 16px; font-size: 16px; font-weight: 700; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); transition: transform .08s ease; text-decoration: none; display: grid; place-items: center; text-align: center; line-height: 1.25; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-family: var(--game); font-weight: 400; font-size: 22px; box-shadow: 0 6px 0 #b47a08, var(--shadow); line-height: 1.15; }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #b47a08, var(--shadow); }
.btn.primary small { display: block; font-family: var(--body); font-size: 12px; font-weight: 700; opacity: .75; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--sub); font-weight: 400; min-height: 44px; }
.btn.daily { display: flex; flex-direction: column; gap: 0; font-family: var(--game); font-weight: 400; font-size: 19px; background: var(--surface-2); border: 2px solid rgba(255, 201, 60, .35); }
.btn.daily .sub { font-family: var(--body); font-weight: 700; }
.btn.daily.hot { border-color: var(--accent); animation: glow 1.4s ease-in-out infinite alternate; }
.btn small.sub { font-size: 12px; }
@keyframes glow { from { box-shadow: 0 0 0 0 rgba(255, 201, 60, .7), var(--shadow); } to { box-shadow: 0 0 0 7px rgba(255, 201, 60, 0), var(--shadow); } }
.actions { display: grid; gap: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chip { display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 5px 12px; border-radius: 99px; background: var(--surface); border: 0; color: var(--ink); font-size: 13px; font-weight: 700; }
.chip.new { background: var(--accent); color: var(--accent-ink); animation: pop .5s ease-out both .6s; align-self: center; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px; z-index: 20; white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis; }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
.coin { display: inline-block; width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle, transparent 3px, #ffd23f 3.5px, #e0a020 7px); box-shadow: inset 0 0 0 1px #8a5a00; flex: none; vertical-align: -2px; }
.purse { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--sub); }
.purse b { font-family: var(--game); font-weight: 400; font-size: 20px; color: var(--accent); }
.invite { text-align: center; background: rgba(255, 201, 60, .14); border: 1px dashed var(--accent); border-radius: 14px; padding: 8px 12px; font-size: 14px; word-break: keep-all; }
.invite b { color: var(--accent); }

/* ---- 시작 화면: 동굴 앞 */
.hall { position: relative; width: 100%; aspect-ratio: 4 / 3.4; border-radius: 24px; overflow: hidden; background: #2a1e33; box-shadow: var(--shadow); isolation: isolate; flex: none; }
.hall .bg { position: absolute; inset: 0; background: url("sprites/bg-start.webp") center 58% / cover no-repeat, linear-gradient(#8a6ad0, #e88a5a); animation: kenburns 18s ease-in-out infinite alternate; }
@keyframes kenburns { to { transform: scale(1.06) translateY(-1.5%); } }
.motes i { position: absolute; left: calc(8% + var(--i) * 10%); bottom: 10%; width: 6px; height: 6px; border-radius: 50%; background: #ffe9a0; box-shadow: 0 0 10px 3px rgba(255, 210, 110, .75); opacity: 0; animation: mote 5.5s ease-in infinite; animation-delay: calc(var(--i) * -.61s); }
@keyframes mote { 0% { opacity: 0; transform: translate(0, 0); } 20% { opacity: .9; } 100% { opacity: 0; transform: translate(14px, -200px); } }
.hall-hero { position: absolute; left: 6%; bottom: -2%; width: 46%; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .5)); z-index: 2; }
.bubble { position: absolute; right: 4%; top: 7%; max-width: 52%; background: #fff; color: #2a1d38; border-radius: 16px 16px 4px 16px; padding: 7px 12px; font-family: var(--game); font-size: 15px; line-height: 1.35; box-shadow: var(--shadow); word-break: keep-all; z-index: 4; }
.bubble.pop { animation: pop .3s ease-out; }
.hero-title { text-align: center; display: flex; flex-direction: column; gap: 4px; }
.hero-title h1 { font-size: 46px; line-height: 1.05; text-shadow: 0 3px 0 #000a; }
.hero-title h1 em { font-style: normal; color: var(--accent); }
.hero-title .lede { color: var(--sub); font-size: 15px; word-break: keep-all; }

/* ---- 마을 지도 */
.screen-title { font-size: 28px; text-align: center; }
.village { position: relative; border-radius: 20px; padding: 12px; overflow: hidden; background: var(--surface); isolation: isolate; box-shadow: var(--shadow); }
.village::before { content: ""; position: absolute; inset: 0; background: var(--vbg) center 40% / cover no-repeat; opacity: .55; z-index: -1; }
.village::after { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(20, 12, 24, .2), rgba(20, 12, 24, .75)); z-index: -1; }
.village h3 { font-size: 20px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; text-shadow: 0 2px 0 #0008; }
.village h3 span { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 15px; }
.village h3 small { font-family: var(--body); font-size: 12px; color: #f0dccf; flex-basis: 100%; }
.village.locked { filter: grayscale(.8) brightness(.7); }
.lv-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.lv { width: 100%; aspect-ratio: 1 / 1.1; border: 0; border-radius: 12px; background: rgba(30, 20, 34, .82); color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px; box-shadow: 0 3px 0 rgba(0, 0, 0, .4); }
.lv b { font: 15px/1 var(--game); }
.lv span { font-size: 10px; letter-spacing: -1px; color: var(--accent); }
.lv:disabled span { color: var(--sub); letter-spacing: 0; }
.lv.done { background: rgba(80, 52, 20, .9); }
.lv.next { background: var(--accent); color: var(--accent-ink); animation: glow 1.2s ease-in-out infinite alternate; }
.lv.next span { color: #7a4d00; }

/* ---- 도감 */
.dex-h { display: flex; align-items: baseline; gap: 8px; font-size: 20px; margin-top: 6px; }
.dex-h small { font-family: var(--body); font-size: 13px; color: var(--accent); }
.dex-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.dex-grid.five { grid-template-columns: repeat(5, 1fr); }
.dex-grid.four { grid-template-columns: repeat(4, 1fr); }
.dex-grid li { display: contents; }
.dex-card { background: var(--surface); border-radius: 14px; padding: 6px 2px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; }
.dex-card img { width: 100%; max-width: 64px; aspect-ratio: 1; object-fit: contain; }
.dex-card.unseen img { filter: brightness(0) opacity(.45); }
.dex-card b { font: 12px/1.2 var(--game); word-break: keep-all; }
.dex-card .cnt { font-size: 11px; color: var(--accent); font-weight: 700; }

/* ---- 판 */
.stage.playing .topbar { display: none; }
.stage.playing .screen { padding: 0; gap: 0; }
.play { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #17141f; touch-action: none; }
.play canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud { position: absolute; left: 0; right: 0; top: 0; padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 0; pointer-events: none; }
.hud-row { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 6px; }
.hud .hb { pointer-events: auto; background: rgba(0, 0, 0, .5); box-shadow: none; }
.where { text-align: center; display: flex; flex-direction: column; line-height: 1.15; color: #fff; text-shadow: 0 2px 0 #000a; }
.where b { font: 18px var(--game); font-weight: 400; }
.where span { font-size: 13px; color: var(--accent); }
.foot { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 8px; padding: 0 10px calc(env(safe-area-inset-bottom, 0px) + 10px); pointer-events: none; }
.hint-btn { pointer-events: auto; flex: none; min-width: 74px; min-height: 52px; border: 0; border-radius: 16px; background: var(--accent); color: var(--accent-ink); display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 4px 0 #b47a08, var(--shadow); touch-action: manipulation; }
.hint-btn b { font: 19px/1 var(--game); font-weight: 400; }
.hint-btn small { font-size: 11px; font-weight: 700; }
.hint-btn:active { transform: translateY(2px); }
.hint-btn.off { filter: saturate(.2) brightness(.7); }
.hint-btn.busy { animation: glow .5s ease-in-out infinite alternate; }
.tipline { flex: 1; min-width: 0; font: 15px/1.3 var(--game); color: #fff; text-shadow: 0 2px 2px #000; word-break: keep-all; transition: opacity .6s; }
.tipline.dim { opacity: .45; }
.banner { position: absolute; left: 50%; top: 22%; transform: translate(-50%, -50%); max-width: 92%; text-align: center; font: 22px/1.25 var(--game); color: #fff; text-shadow: 0 3px 0 #000, 0 0 12px #000; pointer-events: none; opacity: 0; word-break: keep-all; z-index: 3; }
.banner.on { animation: banner 1s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 1; } }
.overlay { position: absolute; inset: 0; background: rgba(20, 10, 24, .7); display: grid; place-items: center; padding: 16px; z-index: 5; backdrop-filter: blur(2px); overflow-y: auto; }
.overlay[hidden] { display: none; }
.panel { width: 100%; max-width: 400px; background: var(--surface); border-radius: 22px; padding: 18px 14px; display: flex; flex-direction: column; gap: 10px; align-items: stretch; text-align: center; box-shadow: var(--shadow); animation: pop .3s ease-out; }
.panel h2 { font-size: 30px; color: var(--accent); }
.panel.fail h2 { color: #ffb3c0; }
.kicker { font: 15px var(--game); color: var(--sub); }
.big-stars { font-size: 48px; line-height: 1; display: flex; justify-content: center; gap: 6px; }
.big-stars i { font-style: normal; color: rgba(255, 255, 255, .18); }
.big-stars i.on { color: #ffd23f; text-shadow: 0 0 14px rgba(255, 210, 60, .8); animation: starpop .45s cubic-bezier(.2, 1.6, .4, 1) both; animation-delay: var(--d); }
@keyframes starpop { from { transform: scale(2.4) rotate(-30deg); opacity: 0; } }
.got { display: flex; align-items: center; justify-content: center; gap: 10px; background: rgba(255, 201, 60, .12); border-radius: 16px; padding: 6px 10px; animation: pop .5s ease-out both 1s; }
.got img { width: 64px; height: 64px; object-fit: contain; filter: drop-shadow(0 0 8px rgba(255, 220, 120, .8)); }
.got b, .earn b, .rate b, .village-won b { color: var(--accent); }
.earn { display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 700; }
.earn b { font: 22px var(--game); font-weight: 400; }
.rate { font-size: 15px; }
.village-won { background: linear-gradient(90deg, #4a2a10, #7a4a14); border: 2px solid var(--accent); border-radius: 14px; padding: 8px 12px; word-break: keep-all; font-size: 14px; animation: pop .5s ease-out both .8s; }
.fail-art { width: 62%; align-self: center; filter: drop-shadow(0 8px 12px rgba(0, 0, 0, .5)); animation: wobble 1.6s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes wobble { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg) scaleY(.97); } }
.say-line { font: 17px/1.4 var(--game); word-break: keep-all; }

.cardimg { width: 100%; border-radius: 18px; box-shadow: var(--shadow); -webkit-touch-callout: default; user-select: auto; }

/* ---- 아래 설명 글 */
.guide { max-width: 480px; margin: 0 auto; padding: 32px 16px 64px; display: flex; flex-direction: column; gap: 28px; }
.guide section { display: flex; flex-direction: column; gap: 10px; }
.guide h2 { font-size: 24px; }
.guide p, .guide li { font-size: 15px; max-width: 65ch; }
.guide a { color: var(--accent); }
.guide ul, .guide ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.arcana { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; list-style: none; padding: 0 !important; }
.arcana li { background: var(--surface); border-radius: 14px; padding: 8px 12px; font-size: 13px; }
.arcana b { display: block; font-family: var(--game); font-weight: 400; font-size: 16px; }
.log { font-size: 14px; }
.site-foot { border-top: 1px solid var(--line); padding-top: 16px; display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; }
.site-foot a { color: var(--sub); }

/* ---- 작은 화면 */
.stage.fit1 .hall { width: 86%; align-self: center; }
.stage.fit1 .hero-title h1 { font-size: 38px; }
.stage.fit1 .btn { min-height: 46px; }
.stage.fit2 .hall { width: 66%; }
.stage.fit2 .hero-title .lede { display: none; }
.stage.fit2 .bubble { font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  .hall .bg, .motes i, .btn.daily.hot, .lv.next, .fail-art, .hint-btn.busy { animation: none !important; }
}
