/* 마을지키기 — 화면 바깥(HUD·가게·안내)의 모양. 게임 세계는 캔버스가 그린다.
   --px: 게임 도트 한 칸의 화면 크기, --fs: 글자 크기 (둘 다 main.js 가 화면에 맞춰 정한다) */
@font-face { font-family: Galmuri11; src: url(assets/font/Galmuri11.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: Galmuri11; font-weight: 700; src: url(assets/font/Galmuri11-Bold.woff2) format('woff2'); font-display: swap; }
:root {
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px); --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
  --px: 3px; --fs: 16.5px;
  --ink: #1b1630; --paper: #fff7e0; --panel: #2b2540; --panel2: #3a3256; --line: #5a4f7a;
  --gold: #ffd23f; --green: #6fdc8c; --red: #ff6b6b; --blue: #7ae0ff; --dim: #b0a8c8;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }   /* 길게 눌러도 미리보기·돋보기가 뜨지 않게 */
html, body { margin: 0; height: 100%; background: #0d0b1c; color: var(--paper); font-family: Galmuri11, 'Apple SD Gothic Neo', sans-serif; font-size: var(--fs); line-height: 1.35; overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.ico { display: inline-block; flex: none; vertical-align: middle; background-repeat: no-repeat; image-rendering: pixelated; }
canvas, img { image-rendering: pixelated; }

#stage { position: relative; margin: 0 auto; overflow: hidden; }
#game { display: block; }
#fade { position: absolute; inset: 0; background: #0d0b1c; opacity: 0; pointer-events: none; transition: opacity .28s; }
#fade.on { opacity: 1; }

/* ── 단추와 판 ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; min-height: 2.5em; padding: .35em .9em; background: #4d8f5e; color: #fff; border: var(--px) solid var(--ink); border-radius: 0; box-shadow: inset 0 calc(var(--px) * -1.5) 0 rgba(0,0,0,.28), inset 0 var(--px) 0 rgba(255,255,255,.25); text-shadow: 0 var(--px) 0 rgba(0,0,0,.35); }
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(var(--px)); box-shadow: inset 0 var(--px) 0 rgba(0,0,0,.25); }
.btn:focus-visible, .mini:focus-visible, .row .btn:focus-visible { outline: var(--px) solid var(--gold); outline-offset: var(--px); }
.btn.big { font-size: 1.2em; min-width: 9em; background: #e0862d; }
.btn.alt { background: #55708f; }
.btn.plain { background: var(--panel2); }
.btn.warn { background: #b84a4a; }
.btn:disabled { background: #57506b; color: var(--dim); cursor: default; filter: none; }
.btn kbd { font: inherit; font-size: .8em; padding: 0 .35em; background: rgba(0,0,0,.3); border: calc(var(--px) / 2) solid rgba(255,255,255,.35); }
.mini { min-width: 2.2em; height: 2.2em; padding: 0 .4em; background: var(--panel); color: var(--paper); border: var(--px) solid var(--ink); }
.box { background: var(--panel); border: var(--px) solid var(--ink); box-shadow: inset 0 0 0 var(--px) var(--line); }

/* ── 전투 HUD ── */
#hud { position: absolute; inset: 0; pointer-events: none; padding: calc(var(--px) * 3); }
#hud button { pointer-events: auto; }
.hud-left { position: absolute; left: calc(var(--px) * 3 + var(--sl)); top: calc(var(--px) * 3 + var(--st)); display: grid; gap: calc(var(--px) * 1.5); }
.meter { display: flex; align-items: center; gap: calc(var(--px) * 2); text-shadow: var(--px) var(--px) 0 var(--ink); }
.meter span { min-width: 4.5em; font-size: .9em; }
.bar { width: calc(var(--px) * 46); height: calc(var(--px) * 5); background: #3b3350; border: var(--px) solid var(--ink); position: relative; }
.bar b { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: #c9a36a; box-shadow: inset 0 var(--px) 0 rgba(255,255,255,.35); transition: width .12s; }
.bar.hp b { background: #e5484d; } .bar.hp.two b { background: #4d8fe5; } .bar.xp { height: calc(var(--px) * 3); } .bar.xp b { background: #ffd23f; } .bar.boss { width: calc(var(--px) * 110); } .bar.boss b { background: #b14bd6; }
#lvl { font-style: normal; font-size: .85em; min-width: calc(var(--px) * 9 + 1.6em); text-align: right; }
.hud-mid { position: absolute; left: 50%; top: calc(var(--px) * 3 + var(--st)); transform: translateX(-50%); display: grid; justify-items: center; gap: calc(var(--px) * 1.5); text-align: center; text-shadow: var(--px) var(--px) 0 var(--ink); }
#wave { font-size: 1.15em; font-weight: 700; }
#wave small { font-weight: 400; font-size: .75em; color: var(--dim); margin-left: .6em; }
#boss span { font-size: .9em; }
#pot { font-size: .85em; padding: .1em .6em; background: rgba(27,22,48,.75); border: var(--px) solid var(--ink); color: var(--gold); text-shadow: none; }
.hud-right { position: absolute; right: calc(var(--px) * 3 + var(--sr)); top: calc(var(--px) * 3 + var(--st)); display: grid; justify-items: end; gap: calc(var(--px) * 2); }
#res { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: calc(var(--px) * 2); max-width: 46vw; }
.chip { display: inline-flex; align-items: center; gap: .25em; padding: 0 .45em 0 .2em; background: rgba(27,22,48,.75); border: var(--px) solid var(--ink); font-size: .9em; white-space: nowrap; }
.chip.bump { animation: bump .25s; } .chip.lack { color: var(--red); } .chip.gain { background: rgba(40,80,50,.8); }
@keyframes bump { 40% { transform: scale(1.25) translateY(-10%); background: #4d8f5e; } }
.hud-btns { display: flex; gap: calc(var(--px) * 2); }
#skills { position: absolute; left: calc(var(--px) * 3 + var(--sl)); bottom: calc(var(--px) * 3); display: flex; gap: calc(var(--px) * 2); }
.skill { display: flex; align-items: center; gap: .3em; padding: .1em .5em .1em .25em; background: rgba(27,22,48,.75); border: var(--px) solid var(--ink); font-size: .85em; }
.skill kbd { font: inherit; font-size: .85em; padding: 0 .3em; background: var(--paper); color: var(--ink); }
.skill.off { opacity: .45; }
#quest { position: absolute; right: calc(var(--px) * 3 + var(--sr)); bottom: calc(var(--px) * 3); max-width: 44vw; padding: .1em .55em; background: rgba(27,22,48,.75); border: var(--px) solid var(--ink); font-size: .85em; text-align: right; }
#quest b { color: var(--gold); font-weight: 400; }

/* ── 웨이브 사이의 띠 ── */
#band { position: absolute; left: 50%; top: calc(var(--px) * 26); transform: translateX(-50%); width: min(96%, 46em); padding: .6em .8em .7em; background: rgba(43,37,64,.96); border: var(--px) solid var(--ink); box-shadow: inset 0 0 0 var(--px) var(--line); animation: rise .22s; }
@keyframes rise { from { transform: translate(-50%, -20%); opacity: 0; } }
#band h2 { margin: 0 0 .2em; font-size: 1.25em; color: var(--gold); text-align: center; }
#band h2 small { font-size: .7em; color: var(--paper); margin-left: .6em; }
#band .cols { display: flex; gap: .8em; align-items: stretch; }
#band .col { flex: 1; min-width: 0; }
#band .loot { display: flex; flex-wrap: wrap; gap: calc(var(--px) * 2); align-items: center; min-height: 2em; }
#band .next { padding: .3em .5em; background: var(--panel2); border: var(--px) solid var(--ink); }
#band .next .mons { display: flex; flex-wrap: wrap; gap: .5em; align-items: flex-end; margin: .2em 0; }
#band .next .mon { display: inline-flex; align-items: flex-end; gap: .15em; font-size: .9em; }
#band .tip { font-size: .9em; color: var(--blue); }
#band .tip b { color: var(--gold); }
#band .note { font-size: .85em; color: var(--dim); }
#band .btns { display: flex; gap: .6em; justify-content: center; margin-top: .55em; flex-wrap: wrap; }
.stepper { display: inline-flex; align-items: center; gap: .3em; }
.stepper b { min-width: 3.2em; text-align: center; }

/* ── 가게·설정 창 ── */
#panel { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(13,11,28,.55); z-index: 5; padding: .5em; touch-action: pan-y; }
#panel > .box { width: min(100%, 44em); max-height: 100%; display: flex; flex-direction: column; animation: pop .16s; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.phead { display: flex; align-items: center; gap: .7em; padding: .5em .7em; background: var(--panel2); border-bottom: var(--px) solid var(--ink); }
.phead .who { flex: 1; min-width: 0; }
.phead h2 { margin: 0; font-size: 1.15em; }
.phead p { margin: 0; font-size: .9em; color: var(--paper); min-height: 1.35em; }
.phead .purse { display: flex; flex-wrap: wrap; gap: calc(var(--px) * 2); justify-content: flex-end; max-width: 45%; }
.pbody { overflow-y: auto; padding: .4em .5em; display: grid; gap: .35em; overscroll-behavior: contain; }
.row { display: flex; align-items: center; gap: .6em; padding: .35em .5em; background: var(--panel2); border: var(--px) solid var(--ink); }
.row .info { flex: 1; min-width: 0; }
.row .name { display: flex; align-items: baseline; gap: .5em; flex-wrap: wrap; }
.row .name small { color: var(--gold); }
.row .desc { font-size: .85em; color: var(--dim); }
.row .delta { font-size: .9em; color: var(--green); }
.row .cost { display: flex; flex-wrap: wrap; gap: calc(var(--px) * 2); margin-top: .15em; }
.row .btn { min-width: 6.5em; }
.row.new { box-shadow: inset 0 0 0 var(--px) var(--gold); }
.row .use { font-size: .8em; color: var(--dim); }
.pfoot { display: flex; justify-content: space-between; align-items: center; gap: .5em; padding: .4em .6em; border-top: var(--px) solid var(--ink); font-size: .85em; color: var(--dim); }
.set { display: grid; grid-template-columns: auto 1fr; gap: .5em .8em; align-items: center; padding: .3em .2em; }
.set input[type=range] { width: 100%; accent-color: var(--gold); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: .15em .8em; font-size: .9em; }
.keys kbd, .hint kbd { font: inherit; padding: 0 .35em; background: var(--paper); color: var(--ink); }
textarea { width: 100%; height: 4.5em; font: inherit; font-size: max(.75em, 16px); background: #1b1630; color: var(--paper); border: var(--px) solid var(--line); user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; touch-action: auto; }   /* 16px 미만이면 iOS 가 누를 때 화면을 확대한다 */
.pbody .btns { display: flex; flex-wrap: wrap; gap: .5em; margin-top: .4em; }
.keys .ico { justify-self: center; }
.fam { display: grid; grid-template-columns: 1fr auto; gap: .1em .6em; }
.fam .bar { width: 100%; }
.mons-list { display: grid; gap: .25em; }
.mons-list .m { display: flex; gap: .5em; align-items: center; font-size: .9em; }

/* ── 처음 화면 ── */
#title { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5em; background: linear-gradient(rgba(13,11,28,.15), rgba(13,11,28,.55)); text-align: center; padding: 1em; }
#logo { width: auto; height: auto; max-width: min(74%, calc(var(--px) * 352)); max-height: 48vh; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(calc(var(--px) * -3)); } }
#tagline { margin: 0; text-shadow: var(--px) var(--px) 0 var(--ink); }
#title-btns { display: flex; gap: .7em; flex-wrap: wrap; justify-content: center; margin-top: .4em; }
#title-note { margin: 0; font-size: .8em; color: var(--dim); text-shadow: var(--px) var(--px) 0 var(--ink); min-height: 1.3em; }

/* ── 알림 ── */
#toasts { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); display: grid; gap: .3em; justify-items: center; pointer-events: none; z-index: 6; width: 94%; }
.toast { display: flex; align-items: center; gap: .5em; padding: .3em .8em; background: rgba(43,37,64,.96); border: var(--px) solid var(--ink); box-shadow: inset 0 0 0 var(--px) var(--gold); animation: toast 3.2s forwards; max-width: 100%; }
.toast.big { font-size: 1.2em; }
body.touch:not(.tall) .toast.big { font-size: 1em; }
@keyframes toast { 0% { transform: translateY(-40%) scale(.9); opacity: 0; } 6% { transform: none; opacity: 1; } 86% { opacity: 1; } 100% { opacity: 0; transform: translateY(-30%); } }

/* ── 터치 조작: 글자 대신 그림 단추 ── */
#touch { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: flex-end; padding: 0 max(14px, var(--sr)) max(12px, var(--sb)) max(14px, var(--sl)); pointer-events: none; z-index: 4; }
#touch button { pointer-events: auto; position: relative; display: flex; align-items: center; justify-content: center; width: 66px; height: 66px; padding: 0; background: rgba(43,37,64,.8); color: var(--paper); border: 3px solid var(--paper); border-radius: 16px; box-shadow: inset 0 -5px 0 rgba(0,0,0,.3); touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
#touch button * { pointer-events: none; }
#touch button.on { background: rgba(224,134,45,.95); transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0,0,0,.3); }
#touch button.off { opacity: .38; }
#touch button.big { width: 86px; height: 86px; background: rgba(224,134,45,.82); border-radius: 22px; }
#touch .pad button { width: 78px; height: 78px; }
#touch .pad, #touch .acts { display: flex; gap: 12px; align-items: flex-end; }
#touch svg { width: 62%; height: 62%; }
#touch .cnt { position: absolute; right: -6px; top: -8px; min-width: 1.7em; padding: 0 .25em; background: var(--ink); border: 2px solid var(--paper); font-size: 13px; line-height: 1.5; text-align: center; }
body.tall #touch { position: static; padding: 18px 16px; }
body.tall #touch button { background: var(--panel2); }
body.tall #touch button.big { background: #e0862d; }
@media (max-width: 430px) { #touch button { width: 56px; height: 56px; } #touch .pad button { width: 64px; height: 64px; } #touch button.big { width: 72px; height: 72px; } #touch .pad, #touch .acts { gap: 8px; } }

/* ── 마을 화면 ── */
#townbar { position: absolute; inset: 0; pointer-events: none; }
#townbar > * { pointer-events: auto; }
.tb-res { position: absolute; right: calc(var(--px) * 3 + var(--sr)); top: calc(var(--px) * 3 + var(--st)); align-items: center; display: flex; flex-wrap: wrap; gap: calc(var(--px) * 2); justify-content: flex-end; max-width: 62%; }
.tb-row { position: absolute; left: 50%; bottom: calc(var(--px) * 3 + var(--sb)); transform: translateX(-50%); display: flex; gap: calc(var(--px) * 2); max-width: 98%; }
.tb { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: .1em; min-width: 3.7em; padding: .25em .4em; background: rgba(43,37,64,.92); color: var(--paper); border: var(--px) solid var(--ink); font-size: .85em; position: relative; }
.tb:hover { filter: brightness(1.2); }
.tb:focus-visible { outline: var(--px) solid var(--gold); }
.tb.has::after { content: '!'; position: absolute; right: -.35em; top: -.55em; width: 1.25em; height: 1.25em; line-height: 1.2em; background: var(--gold); color: var(--ink); border: var(--px) solid var(--ink); }
.tb.go { background: #e0862d; }
.tb-quest { position: absolute; left: calc(var(--px) * 3 + var(--sl)); top: calc(var(--px) * 3 + var(--st)); max-width: 36%; padding: .1em .55em; background: rgba(27,22,48,.75); border: var(--px) solid var(--ink); font-size: .85em; }
.tb-quest b { color: var(--gold); font-weight: 400; }
#townbar.quiet .tb-row, #townbar.quiet .tb-quest { display: none; }
body.touch:not(.tall) #townbar.quiet .tb-res { display: none; }   /* 좁은 화면에서는 띠가 위쪽을 다 쓴다 */
body:has(#title:not([hidden])) #touch { display: none; }   /* 처음 화면에서는 조작 단추를 감춘다 */
body.touch #quest { display: none; }
body.touch #skills { bottom: auto; top: calc(var(--px) * 3 + 5.4em); }
body.touch:not(.tall) #band { top: calc(var(--px) * 3); max-height: calc(100% - var(--px) * 6); overflow-y: auto; }
@media (max-width: 560px) { .meter span { display: none; } .bar { width: calc(var(--px) * 30); } .hud-mid { top: calc(var(--px) * 3 + 4.6em); } #res { max-width: 34vw; } }
body.touch:not(.tall) .tb-row { max-width: calc(100% - 300px - var(--sl) - var(--sr)); overflow-x: auto; scrollbar-width: none; }
body.touch:not(.tall) .tb { min-width: 3.1em; padding: .2em .3em; }
.tb-menu { margin-left: calc(var(--px) * 2); }
#touch button.on2 { background: rgba(77,143,94,.9); }
