/* Galmuri 픽셀 글꼴 (OFL, assets/fonts/OFL.md) */
@font-face { font-family: Galmuri11; src: url("assets/fonts/Galmuri11.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: Galmuri11; src: url("assets/fonts/Galmuri11-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: Galmuri9; src: url("assets/fonts/Galmuri9.woff2") format("woff2"); font-weight: 400; font-display: swap; }

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #000; color: #fff;
  font-family: Galmuri11, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
button { font: inherit; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.back-btn {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); z-index: 40;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; color: #fff; text-decoration: none; font-size: 13px;
  background: rgba(0, 0, 0, 0.55); border: 2px solid #000; box-shadow: inset 2px 2px rgba(255, 255, 255, 0.18);
  text-shadow: 2px 2px #222;
}
.back-btn:hover { color: #ffffa0; }
body.playing .back-btn { display: none; }

/* --- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 6; display: none; }
body.playing #hud, body.paused #hud, body.inv #hud { display: block; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%); mix-blend-mode: difference; }
#crosshair::before, #crosshair::after { content: ''; position: absolute; background: #fff; }
#crosshair::before { left: 10px; top: 0; width: 2px; height: 22px; }
#crosshair::after { left: 0; top: 10px; width: 22px; height: 2px; }
#underwater { position: absolute; inset: 0; background: rgba(20, 60, 160, 0.32); opacity: 0; transition: opacity 0.15s; }
#underwater.on { opacity: 1; }
#debug {
  position: absolute; top: 8px; left: 8px; font-family: Galmuri9, monospace; font-size: 12px; line-height: 1.5;
  white-space: pre; background: rgba(0, 0, 0, 0.45); padding: 4px 8px; display: none; text-shadow: 1px 1px #000;
}
#debug.show { display: block; }
#toast {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%); font-size: 15px; padding: 6px 14px;
  background: rgba(0, 0, 0, 0.5); opacity: 0; transition: opacity 0.3s; text-shadow: 2px 2px #222; white-space: nowrap;
}
#toast.show { opacity: 1; }
#lock-hint {
  position: absolute; left: 50%; top: 60%; transform: translateX(-50%); padding: 8px 16px; font-size: 15px;
  background: rgba(0, 0, 0, 0.6); display: none; text-shadow: 2px 2px #222;
}
#lock-hint.show { display: block; }
#item-name {
  position: absolute; left: 50%; bottom: calc(var(--slot) + 30px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  font-size: 15px; text-shadow: 2px 2px #3f3f3f; opacity: 0; transition: opacity 0.4s; white-space: nowrap;
}
#item-name.show { opacity: 1; transition: none; }

:root { --slot: min(46px, 10.4vw); }
#hotbar {
  position: absolute; left: 50%; bottom: calc(8px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; background: rgba(0, 0, 0, 0.5); border: 2px solid #000; box-shadow: inset 0 0 0 2px #6f6f6f;
  padding: 2px; pointer-events: auto; z-index: 8;
}
.slot { width: var(--slot); height: var(--slot); position: relative; display: grid; place-items: center; cursor: pointer; }
.slot img { width: 78%; height: 78%; image-rendering: pixelated; pointer-events: none; }
.slot::after { content: ''; position: absolute; inset: 0; border: 2px solid rgba(160, 160, 160, 0.55); }
.slot.sel::after { inset: -3px; border: 3px solid #fff; box-shadow: 0 0 0 2px #000; z-index: 2; }

#stats {
  position: absolute; left: 50%; bottom: calc(var(--slot) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: calc(var(--slot) * 9 + 8px); display: none; justify-content: space-between; align-items: flex-end;
}
body.survival #stats { display: flex; }
#hearts, #bubbles, #food { display: flex; gap: 1px; }
#bubbles, #food { flex-direction: row-reverse; }
.rstats { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
#hearts img, #bubbles img, #food img { width: min(18px, 3.9vw); height: min(18px, 3.9vw); image-rendering: pixelated; }
#hearts.blink img { animation: blink 0.15s steps(1) 3; }
@keyframes blink { 50% { filter: brightness(2.2); } }
#hurt { position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(255, 0, 0, 0) 40%, rgba(220, 0, 0, 0.55) 100%); opacity: 0; transition: opacity 0.35s; }
#hurt.on { opacity: 1; transition: none; }
.slot .cnt, .islot .cnt {
  position: absolute; right: 2px; bottom: 0; font-size: 13px; color: #fff; text-shadow: 2px 2px #3f3f3f; pointer-events: none; z-index: 3;
}
.slot .dur, .islot .dur { position: absolute; left: 12%; right: 12%; bottom: 8%; height: 3px; background: #000; display: none; z-index: 3; pointer-events: none; }
.slot .dur b, .islot .dur b { display: block; height: 100%; }

/* --- 화면 공통 */
.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; z-index: 20; padding: 16px; }
.screen.show { display: flex; }
.screen.dim { background: rgba(0, 0, 0, 0.55); }
.panel {
  width: min(420px, 94vw); max-height: 92vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 18px;
  background: linear-gradient(rgba(0, 0, 0, 0.58), rgba(0, 0, 0, 0.58)), url(assets/tiles/dirt.png) 0 0 / 64px;
  border: 3px solid #000; box-shadow: inset 2px 2px rgba(255, 255, 255, 0.15), inset -2px -2px rgba(0, 0, 0, 0.5);
}
.panel.wide { width: min(640px, 94vw); }
.panel h2 { margin: 0 0 4px; text-align: center; font-size: 20px; font-weight: 400; text-shadow: 2px 2px #3f3f3f; }
.panel h3 { margin: 0 0 6px; font-size: 15px; font-weight: 400; color: #ffff70; text-shadow: 2px 2px #3f3f3f; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.mc-btn {
  width: 100%; min-height: 44px; padding: 8px 10px; color: #fff; cursor: pointer; font-size: 16px; text-shadow: 2px 2px #3f3f3f;
  background: linear-gradient(rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.32)), url(assets/tiles/stone.png) center / 72px;
  border: 2px solid #000; box-shadow: inset 2px 2px rgba(255, 255, 255, 0.4), inset -2px -3px rgba(0, 0, 0, 0.45);
}
.mc-btn:hover, .mc-btn:focus-visible { color: #ffffa0; outline: none; filter: brightness(1.12); box-shadow: inset 0 0 0 2px #fff, inset 2px 2px rgba(255, 255, 255, 0.4), inset -2px -3px rgba(0, 0, 0, 0.45); }
.mc-btn:disabled { color: #a0a0a0; filter: grayscale(0.6) brightness(0.8); cursor: default; }
.mc-btn:active { filter: brightness(0.92); }

/* --- 타이틀 */
#title { background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0.55) 100%); justify-content: center; gap: 36px; }
.logo { position: relative; text-align: center; }
.logo h1 {
  margin: 0; font-size: clamp(42px, 10vw, 104px); font-weight: 700; line-height: 1.1; letter-spacing: 0.02em;
  background: linear-gradient(rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0.15)), url(assets/tiles/stone.png) 0 0 / 56px;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 1px #000) drop-shadow(4px 5px 0 #1d1d1d) drop-shadow(0 0 1px #000);
}
.splash {
  position: absolute; right: -6%; bottom: -18%; color: #ffff3c; font-size: clamp(14px, 2.6vw, 22px); text-shadow: 2px 2px #3f3f00;
  transform: rotate(-14deg); animation: splash 0.55s ease-in-out infinite alternate; white-space: nowrap;
}
@keyframes splash { to { transform: rotate(-14deg) scale(1.1); } }
.menu { width: min(400px, 88vw); display: flex; flex-direction: column; gap: 10px; }
.title-foot { position: absolute; left: 0; right: 0; bottom: calc(10px + env(safe-area-inset-bottom)); display: flex; justify-content: space-between; padding: 0 14px; font-size: 12px; color: #ddd; text-shadow: 2px 2px #222; }

/* --- 새 월드·설정 */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field small { color: #bbb; }
.field input {
  font: inherit; font-size: 16px; padding: 9px 10px; color: #fff; background: #000; border: 2px solid #a0a0a0; outline: none; -webkit-user-select: text; user-select: text;
}
.field input:focus { border-color: #fff; }
.warn { margin: 0; font-size: 13px; color: #ff8080; }
.slider { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 14px; }
.slider b { font-weight: 400; color: #ffff70; }
.slider input { grid-column: 1 / -1; width: 100%; accent-color: #7dbb4c; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: #7dbb4c; }

.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.help-cols ul { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.75; }
kbd { font-family: inherit; font-size: 12px; padding: 0 5px; background: #333; border: 1px solid #777; border-bottom-width: 2px; }
@media (max-width: 560px) { .help-cols { grid-template-columns: 1fr; } }

/* --- 블록 팔레트 (크리에이티브 인벤토리) */
.panel.inv {
  width: min(560px, 96vw); background: #c6c6c6; color: #3f3f3f;
  border: 3px solid #000; box-shadow: inset 3px 3px #fff, inset -3px -3px #555; padding: 14px;
}
.inv-head { display: flex; align-items: center; justify-content: space-between; }
.panel.inv h2 { color: #3f3f3f; text-shadow: none; text-align: left; font-size: 17px; margin: 0; }
.panel.inv .hint { margin: 0; font-size: 12px; color: #555; }
.x-btn { width: 34px; height: 34px; cursor: pointer; background: #8b8b8b; border: 2px solid #000; color: #fff; box-shadow: inset 2px 2px #c8c8c8, inset -2px -2px #555; }
#palette, #inv-hotbar { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 3px; }
#inv-hotbar { grid-template-columns: repeat(9, 1fr); margin-top: 6px; }
.islot {
  aspect-ratio: 1; display: grid; place-items: center; background: #8b8b8b; cursor: pointer;
  box-shadow: inset 2px 2px #373737, inset -2px -2px #fff; position: relative;
}
.islot img { width: 76%; height: 76%; image-rendering: pixelated; pointer-events: none; }
.islot:hover { background: #a8a8a8; }
.islot.sel { box-shadow: inset 0 0 0 3px #fff, 0 0 0 2px #000; }
#inv-name, #sinv-name { min-height: 20px; font-size: 14px; text-align: center; color: #3f3f3f; }

/* --- 서바이벌 인벤토리·제작대·화로 */
.panel.sinv { width: min(470px, 96vw); gap: 8px; }
#inv-main, #inv-hot { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; }
#inv-hot { margin-top: 4px; }
.craft-area, .furnace-area { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 6px 0; }
#cgrid { display: grid; gap: 3px; }
#cgrid[data-size="2"] { grid-template-columns: repeat(2, 46px); }
#cgrid[data-size="3"] { grid-template-columns: repeat(3, 46px); }
#cgrid .islot, #cresult-wrap .islot, .furnace-area .islot { width: 46px; }
#cresult-wrap .islot, #f-out-wrap .islot { width: 58px; }
.arrow { font-size: 28px; color: #8b8b8b; }
#survinv .furnace-area { display: none; }
#survinv[data-mode="furnace"] .furnace-area { display: flex; }
#survinv[data-mode="furnace"] .craft-area { display: none; }
.fcol { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.flame { width: 22px; height: 22px; background: #8b8b8b; position: relative; box-shadow: inset 2px 2px #373737; }
.flame i { position: absolute; left: 3px; right: 3px; bottom: 0; background: linear-gradient(#ffe066, #ff6a00); }
.farrow { width: 60px; height: 16px; background: #8b8b8b; box-shadow: inset 2px 2px #373737; position: relative; }
.farrow i { position: absolute; left: 0; top: 0; bottom: 0; background: #fff; width: 0; }
.panel.inv .touch-hint { display: none; }
body.touch .panel.inv .touch-hint { display: block; }
body.touch .panel.inv .pc-hint { display: none; }
#cursor-stack { position: fixed; left: 0; top: 0; width: 46px; z-index: 50; pointer-events: none; margin: -23px 0 0 -23px; background: none; box-shadow: none; display: none; }
#cursor-stack img { width: 80%; height: 80%; }

/* --- 새 월드 모드 선택 */
.mode-pick .mc-btn.on { color: #ffffa0; box-shadow: inset 0 0 0 2px #fff, inset 2px 2px rgba(255, 255, 255, 0.4), inset -2px -3px rgba(0, 0, 0, 0.45); }

/* --- 사망 */
#death { background: rgba(120, 0, 0, 0.5); gap: 16px; }
#death h2 { margin: 0; font-size: clamp(32px, 7vw, 56px); font-weight: 400; text-shadow: 3px 3px #3f0000; }
#death p { margin: 0; font-size: 15px; text-shadow: 2px 2px #3f0000; }

/* --- 로딩 */
#loading { position: fixed; left: 50%; bottom: 22%; transform: translateX(-50%); z-index: 30; width: min(360px, 80vw); display: none; text-align: center; text-shadow: 2px 2px #222; }
#loading.show { display: block; }
.ltext { font-size: 15px; margin-bottom: 8px; }
.lbar { height: 8px; background: #333; border: 2px solid #000; }
.lbar i { display: block; height: 100%; width: 0; background: #80ff20; }

/* --- 터치 조작 */
#touch { display: none; }
body.touch.playing #touch { display: block; }
#touch-zone { position: fixed; inset: 0; z-index: 5; }
#joy {
  position: fixed; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; z-index: 6; display: none;
  background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.35); pointer-events: none;
}
#joy.on { display: block; }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); transform: translate(-50%, -50%); }
.tbtn {
  position: fixed; z-index: 7; width: 58px; height: 58px; color: #fff; font-size: 13px; text-shadow: 1px 1px #000;
  background: rgba(0, 0, 0, 0.35); border: 2px solid rgba(255, 255, 255, 0.4); padding: 0;
}
.tbtn.on { background: rgba(255, 255, 255, 0.3); }
#t-jump { right: calc(18px + env(safe-area-inset-right)); bottom: calc(var(--slot) + 34px + env(safe-area-inset-bottom)); width: 68px; height: 68px; font-size: 22px; }
#t-sneak, #t-down { right: calc(96px + env(safe-area-inset-right)); bottom: calc(var(--slot) + 34px + env(safe-area-inset-bottom)); font-size: 12px; }
#t-down { font-size: 20px; display: none; }
body.flying #t-down { display: block; }
body.flying #t-sneak { display: none; }
#t-sneak.active { background: rgba(120, 200, 80, 0.45); }
#t-fly { right: calc(18px + env(safe-area-inset-right)); bottom: calc(var(--slot) + 112px + env(safe-area-inset-bottom)); width: 68px; height: 40px; font-size: 13px; }
body.flying #t-fly { background: rgba(120, 200, 80, 0.45); }
body.survival #t-fly { display: none; }
#t-inv { right: calc(18px + env(safe-area-inset-right)); top: calc(12px + env(safe-area-inset-top)); width: 46px; height: 46px; font-size: 22px; }
#t-pause { right: calc(72px + env(safe-area-inset-right)); top: calc(12px + env(safe-area-inset-top)); width: 46px; height: 46px; font-size: 16px; }
