* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root { --slot: min(46px, calc((100vw - 90px) / 10)); }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b2a1b; color: #fff;
  font: 14px/1.3 system-ui, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; display: block; }

#hud { position: fixed; top: 8px; left: 8px; display: flex; gap: 12px; padding: 6px 10px;
  background: rgba(0,0,0,.55); border-radius: 8px; font-variant-numeric: tabular-nums; }
#help { position: fixed; top: 8px; right: 8px; padding: 6px 10px; background: rgba(0,0,0,.45);
  border-radius: 8px; font-size: 12px; max-width: 46vw; }
#log { position: fixed; left: 8px; bottom: calc(var(--slot) + 70px); max-width: min(420px, 70vw); pointer-events: none; }
#log div { margin-top: 2px; padding: 2px 8px; background: rgba(0,0,0,.5); border-radius: 6px; width: fit-content;
  animation: fade 9s forwards; }
#log b { color: #ffd54f; }
@keyframes fade { 0%, 80% { opacity: 1 } 100% { opacity: 0 } }
#chat { position: fixed; left: 8px; bottom: calc(var(--slot) + 26px); width: min(420px, 70vw); padding: 8px 10px; border-radius: 8px;
  border: 2px solid #ffd54f; background: rgba(0,0,0,.75); color: #fff; font: inherit; user-select: text; }
#status { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); padding: 12px 18px;
  background: rgba(0,0,0,.75); border-radius: 10px; }

#join { position: fixed; inset: 0; margin: auto; width: min(340px, 90vw); height: fit-content; padding: 22px;
  background: rgba(20,30,20,.92); border: 2px solid #6bb847; border-radius: 14px; text-align: center; }
#join h1 { margin: 0 0 6px; font-size: 26px; color: #9be564; }
#join p { margin: 0 0 14px; opacity: .8; }
#join input { width: 100%; padding: 10px; border-radius: 8px; border: 2px solid #3d5a2e; background: #101a10;
  color: #fff; font: inherit; font-size: 16px; text-align: center; user-select: text; }
#swatches { display: flex; justify-content: center; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
#swatches i { width: 28px; height: 28px; border-radius: 6px; border: 3px solid transparent; cursor: pointer; }
#swatches i.on { border-color: #fff; }
#join button { width: 100%; padding: 10px; border: 0; border-radius: 8px; background: #6bb847; color: #0d1a0d;
  font: inherit; font-size: 17px; font-weight: 700; cursor: pointer; }

#touch { position: fixed; inset: auto 0 14px 0; display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 16px; pointer-events: none; }
#touch button { pointer-events: auto; width: 58px; height: 58px; border-radius: 50%; border: 2px solid #fff6;
  background: rgba(0,0,0,.45); color: #fff; font-size: 20px; }
#touch .dpad { display: grid; grid-template: 58px 58px / 58px 58px 58px; gap: 4px; }
#touch .dpad button[data-d="1"] { grid-area: 1 / 2; }
#touch .dpad button[data-d="2"] { grid-area: 2 / 1; }
#touch .dpad button[data-d="3"] { grid-area: 2 / 3; }
#touch .dpad button[data-d="0"] { grid-area: 2 / 2; }
#touch .btns { display: flex; align-items: flex-end; gap: 10px; }
#touch #act { width: 78px; height: 78px; font-size: 14px; font-weight: 700; }
#touch #pick { font-size: 11px; font-weight: 700; }

/* barra rapida */
#bar { position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; gap: 6px; align-items: center; }
body.touch #bar { bottom: 150px; }
#hotbar, .inv-grid { display: grid; grid-template-columns: repeat(10, var(--slot)); gap: 3px; }
#hotbar { padding: 3px; background: rgba(0,0,0,.55); border-radius: 9px; }
.slot { position: relative; width: var(--slot); height: var(--slot); background: rgba(255,255,255,.08);
  border: 2px solid rgba(255,255,255,.16); border-radius: 6px; cursor: pointer; }
.slot img { position: absolute; inset: 10%; width: 80%; height: 80%; image-rendering: pixelated; pointer-events: none; }
.slot .n { position: absolute; right: 3px; bottom: 0; font-size: 12px; font-weight: 700; text-shadow: 0 1px 2px #000, 0 0 2px #000; }
.slot small { position: absolute; left: 3px; top: 0; font-size: 10px; opacity: .6; }
.slot.sel { border-color: #ffd54f; background: rgba(255,213,79,.2); }
.slot.picked { border-color: #9be564; background: rgba(155,229,100,.25); }
#inv-btn { width: var(--slot); height: var(--slot); border-radius: 9px; border: 2px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.55); font-size: calc(var(--slot) * .5); cursor: pointer; padding: 0; }
#held-name { position: absolute; left: 50%; bottom: calc(100% + 26px); transform: translateX(-50%); padding: 3px 10px;
  background: rgba(0,0,0,.6); border-radius: 6px; white-space: nowrap; opacity: 0; transition: opacity .3s; pointer-events: none; }
#held-name.on { opacity: 1; transition: none; }
#hearts { position: absolute; left: 3px; bottom: 100%; margin-bottom: 5px; width: min(237px, calc(var(--slot) * 5));
  image-rendering: pixelated; filter: drop-shadow(0 1px 1px #000); }

/* dano: borda vermelha rapida */
#hurt-fx { position: fixed; inset: 0; pointer-events: none; box-shadow: inset 0 0 90px rgba(220,0,0,.75); opacity: 0; }
body.hurt #hurt-fx { animation: hurt .45s ease-out; }
@keyframes hurt { from { opacity: 1 } to { opacity: 0 } }

/* inventario */
#inv { --slot: min(40px, calc((100vw - 60px) / 10), calc((100vh - 230px) / 7));
  position: fixed; inset: 0; margin: auto; width: fit-content; height: fit-content; max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px); overflow: auto; touch-action: pan-y; padding: 12px 14px 14px;
  background: rgba(20,30,20,.96); border: 2px solid #6bb847; border-radius: 12px; }
#inv .inv-head { display: flex; gap: 12px; align-items: center; margin-bottom: 2px; font-size: 16px; color: #9be564; }
#inv-def { flex: 1; font-size: 12px; color: #fff; opacity: .75; }
#inv-close { border: 0; background: none; color: #fff; font-size: 18px; cursor: pointer; padding: 2px 6px; }
.inv-body { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.inv-grid.armor { grid-template-columns: repeat(4, var(--slot)); }
.slot.armor.empty::after { content: attr(data-label); position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 9px; opacity: .45; }
.inv-label { margin: 8px 0 4px; font-size: 12px; opacity: .7; }
#inv-info { margin-top: 10px; min-height: 2.6em; font-size: 13px; opacity: .85; max-width: calc(var(--slot) * 10 + 27px); }
.inv-craft { width: 250px; }
#recipes { display: grid; gap: 4px; }
.recipe { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 8px; background: rgba(255,255,255,.05); }
.recipe.ready { background: rgba(155,229,100,.13); }
.recipe > img { width: 28px; height: 28px; image-rendering: pixelated; }
.recipe .r-txt { flex: 1; min-width: 0; }
.recipe b { font-size: 13px; font-weight: 600; }
.r-need { display: flex; flex-wrap: wrap; gap: 6px; font-size: 11px; }
.r-need span { display: inline-flex; align-items: center; gap: 1px; }
.r-need img { width: 16px; height: 16px; image-rendering: pixelated; }
.r-need i { font-style: normal; }
.r-need .miss i { color: #ff8a80; }
.recipe button { padding: 4px 10px; border: 0; border-radius: 6px; background: #6bb847; color: #0d1a0d; font: inherit;
  font-size: 12px; font-weight: 700; cursor: pointer; }
.recipe button:disabled { background: rgba(255,255,255,.12); color: rgba(255,255,255,.4); cursor: default; }
#log .kill b { color: #ff8a80; }
#toast { position: fixed; top: 48px; left: 50%; transform: translateX(-50%); padding: 6px 14px;
  background: rgba(120,30,30,.85); border-radius: 8px; }

/* login */
#join input + input { margin-top: 8px; }
#join .hint { display: block; margin-top: 8px; font-size: 12px; opacity: .6; }
#join-err { margin-top: 10px; padding: 6px 10px; border-radius: 8px; background: rgba(160,40,40,.5); font-size: 13px; }
#join button:disabled { opacity: .6; cursor: default; }
#hud { align-items: center; }
#hud-reset { opacity: .75; }
#logout { padding: 1px 8px; border: 1px solid rgba(255,255,255,.3); border-radius: 6px; background: none; color: #fff;
  font: inherit; font-size: 12px; cursor: pointer; }
