* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #000; }
body {
  font-family: "Pixelify Sans", ui-monospace, monospace;
  color: #fff; user-select: none; -webkit-user-select: none;
  image-rendering: pixelated;
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; transition: filter 0.4s; }
body.menu-blur canvas#game { filter: blur(3px) brightness(0.85); }
.hidden { display: none !important; }

.sh { text-shadow: 2px 2px 0 #3f3f3f; }
button, .panel-title, .load-title, .load-sub, .keys, .foot, #item-name, #debug, .inv-head, .dead-sub, label span { text-shadow: 2px 2px 0 #3f3f3f; }

/* Screens */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; z-index: 10; }
.screen.dim { background: rgba(16, 16, 16, 0.62); }
.screen.red { background: linear-gradient(rgba(120, 0, 0, 0.55), rgba(60, 0, 0, 0.75)); }
.screen.dirt { background-color: #2b1d13; background-image: var(--dirt); background-size: 64px 64px; box-shadow: inset 0 0 0 100vmax rgba(0, 0, 0, 0.58); }
.screen.dirt > * { position: relative; }

.title-inner { display: flex; flex-direction: column; align-items: center; gap: 0; position: relative; margin-top: -6vh; }
.logo {
  position: relative; font-weight: 700; letter-spacing: 0.02em;
  font-size: clamp(56px, 10vw, 128px); line-height: 1;
  color: #9a9a9a; background: var(--stone) 0 0 / 48px 48px; -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; -webkit-text-stroke: 3px #1a1a1a;
  filter: drop-shadow(0 4px 0 #2e2e2e) drop-shadow(0 4px 0 #242424) drop-shadow(0 6px 10px rgba(0,0,0,.5));
  margin-bottom: 58px;
}
.splash {
  position: absolute; right: -4%; top: 28%; color: #ffff55; font-weight: 600; font-size: clamp(16px, 2vw, 24px);
  text-shadow: 2px 2px 0 #3f3f15; transform: rotate(-18deg); animation: splash 0.55s ease-in-out infinite alternate; white-space: nowrap;
}
@keyframes splash { from { transform: rotate(-18deg) scale(1); } to { transform: rotate(-18deg) scale(1.09); } }

.menu { display: flex; flex-direction: column; gap: 10px; width: min(400px, 88vw); }
.row { display: flex; gap: 10px; }
button.mc {
  font: inherit; font-size: 20px; color: #fff; cursor: pointer; height: 42px; width: 100%;
  background: linear-gradient(#8a8a8a, #6d6d6d 48%, #646464 52%, #5a5a5a);
  border: 2px solid #000; box-shadow: inset 2px 2px 0 rgba(255,255,255,.35), inset -2px -3px 0 rgba(0,0,0,.35);
  image-rendering: pixelated;
}
button.mc:hover, button.mc:focus-visible { outline: none; border-color: #fff; color: #ffffa0; }
button.mc:active { filter: brightness(0.92); }
button.mc.half { width: 50%; }
.foot { position: fixed; bottom: 8px; font-size: 16px; color: #fff; opacity: 0.92; }
.foot.left { left: 10px; }
.foot.right { right: 10px; }
@media (max-width: 820px) { .foot.left { display: none; } .foot.right { font-size: 13px; } }

.panel-title { font-size: 26px; margin-bottom: 8px; }

/* Options */
.opts { display: grid; grid-template-columns: repeat(2, minmax(0, 300px)); gap: 10px; }
@media (max-width: 680px) { .opts { grid-template-columns: minmax(0, 88vw); } }
label.slider { position: relative; height: 42px; display: block; border: 2px solid #000; background: #2a2a2a; }
label.slider span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 18px; pointer-events: none; }
label.slider input { -webkit-appearance: none; appearance: none; width: 100%; height: 100%; background: transparent; cursor: pointer; }
label.slider input::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 38px; background: linear-gradient(#a0a0a0, #707070); border: 2px solid #000; box-shadow: inset 2px 2px 0 rgba(255,255,255,.4); }
label.slider input::-moz-range-thumb { width: 14px; height: 36px; background: #8b8b8b; border: 2px solid #000; border-radius: 0; }
label.slider:hover { border-color: #fff; }
.opts button.mc { height: 42px; }

.keys { display: grid; grid-template-columns: repeat(2, minmax(0, 320px)); gap: 6px 26px; font-size: 18px; }
.keys div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 2px solid rgba(255,255,255,.08); padding: 4px 0; }
.keys b { color: #ffff55; font-weight: 400; }
@media (max-width: 680px) { .keys { grid-template-columns: minmax(0, 88vw); } }

/* Loading */
.load-box { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.load-title { font-size: 26px; }
.load-sub { font-size: 18px; color: #ccc; }
.bar { width: 320px; height: 6px; background: #444; border: 2px solid #000; box-sizing: content-box; }
#load-bar { height: 100%; width: 0; background: #80ff20; transition: width 0.15s; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#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 { top: 10px; left: 0; width: 22px; height: 2px; }

#hotbar { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); display: flex; padding: 2px; background: rgba(0,0,0,.35); border: 2px solid #111; box-shadow: inset 0 0 0 2px #6d6d6d; }
.slot { position: relative; width: 44px; height: 44px; border: 2px solid #8b8b8b; border-right-color: #373737; border-bottom-color: #373737; background: rgba(110,110,110,.28); display: grid; place-items: center; margin: 1px; }
.slot img { width: 32px; height: 32px; image-rendering: pixelated; filter: drop-shadow(1px 1px 0 rgba(0,0,0,.35)); }
#hotbar .slot.sel::after { content: ""; position: absolute; inset: -6px; border: 3px solid #fff; outline: 2px solid #000; box-shadow: inset 0 0 0 2px #000; }
#status { position: absolute; left: 50%; bottom: 66px; transform: translateX(-50%); width: 458px; display: flex; justify-content: space-between; }
#hearts, #bubbles { display: flex; gap: 0; }
#bubbles { flex-direction: row-reverse; }
#hearts img, #bubbles img { width: 18px; height: 18px; image-rendering: pixelated; margin-right: -1px; }
#hearts.shake img { animation: hshake 0.25s steps(2) 2; }
@keyframes hshake { 50% { transform: translateY(-2px); } }
#item-name { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); font-size: 20px; transition: opacity 0.4s; opacity: 0; white-space: nowrap; }
#item-name.show { opacity: 1; transition: none; }
#debug { position: absolute; left: 4px; top: 4px; font-size: 16px; line-height: 1.25; white-space: pre; }
#debug span { background: rgba(60, 60, 60, 0.55); padding: 0 3px; display: inline-block; }
#water-tint { position: absolute; inset: 0; background: rgba(30, 60, 160, 0.38); opacity: 0; }
#hurt-flash { position: absolute; inset: 0; box-shadow: inset 0 0 140px 30px rgba(200, 0, 0, 0.75); opacity: 0; transition: opacity 0.35s; }
#hurt-flash.on { opacity: 1; transition: none; }

/* Inventory */
.inv { background: #c6c6c6; border: 2px solid #000; padding: 14px; box-shadow: inset 4px 4px 0 #fff, inset -4px -4px 0 #555; border-radius: 4px; }
.inv-head { color: #404040; text-shadow: none; font-size: 20px; margin: 0 0 8px 2px; }
.inv-head.small { margin-top: 14px; }
.inv-grid { display: grid; grid-template-columns: repeat(9, 40px); }
.inv-grid .slot { width: 40px; height: 40px; margin: 0; background: #8b8b8b; border: 2px solid #373737; border-right-color: #fff; border-bottom-color: #fff; pointer-events: auto; cursor: pointer; }
.inv-grid .slot img { width: 30px; height: 30px; filter: none; }
.inv-grid .slot:hover { background: #a9a9a9; }
.inv-grid.hot .slot.sel { outline: 2px solid #fff; outline-offset: -4px; }
#tooltip { position: fixed; pointer-events: none; padding: 4px 8px; background: rgba(16, 0, 16, 0.94); border: 2px solid #2a0a5e; outline: 1px solid #100010; font-size: 18px; z-index: 30; text-shadow: 2px 2px 0 #3f3f3f; }
#cursor-item { position: fixed; pointer-events: none; z-index: 31; width: 32px; height: 32px; transform: translate(-50%, -50%); }
#cursor-item img { width: 32px; height: 32px; image-rendering: pixelated; }

.dead-title { font-size: 54px; text-shadow: 3px 3px 0 #3f3f3f; }
.dead-sub { font-size: 20px; margin-bottom: 30px; }
.dead-sub b { color: #ffff55; font-weight: 400; }

.slot .count { position: absolute; right: 1px; bottom: -2px; font-size: 18px; line-height: 1; text-shadow: 2px 2px 0 #3f3f3f; pointer-events: none; }
.slot .dur { position: absolute; left: 4px; right: 4px; bottom: 3px; height: 3px; background: #000; pointer-events: none; }
.slot .dur i { display: block; height: 2px; }
.right-col { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
#food { display: flex; flex-direction: row-reverse; }
#food img { width: 18px; height: 18px; image-rendering: pixelated; margin-left: -1px; }
#status { align-items: flex-end; }
.craft-row { display: flex; align-items: center; gap: 18px; margin: 0 0 4px 60px; }
.inv-grid.c2 { grid-template-columns: repeat(2, 40px); }
.inv-grid.c3 { grid-template-columns: repeat(3, 40px); }
.inv-grid.hot { margin-top: 8px; }
.inv-grid.creative { max-height: 50vh; overflow-y: auto; }
.arrow { width: 32px; height: 22px; background: #8b8b8b; clip-path: polygon(0 35%, 60% 35%, 60% 0, 100% 50%, 60% 100%, 60% 65%, 0 65%); }
.slot.result { width: 52px !important; height: 52px !important; }
.inv { min-width: 392px; }
#cursor-item .count { position: absolute; right: -4px; bottom: -6px; font-size: 18px; text-shadow: 2px 2px 0 #3f3f3f; }

/* Touch */
#touch-ui { position: absolute; inset: 0; pointer-events: none; }
#touch-ui > * { pointer-events: auto; touch-action: none; }
#joy { position: absolute; left: 28px; bottom: 96px; width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.08); border: 2px solid rgba(255,255,255,.25); }
#joy-knob { position: absolute; left: 41px; top: 41px; width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,.35); border: 2px solid rgba(0,0,0,.4); }
.tbtn { position: absolute; font: inherit; color: #fff; font-size: 26px; width: 72px; height: 72px; background: rgba(110,110,110,.45); border: 2px solid rgba(0,0,0,.6); box-shadow: inset 2px 2px 0 rgba(255,255,255,.25); }
.tbtn.small { width: 52px; height: 52px; font-size: 20px; }
.tbtn.on { background: rgba(255,255,255,.4); }
#t-jump { right: 28px; bottom: 110px; }
#t-sneak { right: 110px; bottom: 120px; }
#t-inv { right: 12px; top: 12px; }
#t-pause { right: 72px; top: 12px; }
body.touch #hotbar { pointer-events: auto; }
@media (max-width: 640px) {
  #hotbar { transform: translateX(-50%) scale(0.72); transform-origin: bottom center; }
  #status { transform: translateX(-50%) scale(0.72); transform-origin: bottom center; bottom: 50px; }
  #item-name { bottom: 76px; }
  .inv { transform: scale(0.8); }
}

#resume-hint { position: fixed; left: 50%; top: 58%; transform: translateX(-50%); font-size: 22px; z-index: 20; text-shadow: 2px 2px 0 #3f3f3f; }
