* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #87c7f0; font-family: Rubik, system-ui, sans-serif; color: #fff;
  user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

:root { --pix: 0 3px 0 rgba(0,0,0,.35); --panel: rgba(24, 28, 40, .82); --top: max(env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px), 8px); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #hud input, #hud #stick, #hud #hotbar { pointer-events: auto; }
.stats { position: absolute; left: 10px; top: var(--top); display: flex; gap: 8px; align-items: center; background: var(--panel);
  padding: 6px 10px 6px 6px; border-radius: 12px; box-shadow: var(--pix); }
.lvl { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(#ffcf4a, #f09b19); color: #4a2a00; font-weight: 800;
  display: grid; place-items: center; font-size: 20px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); }
.bars { width: 128px; }
.name { font-size: 12px; font-weight: 700; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { position: relative; height: 12px; background: rgba(0,0,0,.5); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.bar span { position: absolute; inset: 0 auto 0 0; transition: width .2s; }
.bar.hp span { background: linear-gradient(#ff6b6b, #d63031); }
.bar.xp span { background: linear-gradient(#74b9ff, #0984e3); }
.bar em { position: relative; font-style: normal; font-size: 9px; font-weight: 700; display: block; text-align: center; line-height: 12px; text-shadow: 0 1px 1px #000; }
.gold { position: absolute; left: 10px; top: calc(var(--top) + 62px); background: var(--panel); padding: 4px 10px; border-radius: 10px; font-weight: 700; font-size: 14px; box-shadow: var(--pix); }
.zone { position: absolute; left: 50%; top: calc(var(--top) + 100px); transform: translateX(-50%); font-weight: 800; font-size: 13px; text-shadow: 0 2px 0 rgba(0,0,0,.5);
  white-space: nowrap; opacity: .9; }
.zone.danger { color: #ffb3b3; }
#map { position: absolute; right: 10px; top: var(--top); width: 92px; height: 92px; border-radius: 12px; border: 3px solid rgba(24,28,40,.85); image-rendering: pixelated; background: #333; box-shadow: var(--pix); }
.side { position: absolute; right: 10px; top: calc(var(--top) + 100px); display: flex; flex-direction: column; gap: 8px; }
.side button { width: 44px; height: 44px; border-radius: 12px; background: var(--panel); font-size: 20px; box-shadow: var(--pix); }

#log { position: absolute; left: 10px; bottom: 190px; width: min(70vw, 320px); font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
#log div { background: rgba(0,0,0,.45); padding: 3px 8px; border-radius: 6px; align-self: flex-start; max-width: 100%; word-wrap: break-word; animation: fadeOut 12s forwards; }
#log div b { color: #ffd66b; }
#log div.sys { color: #9ef0a7; }
@keyframes fadeOut { 0%, 85% { opacity: 1 } 100% { opacity: 0 } }

#stick { position: absolute; left: 0; bottom: 0; width: 45vw; height: 45vh; }
#knob { position: absolute; width: 110px; height: 110px; margin: -55px; border-radius: 50%; border: 3px solid rgba(255,255,255,.35); background: rgba(0,0,0,.18);
  left: 90px; bottom: calc(env(safe-area-inset-bottom) + 100px); }
#knob::after { content: ""; position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px; border-radius: 50%; background: rgba(255,255,255,.55);
  transform: translate(var(--kx, 0px), var(--ky, 0px)); }

.actions { position: absolute; right: 14px; bottom: calc(env(safe-area-inset-bottom) + 18px); width: 170px; height: 170px; }
.actions button { position: absolute; border-radius: 50%; background: rgba(24,28,40,.7); box-shadow: var(--pix); display: grid; place-items: center; }
.actions .big { width: 78px; height: 78px; right: 0; bottom: 0; font-size: 34px; background: rgba(214, 48, 49, .8); }
.actions .mid { width: 58px; height: 58px; right: 92px; bottom: 6px; font-size: 26px; font-weight: 800; }
.actions .small { width: 48px; height: 48px; font-size: 22px; }
#btnMode { right: 14px; bottom: 92px; }
#btnMode.build { background: rgba(9, 132, 227, .85); }
#btnPotion { right: 76px; bottom: 80px; }
#btnPotion i { position: absolute; right: -2px; bottom: -2px; font-style: normal; font-size: 11px; font-weight: 800; background: #6c5ce7; border-radius: 8px; padding: 0 5px; }
.actions button:active { transform: scale(.92); }

#hotbar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 196px); display: flex; gap: 4px; background: var(--panel); padding: 5px; border-radius: 12px; max-width: 92vw; overflow-x: auto; }
#hotbar button { position: relative; width: 40px; height: 40px; border-radius: 8px; background: rgba(255,255,255,.08); padding: 4px; flex: none; }
#hotbar button.on { outline: 3px solid #ffd66b; }
#hotbar img, .icon { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
#hotbar i { position: absolute; right: 1px; bottom: 0; font-style: normal; font-size: 10px; font-weight: 800; text-shadow: 0 1px 1px #000; }

#chatForm { position: absolute; left: 10px; right: 10px; top: calc(var(--top) + 100px); display: flex; gap: 6px; pointer-events: auto; }
#chatForm input { flex: 1; height: 42px; border-radius: 12px; border: 0; padding: 0 12px; font: inherit; font-size: 16px; background: rgba(255,255,255,.95); color: #222; outline: none; }
#chatForm button { width: 48px; border-radius: 12px; background: #0984e3; font-size: 18px; }

/* ---------- метки над головами ---------- */
#labels, #floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); text-align: center; font-size: 11px; font-weight: 700; white-space: nowrap; text-shadow: 0 1px 2px #000; will-change: transform; }
.lbl i { font-style: normal; color: #ffd66b; }
.lbl.mob b { color: #ffd0d0; }
.lbl.mob.hard b { color: #ff7675; }
.lbl.boss b { color: #fd79a8; font-size: 13px; }
.lbl .hp { width: 46px; height: 5px; margin: 2px auto 0; background: rgba(0,0,0,.6); border-radius: 3px; overflow: hidden; }
.lbl .hp span { display: block; height: 100%; background: #ff5e57; }
.lbl.player .hp span { background: #55efc4; }
.lbl .bubble { display: block; max-width: 180px; white-space: normal; background: #fff; color: #222; text-shadow: none; padding: 4px 8px; border-radius: 10px; margin: 0 auto 4px; font-weight: 500; width: max-content; }
.fl { position: absolute; left: 0; top: 0; font-weight: 800; font-size: 18px; text-shadow: 0 2px 0 #000, 0 0 4px #000; animation: rise 1s ease-out forwards; }
.fl.crit { color: #ffd32a; font-size: 24px; }
.fl.me { color: #ff6b6b; }
.fl.xp { color: #74b9ff; font-size: 15px; }
.fl.gold { color: #ffd66b; font-size: 15px; }
@keyframes rise { from { opacity: 1; margin-top: 0 } to { opacity: 0; margin-top: -50px } }

/* ---------- окна ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.box { position: relative; width: min(100%, 440px); max-height: 86vh; display: flex; flex-direction: column; background: #20242f; border-radius: 16px; box-shadow: 0 6px 0 rgba(0,0,0,.4); padding: 14px; }
.box.center { text-align: center; padding: 24px; }
.box h1 { margin: 0 0 8px; } .box h2 { margin: 0 0 10px; font-size: 18px; }
.box p { color: #b2bec3; }
.close { position: absolute; right: 8px; top: 8px; width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,.08); }
.tabs { display: flex; gap: 4px; margin-right: 40px; flex-wrap: wrap; }
.tabs button { padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.06); font-size: 13px; font-weight: 700; }
.tabs button.on { background: #f09b19; color: #3a2000; }
.body { overflow-y: auto; margin-top: 12px; }
.primary { background: #00b894; padding: 12px 20px; border-radius: 12px; font-weight: 800; box-shadow: 0 3px 0 #00866b; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.cell { background: rgba(255,255,255,.06); border-radius: 10px; padding: 6px; text-align: center; font-size: 10px; }
.cell .icon { width: 32px; height: 32px; margin: 0 auto 3px; }
.cell b { display: block; font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.06); border-radius: 12px; padding: 8px 10px; margin-bottom: 6px; }
.row .info { flex: 1; min-width: 0; }
.row .info b { display: block; font-size: 14px; }
.row .info small { color: #b2bec3; font-size: 11px; }
.row .info small.bad { color: #ff7675; }
.row button { background: #0984e3; padding: 8px 12px; border-radius: 10px; font-weight: 700; font-size: 13px; flex: none; }
.row button:disabled { background: #555; color: #999; }
.row.have { opacity: .55; }
.note { font-size: 12px; color: #fdcb6e; margin: 0 0 8px; }
.eq { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; font-size: 12px; }
.eq span { background: rgba(255,255,255,.08); padding: 5px 8px; border-radius: 8px; }
.toprow { display: flex; justify-content: space-between; padding: 7px 4px; border-bottom: 1px solid rgba(255,255,255,.06); font-size: 14px; }

.screen { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: linear-gradient(#5aa9e6, #3d7a4a); }
.logo { font-size: 38px; font-weight: 800; letter-spacing: 2px; text-shadow: 0 4px 0 rgba(0,0,0,.35); }
.sub { font-size: 14px; opacity: .9; }
.prog { width: 200px; height: 12px; background: rgba(0,0,0,.35); border-radius: 6px; overflow: hidden; }
.prog span { display: block; height: 100%; width: 0; background: #ffd66b; transition: width .15s; }

#toast { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.9); background: rgba(20,22,30,.9); padding: 10px 16px; border-radius: 12px; font-weight: 700;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 30; text-align: center; max-width: 80vw; }
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
