* { box-sizing: border-box; }
body { margin: 0; background: #050510; color: #EAF5F6; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; touch-action: none; }
#viewport { position: fixed; inset: 0; overflow: hidden; }
#game { display: block; image-rendering: pixelated; }

.touch-btn {
  position: absolute; bottom: 20px; width: 60px; height: 60px;
  background: rgba(0,255,255,0.2); border: 2px solid #0ff; border-radius: 8px;
  color: #0ff; font-size: 20px; display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none;
  z-index: 6;
}
#btn-up { left: 70px; bottom: 90px; }
#btn-down { left: 70px; bottom: 20px; }
#btn-left { left: 10px; bottom: 55px; }
#btn-right { left: 130px; bottom: 55px; }
#btn-attack { right: 20px; bottom: 40px; width: 80px; height: 80px; background: rgba(255,0,100,0.3); }
#btn-interact {
  position: absolute; right: 110px; bottom: 40px; width: 70px; height: 70px;
  background: rgba(0,255,100,0.25); border: 2px solid #0f8; border-radius: 8px;
  color: #0f8; font-size: 16px; display: flex; align-items: center; justify-content: center;
  user-select: none;
}
#btn-use {
  right: 30px; bottom: 135px; width: 60px; height: 50px; font-size: 14px;
  background: rgba(255,193,90,0.22); border-color: #ffc15a; color: #ffc15a;
}
/* Hide touch controls on devices with fine pointer and hover */
@media (hover: hover) and (pointer: fine) {
  .touch-btn { display: none; }
}

#safe-indicator { display: none !important; }

#dialog {
  position: absolute; bottom: 160px; left: 50%; transform: translateX(-50%);
  width: min(90vw, 420px); background: rgba(10,20,30,0.95);
  border: 2px solid #0ff; padding: 12px 16px; font-size: 14px;
  color: #fff; display: none; z-index: 10; text-align: center;
  box-shadow: 0 0 20px rgba(0,255,255,0.3);
}
#dialog .name { color: #f6a; font-weight: bold; margin-bottom: 6px; }
#dialog-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; max-height: 46vh; overflow-y: auto; }   /* 15C: Rdza has more stock */
#dialog-actions button {
  background: #0a2030; color: #0ff; border: 1px solid #0ff; padding: 8px 10px;
  font-size: 13px; cursor: pointer; text-align: left;
}
#dialog-actions button:hover:not(:disabled) { background: #0ff; color: #000; }
#dialog-actions button:disabled { color: #646880; border-color: #474a5f; cursor: default; }
#dialog .dialog-hint { margin-top: 8px; font-size: 11px; color: #8a8ea6; }


/* 15G: 3-line log, older lines dimmed */
#log .log-line { color: #8FA3B0; line-height: 1.35; }
#log .log-line.new { color: #EAF5F6; }

#respawn-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 20;
}
.respawn-box {
  background: rgba(10, 20, 30, 0.95);
  border: 2px solid #0ff;
  padding: 24px 32px;
  text-align: center;
  color: #fff;
  min-width: 200px;
}
.respawn-text {
  font-size: 20px;
  margin-bottom: 16px;
}
#respawn-btn {
  background: #0a2030;
  color: #0ff;
  border: 2px solid #0ff;
  padding: 10px 24px;
  font-size: 16px;
  cursor: pointer;
}
#respawn-btn:hover {
  background: #0ff;
  color: #000;
}

/* G6: return screen after a break (js/welcome.js) */
#welcome { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.55); z-index: 22; }
.welcome-box { background: rgba(10, 20, 30, 0.96); border: 2px solid var(--cyn3); padding: 18px 22px; color: #EAF5F6; width: min(380px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; }
.welcome-title { color: var(--cyn4); font-size: 18px; letter-spacing: 1px; margin-bottom: 10px; }
#welcome-body { font-size: 13px; line-height: 1.45; }
#welcome-body .wb-safe { color: var(--veg4); margin-bottom: 8px; }
#welcome-body .wb-head { color: var(--cyn3); margin-top: 8px; }
#welcome-body .wb-row { padding-left: 8px; color: #C9D6DE; }
#welcome-body .wb-row.ready { color: var(--amb); }
#welcome-body .wb-row.dim { color: #8a8ea6; }
#welcome-body .wb-line { margin-top: 4px; }
#welcome-body .wb-next { margin-top: 10px; color: var(--amb); }
#welcome-btn { margin-top: 14px; width: 100%; background: #0a2030; color: var(--cyn4); border: 2px solid var(--cyn3); padding: 10px; font-size: 16px; cursor: pointer; }
#welcome-btn:hover { background: var(--cyn3); color: #000; }

#inventory-panel {
  position: fixed;
  top: 50%;
  right: 24px;
  transform: translateY(-50%);
  width: min(280px, calc(100vw - 32px));
  background: rgba(17, 29, 41, 0.96);
  border: 1px solid #00CCAA;
  padding: 12px;
  z-index: 15;
  color: #EAF5F6;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.inv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.inv-title { font-weight: 600; color: #00CCAA; }
#inv-count { font-size: 12px; color: #8FABAe; }
#inv-close {
  background: transparent;
  border: 1px solid #00CCAA;
  color: #00CCAA;
  width: 24px;
  height: 24px;
  cursor: pointer;
  padding: 0;
}
.inv-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.inv-slot {
  aspect-ratio: 1;
  background: #0a1520;
  border: 1px solid #314451;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  cursor: pointer;
  position: relative;
}
.inv-slot.selected { border-color: #00CCAA; }
.inv-slot .qty { position: absolute; bottom: 2px; right: 3px; font-size: 10px; }
.inv-slot .icon { width: 12px; height: 10px; background: #6a6a6a; position: relative; }
.inv-slot .icon.stymulant { width: 6px; height: 14px; background: #ffc15a; border-radius: 2px; }
.inv-slot .icon.medpak { width: 14px; height: 12px; background: #e0319b; border-radius: 2px; }
.inv-slot .icon.stymulant::after, .inv-slot .icon.medpak::after { display: none; }
.inv-use { display: block; margin-top: 6px; background: transparent; color: #ffc15a; border: 1px solid #ffc15a; border-radius: 4px; padding: 4px 8px; cursor: pointer; }
.inv-slot .icon::after {
  content: '';
  position: absolute;
  left: 4px; top: 3px;
  width: 4px; height: 4px;
  background: #00CCAA;
}
.inv-equip { display: grid; grid-template-columns: repeat(2, 56px); gap: 6px; margin-bottom: 4px; }
.inv-slot.eq-slot { border-color: #8a6a2a; }
.inv-slot.eq-slot.selected { border-color: #00CCAA; }
.inv-slot.eq-slot.empty { opacity: 0.6; }
.inv-slot .eq-label { position: absolute; bottom: 1px; font-size: 8px; color: #ffc15a; letter-spacing: 0.5px; }
.inv-stats { font-size: 11px; color: #ffc15a; margin-bottom: 6px; }
.inv-use + .inv-use { margin-top: 4px; }
/* 15C gear icons (CSS placeholders, like the stimulant/medpak ones) */
.inv-slot .icon.pipe, .inv-slot .icon.machete, .inv-slot .icon.spiked_club, .inv-slot .icon.isotope_blade { width: 3px; height: 18px; transform: rotate(35deg); }
.inv-slot .icon.pipe { background: #8a96a8; }
.inv-slot .icon.machete { width: 4px; background: #c06a3a; }
.inv-slot .icon.spiked_club { width: 5px; background: #6b4a3a; box-shadow: -2px -4px 0 #c0c8d4, 2px -7px 0 #c0c8d4; }
.inv-slot .icon.isotope_blade { width: 4px; background: #e0319b; box-shadow: 0 0 4px #e0319b; }
.inv-slot .icon.tire_jacket, .inv-slot .icon.plate_vest, .inv-slot .icon.raider_armor, .inv-slot .icon.hazmat_suit { width: 16px; height: 14px; border-radius: 3px 3px 1px 1px; }
.inv-slot .icon.tire_jacket { background: #3a3446; }
.inv-slot .icon.plate_vest { background: #6f7c90; }
.inv-slot .icon.raider_armor { background: #7a4a2a; box-shadow: inset 0 3px 0 #e0319b; }
.inv-slot .icon.hazmat_suit { background: #ffc15a; box-shadow: inset 0 4px 0 #2a3a4a; }
.inv-slot .icon.pipe::after, .inv-slot .icon.machete::after, .inv-slot .icon.spiked_club::after, .inv-slot .icon.isotope_blade::after,
.inv-slot .icon.tire_jacket::after, .inv-slot .icon.plate_vest::after, .inv-slot .icon.raider_armor::after, .inv-slot .icon.hazmat_suit::after { display: none; }
.inv-detail {
  margin-top: 8px;
  min-height: 18px;
  font-size: 12px;
  color: #EAF5F6;
}
@media (max-width: 700px) {
  #inventory-panel {
    right: 50%;
    transform: translate(50%, -50%);
  }
}

#game-menu {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 22, 0.72);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
}
.menu-box {
  background: rgba(17, 29, 41, 0.96);
  border: 1px solid #00CCAA;
  padding: 16px;
  min-width: 220px;
  color: #EAF5F6;
}
.menu-title { color: #00CCAA; font-weight: 600; margin-bottom: 10px; }
.menu-box button {
  display: block;
  width: 100%;
  margin: 4px 0;
  background: transparent;
  border: 1px solid #314451;
  color: #EAF5F6;
  padding: 6px;
  cursor: pointer;
}
.menu-box button:hover { border-color: #00CCAA; }
.menu-content { margin-top: 10px; font-size: 12px; color: #8FABAe; }

/* 15D: character block in the backpack panel */
#inventory-panel { max-height: calc(100vh - 24px); overflow-y: auto; }
.inv-char { border-bottom: 1px solid #2a3a4a; padding-bottom: 6px; margin-bottom: 8px; font-size: 12px; }
.char-head { color: #00CCAA; font-weight: 600; margin-bottom: 4px; }
.char-row { display: flex; align-items: center; gap: 6px; min-height: 24px; }
.char-row > span:first-child { width: 48px; color: #ffc15a; font-weight: 600; }
.char-hint { flex: 1; color: #8FABAE; font-size: 10px; }
.char-plus { background: transparent; color: #00CCAA; border: 1px solid #00CCAA; border-radius: 4px; width: 28px; height: 24px; cursor: pointer; font-weight: 700; }
.char-line { color: #8FABAE; font-size: 11px; margin-top: 3px; }
.char-mut { color: #e0319b; }
.inv-mutate { color: #e0319b; border-color: #e0319b; text-align: left; font-size: 11px; }
#inv-btn.has-points { color: #ffc15a; border-color: #ffc15a; }
.inv-slot .icon.mutagen_shard { width: 10px; height: 14px; background: #e0319b; clip-path: polygon(50% 0, 100% 40%, 70% 100%, 20% 90%, 0 35%); box-shadow: 0 0 4px #e0319b; }
.inv-slot .icon.mutagen_shard::after { display: none; }

/* 15E: quests and terminals */
#dialog-text { white-space: pre-line; }
#dialog.terminal { border-color: #0ff; }
#dialog.terminal .name { color: #0ff; letter-spacing: 1px; }
#dialog.terminal #dialog-text { color: #9fe; font-family: monospace; font-size: 12px; }
.inv-quests { border-bottom: 1px solid #2a3a4a; padding-bottom: 6px; margin-bottom: 8px; font-size: 11px; color: #8FABAE; }
.inv-quests .q-head { color: #00CCAA; font-weight: 600; font-size: 12px; margin-bottom: 3px; }
.inv-quests .q-row { margin-top: 2px; }
.inv-quests .q-row.ready { color: #ffb347; }

/* 15F: Strażnik Sterowni loot (placeholder icons, palette colours) */
.inv-slot .icon.warden_chip { width: 12px; height: 10px; background: #2f3243; border: 1px solid #2fe3d1; box-shadow: inset 0 0 0 2px #0a4a58; }
.inv-slot .icon.arc_baton { width: 4px; height: 18px; transform: rotate(35deg); background: #646880; box-shadow: 0 -6px 0 #2fe3d1, 0 0 4px #2fe3d1; }
.inv-slot .icon.warden_plating { width: 16px; height: 14px; border-radius: 3px 3px 1px 1px; background: #8a8ea6; box-shadow: inset 0 3px 0 #ffc15a, inset 0 -3px 0 #0d0b16; }
.inv-slot .icon.warden_chip::after, .inv-slot .icon.arc_baton::after, .inv-slot .icon.warden_plating::after { display: none; }

/* ===== 16B: phone layout (body.touch = coarse pointer or a finger seen). One hand: map taps + right thumb. ===== */
:root {
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --pad: clamp(44px, 13vw, 56px);   /* d-pad button */
  --atk: clamp(68px, 21vw, 88px);   /* attack button */
}
#dialog-close { display: none; }
.dialog-hint .hint-touch { display: none; }
body.touch .dialog-hint .hint-keys { display: none; }
body.touch .dialog-hint .hint-touch { display: inline; }

/* touch buttons: big, round, out of the log's way. Right hand by default. */
body.touch .touch-btn { display: flex; border-radius: 50%; touch-action: none; }
body.touch #btn-up, body.touch #btn-down, body.touch #btn-left, body.touch #btn-right {
  width: var(--pad); height: var(--pad); border-radius: 10px; font-size: 20px;
}
body.touch #btn-left  { left: calc(var(--sal) + 8px);                         bottom: calc(var(--sab) + 20px + var(--pad) + 4px); right: auto; }
body.touch #btn-up    { left: calc(var(--sal) + 12px + var(--pad));           bottom: calc(var(--sab) + 24px + 2 * var(--pad) + 4px); right: auto; }
body.touch #btn-down  { left: calc(var(--sal) + 12px + var(--pad));           bottom: calc(var(--sab) + 20px); right: auto; }
body.touch #btn-right { left: calc(var(--sal) + 16px + 2 * var(--pad));       bottom: calc(var(--sab) + 20px + var(--pad) + 4px); right: auto; }
body.touch #btn-attack {
  right: calc(var(--sar) + 14px); bottom: calc(var(--sab) + 20px); left: auto;
  width: var(--atk); height: var(--atk); font-size: 18px; font-weight: 700;
}
body.touch #btn-interact {
  right: calc(var(--sar) + 26px + var(--atk)); bottom: calc(var(--sab) + 20px); left: auto;
  width: calc(var(--atk) * 0.78); height: calc(var(--atk) * 0.78); border-radius: 50%; font-size: 18px; font-weight: 700;
}
body.touch #btn-use {
  right: calc(var(--sar) + 18px); bottom: calc(var(--sab) + 32px + var(--atk)); left: auto;
  width: calc(var(--atk) * 0.72); height: calc(var(--atk) * 0.62); border-radius: 12px; font-size: 14px;
}
/* left hand: mirror everything */
body.touch.left-hand #btn-attack   { left: calc(var(--sal) + 14px); right: auto; }
body.touch.left-hand #btn-interact { left: calc(var(--sal) + 26px + var(--atk)); right: auto; }
body.touch.left-hand #btn-use      { left: calc(var(--sal) + 18px); right: auto; }
body.touch.left-hand #btn-right { right: calc(var(--sar) + 8px); left: auto; }
body.touch.left-hand #btn-up    { right: calc(var(--sar) + 12px + var(--pad)); left: auto; }
body.touch.left-hand #btn-down  { right: calc(var(--sar) + 12px + var(--pad)); left: auto; }
body.touch.left-hand #btn-left  { right: calc(var(--sar) + 16px + 2 * var(--pad)); left: auto; }
body.touch.no-dpad #btn-up, body.touch.no-dpad #btn-down, body.touch.no-dpad #btn-left, body.touch.no-dpad #btn-right { display: none; }
/* a window covers the map: the action buttons would only get in the way */
body.touch.ui-open .touch-btn { display: none; }

/* dialog = bottom sheet with thumb-size buttons */
body.touch #dialog {
  left: 0; right: 0; bottom: 0; transform: none; width: 100%;
  max-height: 72vh; overflow-y: auto; border-width: 2px 0 0 0;
  padding: 12px 14px calc(12px + var(--sab)); font-size: 15px; text-align: left;
}
body.touch #dialog .name { padding-right: 44px; }
body.touch #dialog-actions { max-height: 52vh; gap: 8px; }
body.touch #dialog-actions button { min-height: 46px; font-size: 15px; padding: 10px 12px; }
body.touch #dialog-close {
  display: block; position: absolute; top: 6px; right: 8px; width: 40px; height: 40px;
  background: transparent; color: #0ff; border: 1px solid #0ff; font-size: 18px; cursor: pointer;
}

/* POSTAĆ · PLECAK = bottom sheet */
body.touch #inventory-panel {
  top: auto; bottom: 0; left: 0; right: 0; transform: none; width: 100%;
  max-height: 75vh; padding: 10px 12px calc(12px + var(--sab)); border-width: 1px 0 0 0;
}
body.touch #inv-close { width: 40px; height: 40px; font-size: 16px; }
body.touch .inv-title { font-size: 15px; }
body.touch .inv-grid { gap: 6px; }
body.touch .inv-slot .qty { font-size: 12px; }
body.touch .inv-equip { grid-template-columns: repeat(2, 64px); }
body.touch .inv-use { min-height: 42px; font-size: 14px; padding: 8px 12px; width: 100%; text-align: left; }
body.touch .char-row { min-height: 40px; }
body.touch .char-plus { width: 44px; height: 38px; font-size: 18px; }
body.touch .inv-detail { font-size: 13px; }
body.touch .inv-quests, body.touch .inv-char { font-size: 13px; }

body.touch .menu-box { width: min(92vw, 360px); }
body.touch .menu-box button { min-height: 44px; font-size: 15px; }
body.touch #respawn-btn { min-height: 48px; padding: 12px 32px; }

/* phone on its side: windows become a side sheet, the map stays visible */
@media (orientation: landscape) {
  body.touch #inventory-panel, body.touch #dialog {
    left: auto; right: 0; top: 0; bottom: 0; width: min(440px, 60vw); max-height: 100vh;
    border-width: 0 0 0 2px; padding-top: calc(10px + var(--sat)); padding-right: calc(12px + var(--sar));
  }
  body.touch #dialog-actions { max-height: none; }
}

#net-lost {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 30;
}
.net-lost-box {
  background: rgba(10, 20, 30, 0.95);
  border: 2px solid #f0f;
  padding: 24px 32px;
  text-align: center;
  color: #fff;
  max-width: 86vw;
}
.net-lost-title { font-size: 20px; color: #f0f; margin-bottom: 8px; }
.net-lost-text { margin-bottom: 16px; }
#net-retry {
  background: #0a2030;
  color: #0ff;
  border: 2px solid #0ff;
  padding: 10px 24px;
  min-height: 46px;
  font: inherit;
  cursor: pointer;
}

/* 17C: chat, party list, party invite, player menu. Everything hidden unless online (body.online). */
#chat-btn, #chat { display: none; }
body.online #chat {
  display: flex; flex-direction: column;
  position: fixed; right: 16px; bottom: 16px; width: min(380px, 40vw);
  pointer-events: none; z-index: 7; font-size: 13px;
}
body.online #chat .chat-top, body.online #chat-form { display: none; }
#chat-lines { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; max-height: 30vh; }
.chat-line {
  background: rgba(17, 29, 41, 0.78); padding: 3px 8px; border-radius: 4px;
  color: #EAF5F6; line-height: 1.3; word-break: break-word; align-self: flex-start;
}
.chat-line .chat-from { color: #2fe3d1; font-weight: 600; }
.chat-line.party .chat-from { color: #9be564; }
.chat-line.self .chat-from { color: #ffc15a; }
body.online.chat-open #chat {
  pointer-events: auto; background: rgba(10, 20, 30, 0.95); border: 2px solid #0ff; border-radius: 6px; padding: 8px;
}
body.online.chat-open #chat .chat-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; color: #0ff; font-size: 12px; }
body.online.chat-open #chat-form { display: flex; gap: 6px; margin-top: 8px; }
body.online.chat-open #chat-lines { max-height: 40vh; }
#chat-close { background: none; border: 0; color: #8a8ea6; font-size: 16px; cursor: pointer; }
#chat-input {
  flex: 1; min-width: 0; background: #0a2030; color: #fff; border: 1px solid #0ff; padding: 6px 8px; font-size: 14px;
}
#chat-ch, #chat-send {
  background: #0a2030; color: #0ff; border: 1px solid #0ff; padding: 6px 8px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
#chat-ch.party { color: #9be564; border-color: #9be564; }

/* phone: a CZAT button top right, the chat itself is a bottom sheet while open */
body.online.touch #chat-btn {
  display: block; position: fixed; right: calc(var(--sar, 0px) + 14px);
  bottom: calc(var(--sab, 0px) + 46px + var(--atk) * 1.62);   /* right above MED, under the thumb */
  min-width: 64px; min-height: 40px; padding: 6px 10px; z-index: 7;
  background: rgba(17, 29, 41, 0.9); color: #0ff; border: 1px solid #0ff; border-radius: 8px; font-size: 13px; font-weight: 700;
}
body.online.touch #chat { display: none; }
body.online.touch.chat-open #chat {
  display: flex; left: 0; right: 0; bottom: 0; width: 100%; max-height: 60vh; border-width: 2px 0 0 0; border-radius: 0;
  padding-bottom: calc(8px + var(--sab, 0px)); z-index: 12;
}
body.online.touch.chat-open #chat-input, body.online.touch.chat-open #chat-ch, body.online.touch.chat-open #chat-send { min-height: 44px; font-size: 16px; }
body.touch.chat-open .touch-btn { display: none; }

/* party list: desktop under the online status, phone under the CZAT button */
#party-list {
  position: fixed; top: 48px; right: 16px; width: 200px; z-index: 6;
  background: rgba(17, 29, 41, 0.88); border: 1px solid #314451; border-radius: 8px; padding: 6px 8px; font-size: 12px;
}
.party-head { display: flex; justify-content: space-between; align-items: center; color: #9be564; font-weight: 700; margin-bottom: 4px; }
.party-head button { background: #0a2030; color: #8a8ea6; border: 1px solid #474a5f; font-size: 11px; padding: 2px 6px; cursor: pointer; }
.party-row { margin: 3px 0; }
.party-row.me .party-name { color: #ffc15a; }
.party-row.dead { opacity: 0.5; }
.party-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.party-bar { height: 4px; background: #364554; border-radius: 2px; overflow: hidden; }
.party-bar > div { height: 100%; background: #DF658F; }
body.touch #party-list {
  top: auto; bottom: calc(var(--sab, 0px) + 100px + var(--atk) * 1.62); right: calc(var(--sar, 0px) + 8px);
  width: 140px; font-size: 11px; padding: 4px 6px;
}
/* left hand: mirror the CZAT button and the party list too */
body.online.touch.left-hand #chat-btn { right: auto; left: calc(var(--sal, 0px) + 14px); }
body.touch.left-hand #party-list { right: auto; left: calc(var(--sal, 0px) + 8px); }
body.touch.ui-open #chat-btn, body.touch.ui-open #party-list { display: none !important; }
body.touch .party-head button { min-height: 32px; padding: 4px 8px; }

/* invite banner + player menu: small centered boxes */
#party-invite, #pmenu {
  position: fixed; left: 50%; top: 32%; transform: translateX(-50%); z-index: 15;
  width: min(86vw, 320px); background: rgba(10, 20, 30, 0.96); border: 2px solid #9be564; padding: 12px; text-align: center; color: #fff;
}
#pmenu { border-color: #0ff; }
.party-invite-actions, .pmenu-actions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.pmenu-actions { flex-direction: column; }
.pmenu-name { color: #2fe3d1; font-weight: 700; }
#party-invite button, #pmenu button {
  background: #0a2030; color: #0ff; border: 1px solid #0ff; padding: 8px 12px; font-size: 14px; cursor: pointer; min-height: 40px;
}
#party-yes { color: #9be564 !important; border-color: #9be564 !important; }
/* 17C: phone on its side: little height, so the party list sits next to the CZAT button, not above it */
@media (orientation: landscape) {
  body.touch #party-list { bottom: calc(var(--sab, 0px) + 46px + var(--atk) * 1.62); right: calc(var(--sar, 0px) + 100px); }
  body.touch.left-hand #party-list { right: auto; left: calc(var(--sal, 0px) + 100px); }
}
/* =====================================================================================
   17B.1: HUD rework. Desktop = frame (panel right, action bar + log under the map, nothing
   on the map). Phone (body.touch) = thin strip on top, log fades, buttons under the thumb.
   Colours only from js/art.js PALETTE, sharp corners, bevel light top-left / dark bottom-right,
   pixel font Tiny5 (OFL, assets/fonts) on 16 px steps.
   ===================================================================================== */
@font-face { font-family: 'Tiny5'; src: url('../assets/fonts/tiny5-latin.woff2') format('woff2'); unicode-range: U+0000-00FF, U+2013-2014, U+2022; font-display: swap; }
@font-face { font-family: 'Tiny5'; src: url('../assets/fonts/tiny5-latin-ext.woff2') format('woff2'); unicode-range: U+0100-024F; font-display: swap; }
:root {
  --ink: #0d0b16; --gnd1: #1e1827; --gnd2: #2d2438; --gnd3: #3c3349;
  --con1: #2f3243; --con2: #474a5f; --con3: #646880; --con4: #8a8ea6;
  --cyn1: #0a4a58; --cyn2: #0f9aa6; --cyn3: #2fe3d1; --cyn4: #b9fff1;
  --mag1: #3a0f3d; --mag2: #85207a; --mag3: #e0319b; --mag4: #ff8fd2;
  --amb: #ffc15a; --wht: #f3f0ff; --rst4: #d98a45; --veg4: #8ccf5a;
  --px: 'Tiny5', ui-monospace, monospace;
  --side: 248px;      /* desktop frame panel */
  --bottom: 92px;     /* desktop strip under the map: log = 2 old lines (1 row each) + newest (up to 2 rows) */
  --abar: 420px;      /* desktop action bar width (U2: 5 slots) */
  --hf: 16px;         /* U5: HUD pixel font (Tiny5), whole steps only: 16 or 24 */
}
#hud, #actionbar, #log, .touch-btn, #net-status { font-family: var(--px); font-size: var(--hf); line-height: 1.25; -webkit-font-smoothing: none; font-smooth: never; }
.px-frame, #hud, #actionbar, #log { background: var(--gnd1); }

/* ---------- shared HUD pieces ---------- */
#hud { position: fixed; z-index: 5; color: var(--wht); display: grid; gap: 6px; pointer-events: none; }
#hud .hud-lvl { grid-area: lvl; color: var(--wht); white-space: nowrap; }
#hud .hud-zone { grid-area: zone; white-space: nowrap; }
#hud .hud-zone.safe { color: var(--cyn3); }
#hud .hud-zone.danger { color: var(--amb); }
#hud .hud-zone.deadly { color: var(--mag3); }
#hud .hud-hp { grid-area: hp; position: relative; }
#hud .hud-xp { grid-area: xp; position: relative; }
#hud .hud-cr { grid-area: cr; color: var(--cyn3); white-space: nowrap; }
#hud .hud-floor { grid-area: floor; color: var(--con4); white-space: nowrap; justify-self: end; }
#hud .hud-btns { grid-area: btns; display: flex; gap: 6px; }
#hud .hud-quests { grid-area: quests; }
/* G1: one current objective, PC and phone (js/guide.js + ui.js) */
#hud .hud-goal { grid-area: goal; display: flex; gap: 6px; align-items: baseline; padding: 4px 6px; background: var(--ink); border-left: 2px solid var(--amb); color: var(--wht); line-height: 18px; }
#hud .hud-goal:empty { display: none; }
#hud .hud-goal .hg-head { color: var(--amb); }
#hud .hud-goal .hg-arrow { color: var(--amb); font-size: 18px; min-width: 1em; text-align: center; }
#hud .hud-goal .hg-text { flex: 1; overflow: hidden; text-overflow: ellipsis; }
#hud .hud-goal .hg-dist { color: var(--con4); white-space: nowrap; }
#hud .hud-goal.ready { border-left-color: var(--cyn3); }
#hud .hud-goal.ready .hg-head, #hud .hud-goal.ready .hg-arrow { color: var(--cyn3); }
body.touch #hud .hud-goal { padding: 1px 4px; font-size: 14px; line-height: 16px; white-space: nowrap; }
body.touch #hud .hud-goal .hg-head { display: none; }
#hud .bar { height: 20px; background: var(--ink); border: 2px solid var(--con1); border-radius: 0; overflow: hidden; }
#hud .bar-fill { height: 100%; width: 0%; transition: width 0.1s linear; }
#hud .bar-fill.hp { background: var(--mag3); box-shadow: inset 0 2px 0 var(--mag4), inset 0 -2px 0 var(--mag2); }
#hud .bar-fill.xp { background: var(--cyn2); box-shadow: inset 0 2px 0 var(--cyn3), inset 0 -2px 0 var(--cyn1); }
#hud .bar-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--wht); text-shadow: 1px 1px 0 var(--ink), -1px 0 0 var(--ink), 0 -1px 0 var(--ink); white-space: nowrap; }
#inv-btn, #menu-btn {
  pointer-events: auto; cursor: pointer; flex: 1; height: 32px; padding: 0 8px; border-radius: 0;
  font: var(--hf) var(--px); color: var(--cyn3); background: var(--gnd2);
  border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3);
}
#inv-btn:hover, #menu-btn:hover { background: var(--gnd3); }
#inv-btn.has-points { color: var(--amb); }

/* ---------- desktop frame (default, any non-touch layout) ---------- */
body:not(.touch) #viewport { right: var(--side); bottom: var(--bottom); }
body:not(.touch) #hud {
  top: 0; right: 0; bottom: 0; width: var(--side); padding: 12px; align-content: start;
  grid-template-columns: 1fr auto;
  grid-template-areas: "lvl zone" "hp hp" "xp xp" "cr floor" "goal goal" "btns btns" "quests quests";
  border-left: 2px solid var(--con2); box-shadow: inset 2px 0 0 var(--ink);
}
body:not(.touch) #hud .hud-lvl { font-size: calc(var(--hf) * 2); line-height: calc(var(--hf) * 2); }
body:not(.touch) #hud .hud-zone { align-self: end; text-align: right; }
body:not(.touch) #hud .hud-btns { margin: 4px 0 6px; }
body:not(.touch) .hud-quests { border-top: 2px solid var(--con1); padding-top: 8px; overflow-y: auto; max-height: calc(100vh - 260px); pointer-events: auto; }
.hud-quests .tq-head { color: var(--cyn3); margin-bottom: 6px; }
.hud-quests .tq-row { margin-bottom: 8px; padding-left: 6px; border-left: 2px solid var(--con2); }
.hud-quests .tq-row.ready { border-left-color: var(--amb); }
.hud-quests .tq-name { color: var(--wht); }
.hud-quests .tq-goal { color: var(--con4); }
.hud-quests .tq-row.ready .tq-goal { color: var(--amb); }
.hud-quests .tq-row.empty { color: var(--con4); border: 0; padding: 0; }

#actionbar { display: none; }
body:not(.touch) #actionbar {
  position: fixed; z-index: 5; right: var(--side); bottom: 0; width: var(--abar); height: var(--bottom);
  display: flex; gap: 6px; padding: 10px; border-top: 2px solid var(--con2); border-left: 2px solid var(--con1);
}
#actionbar .act {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font: var(--hf) var(--px); color: var(--wht); background: var(--gnd2); cursor: pointer; border-radius: 0; padding: 0;
  border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3);
}
#actionbar .act:hover { background: var(--gnd3); }
#actionbar .act:active { border-color: var(--ink) var(--con3) var(--con3) var(--ink); }
#actionbar .act .key { color: var(--con4); }
#actionbar .act.atk { color: var(--mag4); }
#actionbar .act.use { color: var(--cyn3); }
#actionbar .act.med { color: var(--amb); }
#actionbar .act.inv { color: var(--cyn4); }
#actionbar .act.tgt { color: var(--mag4); }
#actionbar .act.dim { opacity: 0.45; }

body:not(.touch) #log {
  position: fixed; z-index: 5; left: 0; bottom: 0; right: calc(var(--side) + var(--abar)); max-width: none;
  height: var(--bottom); padding: 8px 12px; border-radius: 0; overflow: hidden; pointer-events: none;
  border-top: 2px solid var(--con2); display: flex; flex-direction: column; justify-content: flex-end;
}
#log .log-line { color: var(--con4); line-height: 1.25; }
#log .log-line.new { color: var(--wht); }

/* windows on desktop: centred on the map, not on the whole window, and never over the frame */
body:not(.touch) #dialog { left: calc((100vw - var(--side)) / 2); bottom: calc(var(--bottom) + 24px); }
body:not(.touch) #inventory-panel { right: calc(var(--side) + 16px); max-height: calc(100vh - var(--bottom) - 24px); }
#net-status {
  position: fixed; z-index: 6; right: 12px; bottom: 12px; width: calc(var(--side) - 24px); padding: 4px 8px;
  background: var(--ink); border: 2px solid var(--cyn1); border-radius: 0; color: var(--cyn3); font-size: var(--hf); pointer-events: none;
}
body.touch #net-status { display: none !important; }
/* P0: nakładka pomiaru (F3 albo ?perf). Tylko diagnostyka. */
#perf {
  position: fixed; z-index: 30; left: 8px; top: 8px; margin: 0; padding: 4px 8px; max-width: calc(100vw - 16px);
  background: var(--ink); border: 1px solid var(--cyn1); color: var(--cyn3); font: 12px/1.3 monospace; white-space: pre; pointer-events: none; opacity: 0.9;
}

/* ---------- phone: thin strip on top ---------- */
body.touch #hud {
  top: calc(var(--sat) + 4px); left: calc(var(--sal) + 4px); right: calc(var(--sar) + 4px); max-width: 520px;
  padding: 4px 6px; gap: 2px 6px; align-items: center;
  grid-template-columns: auto 1fr auto auto;
  grid-template-areas: "lvl hp hp btns" "zone xp cr btns" "goal goal goal goal";
  border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3);
}
body.touch #hud .hud-btns { align-self: stretch; }
body.touch #inv-btn, body.touch #menu-btn { width: 44px; height: auto; min-height: 40px; flex: none; padding: 0; }
body.touch #hud .hud-xp .bar { height: 8px; border-width: 1px; }
body.touch #hud .hud-xp .bar-text { display: none; }
body.touch #hud .hud-zone, body.touch #hud .hud-cr { line-height: 16px; }
body.touch #hud .hud-floor, body.touch #hud .hud-quests { display: none !important; }

/* log: no box, outlined text under the strip, fades when quiet (ui.js adds .idle) */
body.touch #log {
  position: fixed; z-index: 5; top: calc(var(--sat) + 62px); bottom: auto; left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px);
  max-width: 520px; padding: 0; background: none; border: 0; pointer-events: none;
  text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink), 2px 2px 0 var(--ink);
  transition: opacity 0.6s;
}
body.touch #log.idle { opacity: 0; }
body.touch #log .log-line { color: var(--con4); }
body.touch #log .log-line.new { color: var(--wht); }
body.touch #log .log-line:not(:nth-last-child(-n+2)) { display: none; }
@media (orientation: landscape) {
  /* phone on its side: the bottom left is free (no d-pad), the log goes there, the strip stays short */
  body.touch.no-dpad #log { top: auto; bottom: calc(var(--sab) + 12px); right: auto; width: min(46vw, 480px); }
  body.touch:not(.no-dpad) #log { left: calc(var(--sal) + 540px); top: calc(var(--sat) + 6px); right: calc(var(--sar) + 8px); }
}

/* touch buttons: square pixel keys, palette colours, ATK biggest (most used) */
body.touch .touch-btn {
  border-radius: 0; border: 2px solid; font-family: var(--px); font-size: 16px; font-weight: 400;
  background: rgba(13, 11, 22, 0.82); flex-direction: column; gap: 2px;
}
body.touch #btn-up, body.touch #btn-down, body.touch #btn-left, body.touch #btn-right {
  border-radius: 0; color: var(--cyn3); border-color: var(--cyn2) var(--cyn1) var(--cyn1) var(--cyn2);
}
body.touch #btn-attack { color: var(--mag4); border-color: var(--mag3) var(--mag2) var(--mag2) var(--mag3); font-size: 32px; line-height: 32px; }
body.touch #btn-interact { border-radius: 0; color: var(--cyn4); border-color: var(--cyn3) var(--cyn1) var(--cyn1) var(--cyn3); background: rgba(10, 74, 88, 0.85); }
body.touch #btn-use { border-radius: 0; color: var(--amb); border-color: var(--amb) var(--rst4) var(--rst4) var(--amb); }
body.touch #btn-use .btn-count { color: var(--wht); }
body.touch .touch-btn.dim { opacity: 0.45; }
body.touch #btn-interact.ctx-off { visibility: hidden; }
/* 17B.1 fixes: #btn-interact's own display:flex (id rule) beat the hover/pointer media query, so a
   touch E button showed on desktop since 16B. Flex also ate the space in "HP 100/100". */
body:not(.touch) .touch-btn { display: none !important; }
#hud .bar-text { display: block; text-align: center; line-height: 20px; }
/* desktop log: older lines stay on one row (ellipsis), the newest may wrap to two, so 4 rows always fit */
body:not(.touch) #log .log-line { line-height: 20px; }
body:not(.touch) #log .log-line:not(.new) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body:not(.touch) #log .log-line.new { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* 17C.1: chat + party list (17C) moved out of the desktop frame's way and given the HUD look.
   Desktop: chat lines sit on the map's bottom-left edge, just above the log strip (they fade like
   the old ones did); party list lives at the bottom of the frame, above the online status. */
#chat, #chat-btn, #party-list, #party-invite, #pmenu { font-family: var(--px); font-size: 16px; -webkit-font-smoothing: none; }
.chat-line { border-radius: 0; background: rgba(13, 11, 22, 0.82); }
.chat-line .chat-from { color: var(--cyn3); font-weight: 400; }
.chat-line.party .chat-from { color: var(--veg4, #8ccf5a); }
.chat-line.self .chat-from { color: var(--amb); }
body.online:not(.touch) #chat { right: auto; left: 8px; bottom: calc(var(--bottom) + 8px); width: min(460px, calc(100vw - var(--side) - 24px)); font-size: 16px; }
body.online.chat-open:not(.touch) #chat { border-radius: 0; background: var(--gnd1); border: 2px solid; border-color: var(--cyn3) var(--cyn1) var(--cyn1) var(--cyn3); }
#chat-input, #chat-ch, #chat-send, #chat-btn { border-radius: 0; font-family: var(--px); }
body:not(.touch) #party-list {
  top: auto; right: 12px; bottom: 52px; width: calc(var(--side) - 24px);
  border-radius: 0; background: var(--ink); border: 2px solid var(--con1); font-size: 16px;
}
#party-list .party-head { color: var(--veg4, #8ccf5a); font-weight: 400; }
#party-list .party-bar { height: 6px; border-radius: 0; background: var(--gnd2); }
#party-list .party-bar > div { background: var(--mag3); }
body.touch #party-list { border-radius: 0; background: rgba(13, 11, 22, 0.85); border: 2px solid var(--con1); font-size: 16px; }
body.online.touch #chat-btn { border-radius: 0; background: rgba(13, 11, 22, 0.85); border: 2px solid; border-color: var(--cyn3) var(--cyn1) var(--cyn1) var(--cyn3); color: var(--cyn3); font-weight: 400; font-size: 16px; }
#party-invite, #pmenu { background: var(--gnd1); }
#party-list .party-head button { font-family: var(--px); font-size: 16px; border-radius: 0; }
#chat-input { border-radius: 0; font-family: var(--px); font-size: 16px; }

/* =====================================================================================
   D0a: the game in the site frame (play.html). Desktop: a 32 px site bar on top, the whole
   desktop frame (map, HUD panel, windows) moves down by --top. Phone: no bar (--top: 0).
   ===================================================================================== */
#sitebar { display: none; }
body.framed:not(.touch) { --top: 32px; }
body.framed:not(.touch) #sitebar {
  display: flex; align-items: center; gap: 16px; position: fixed; z-index: 7; top: 0; left: 0; right: 0; height: var(--top);
  padding: 0 12px; background: var(--ink); border-bottom: 2px solid var(--con1);
  font: 16px var(--px); -webkit-font-smoothing: none; font-smooth: never;
}
#sitebar a { color: var(--cyn3); text-decoration: none; }
#sitebar a:hover { color: var(--cyn4); }
#sitebar .sb-logo { display: flex; align-items: center; gap: 8px; color: var(--wht); letter-spacing: 1px; }
#sitebar .sb-logo img { image-rendering: pixelated; }
#sitebar .sb-logo b { color: var(--mag3); font-weight: 400; }
#sitebar .sb-link { padding: 2px 8px; border: 2px solid; border-color: var(--con2) var(--ink) var(--ink) var(--con2); background: var(--gnd1); }
#sitebar .sb-build { margin-left: auto; color: var(--con3); }
#sitebar .sb-user { color: var(--amb); }
#sitebar [hidden], .menu-box [hidden] { display: none !important; }
body.framed:not(.touch) #viewport { top: var(--top); }
body.framed:not(.touch) #hud { top: var(--top); }
body.framed:not(.touch) .hud-quests { max-height: calc(100vh - 260px - var(--top)); }
body.framed:not(.touch) #inventory-panel { top: calc(50% + var(--top) / 2); max-height: calc(100vh - var(--bottom) - var(--top) - 24px); }
.menu-box .menu-link {
  display: block; margin: 4px 0; padding: 6px; text-align: center; text-decoration: none;
  color: #EAF5F6; border: 1px solid #314451;
}
.menu-box .menu-link:hover { border-color: #00CCAA; }
body.touch .menu-box .menu-link { min-height: 44px; font-size: 15px; line-height: 30px; }

/* D1c: compact backpack on the left edge, same panel as EQ/I */
#backpack-btn {
  position: fixed; left: 8px; top: 50%; transform: translateY(-50%);
  z-index: 6; width: 40px; height: 40px; padding: 0; cursor: pointer;
  font-size: 20px; background: var(--gnd2); color: var(--cyn3);
  border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3);
}
body.touch #backpack-btn { left: calc(var(--sal, 0px) + 8px); }
/* D1c: inventory centered over the game */
#inventory-panel {
  left: 50%; right: auto; top: 50%; transform: translate(-50%, -50%);
  width: min(320px, calc(100vw - 32px)); max-height: calc(100vh - 24px); overflow-y: auto;
}
#log .log-line.green { color: var(--veg4); }
#log .log-line.green.new { color: var(--veg4); }
#log .log-line.gold, #log .log-line.gold.new { color: var(--amb); font-weight: 600; }   /* G3: rare loot */
#log .log-line.boss, #log .log-line.boss.new { color: var(--mag4); font-weight: 600; }

/* D1c.2: character panel from the server room computer */
#char-panel {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(340px, calc(100vw - 32px)); max-height: calc(100vh - 24px); overflow-y: auto;
  background: rgba(17, 29, 41, 0.97); border: 1px solid #00CCAA; padding: 12px;
  z-index: 20; color: #EAF5F6; font-family: system-ui, sans-serif;
}
.char-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.char-title { font-weight: 600; color: #00CCAA; }
#char-close { background: transparent; border: 1px solid #00CCAA; color: #00CCAA; width: 28px; height: 28px; cursor: pointer; }
.char-body { display: grid; gap: 6px; font-size: 14px; }
.char-row { display: flex; justify-content: space-between; }
.char-label { color: #8FABAE; }
/* D1c.3: HUD stays visible; panel is modal via pointer isolation */

/* D1c.3: character workspace */
#char-panel { width: min(860px, calc(100vw - 24px)); }
.char-workspace { display: grid; grid-template-columns: 180px 1fr 1fr; gap: 12px; }
.char-left, .char-center, .char-right { display: flex; flex-direction: column; gap: 6px; }
.char-sprite { width: 64px; height: 96px; image-rendering: pixelated; background: #1e1827; border: 1px solid #474a5f; }
.char-stat { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
/* G4: what +1 point does / you vs the monster of your level */
.char-prev { color: var(--cyn4); font-size: 11px; margin: 0 0 6px 2px; line-height: 1.3; }
.char-vs { color: var(--con4); margin-top: 6px; }
.inv-mut-nums { color: var(--cyn4); margin: 0 0 4px; }
.char-plus:disabled { opacity: 0.35; cursor: default; }
.char-undo { background: var(--con2); color: var(--cyn4); margin-bottom: 4px; }
.char-plus, .char-apply { background: #0f9aa6; color: #0d0b16; border: none; padding: 2px 8px; cursor: pointer; font-weight: 600; }
.char-grids { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.char-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; }
.char-slot { width: 36px; height: 36px; background: #2d2438; border: 1px solid #474a5f; position: relative; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.char-slot.selected { border-color: #2fe3d1; }
.char-slot .qty { position: absolute; bottom: 0; right: 1px; font-size: 10px; color: #f3f0ff; }
.char-heading { color: #00CCAA; font-weight: 600; font-size: 13px; }
@media (max-width: 700px) {
  .char-workspace { grid-template-columns: 1fr; }
  .char-grids { grid-template-columns: 1fr 1fr; }
}

/* ---------- U2: target frame (over the map, display only) ---------- */
#target-frame {
  position: absolute; z-index: 4; top: 8px; left: 50%; transform: translateX(-50%); width: 220px;
  padding: 4px 6px; background: rgba(13, 11, 22, 0.86); border: 2px solid; border-color: var(--mag3) var(--mag1) var(--mag1) var(--mag3);
  font-family: var(--px); font-size: 16px; line-height: 18px; color: var(--wht); pointer-events: none; -webkit-font-smoothing: none;
}
#target-frame[hidden] { display: none; }
#target-frame .tf-head { display: flex; justify-content: space-between; gap: 6px; }
#target-frame .tf-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#target-frame .tf-lvl { color: var(--amb); white-space: nowrap; }
#target-frame.weak .tf-lvl { color: var(--con4); }
#target-frame.strong .tf-lvl { color: var(--mag4); }
#target-frame .tf-bar { height: 10px; margin-top: 3px; background: var(--ink); border: 1px solid var(--con1); overflow: hidden; }
#target-frame .tf-fill { height: 100%; width: 100%; background: var(--mag3); box-shadow: inset 0 1px 0 var(--mag4); transition: width 0.1s linear; }
#target-frame .tf-hp-text { display: block; text-align: right; font-size: 14px; line-height: 16px; color: var(--con4); }
/* phone: landscape = top right (the strip is top left), portrait = above the action buttons */
body.touch #target-frame { position: fixed; transform: none; left: auto; width: min(44vw, 220px); }
@media (orientation: landscape) {
  body.touch #target-frame { top: calc(var(--sat) + 4px); right: calc(var(--sar) + 4px); }
  body.touch:not(.no-dpad) #target-frame { top: calc(var(--sat) + 52px); }   /* the log sits top right with the d-pad on */
}
@media (orientation: portrait) { body.touch #target-frame { top: auto; bottom: calc(var(--sab) + 44px + 2 * var(--atk)); right: calc(var(--sar) + 8px); } }
body.touch.left-hand #target-frame { right: auto; left: calc(var(--sal) + 8px); }
body.touch.ui-open #target-frame { display: none; }

/* U2: CEL button on the phone, above AKCJA (next to MED) */
body.touch #btn-target {
  right: calc(var(--sar) + 30px + var(--atk)); bottom: calc(var(--sab) + 32px + var(--atk)); left: auto;
  width: calc(var(--atk) * 0.62); height: calc(var(--atk) * 0.62); border-radius: 0; font-size: 14px;
  color: var(--mag4); border-color: var(--mag3) var(--mag1) var(--mag1) var(--mag3);
}
body.touch.left-hand #btn-target { left: calc(var(--sal) + 30px + var(--atk)); right: auto; }

/* ---------- U3: phone layout = thumb arc (PLAN_HUD). Sizes fixed: ATAK 76, AKCJA/MED 56, CEL/PLECAK 48 px,
   gaps >= 10 px. Right hand by default, body.touch.left-hand mirrors. The d-pad stays off by default (ui.js). ---------- */
:root { --atk: 76px; --b56: 56px; --b48: 48px; --gap: 10px; --arcR: calc(var(--sar) + 12px); --arcL: calc(var(--sal) + 12px); --arcB: calc(var(--sab) + 16px); }
body.touch #btn-attack, body.touch #btn-interact, body.touch #btn-use, body.touch #btn-target, body.touch #btn-inventory {
  position: fixed; z-index: 5; left: auto; border-radius: 0; align-items: center; justify-content: center; user-select: none; -webkit-user-select: none;
}
body.touch #btn-attack    { width: var(--atk); height: var(--atk); right: var(--arcR); bottom: var(--arcB); }
body.touch #btn-interact  { width: var(--b56); height: var(--b56); font-size: 14px; right: calc(var(--arcR) + var(--atk) + var(--gap)); bottom: calc(var(--arcB) + 10px); }
body.touch #btn-use       { width: var(--b56); height: var(--b56); font-size: 14px; right: calc(var(--arcR) + 10px); bottom: calc(var(--arcB) + var(--atk) + var(--gap)); }
body.touch #btn-target    { width: var(--b48); height: var(--b48); font-size: 12px; right: calc(var(--arcR) + var(--atk) + var(--gap) + 4px); bottom: calc(var(--arcB) + var(--atk) + var(--gap) + 4px); }
body.touch #btn-inventory { width: var(--b48); height: var(--b48); font-size: 12px; right: calc(var(--arcR) + var(--atk) + var(--b56) + 2 * var(--gap)); bottom: calc(var(--arcB) + 14px);
  color: var(--cyn3); border-color: var(--cyn2) var(--cyn1) var(--cyn1) var(--cyn2); }
body.touch.left-hand #btn-attack    { left: var(--arcL); right: auto; }
body.touch.left-hand #btn-interact  { left: calc(var(--arcL) + var(--atk) + var(--gap)); right: auto; }
body.touch.left-hand #btn-use       { left: calc(var(--arcL) + 10px); right: auto; }
body.touch.left-hand #btn-target    { left: calc(var(--arcL) + var(--atk) + var(--gap) + 4px); right: auto; }
body.touch.left-hand #btn-inventory { left: calc(var(--arcL) + var(--atk) + var(--b56) + 2 * var(--gap)); right: auto; }
/* the arc has PLECAK, the old edge button would only duplicate it */
body.touch #backpack-btn { display: none; }
body.online.touch #chat-btn { bottom: calc(var(--arcB) + var(--atk) + var(--b56) + 2 * var(--gap)); }

/* log: PC shows the last 3 lines, phone the last 2; tap on the phone log = all lines on a dark box */
#log .log-line:not(:nth-last-child(-n+3)) { display: none; }
body.touch #log { pointer-events: auto; }
body.touch #log.idle { pointer-events: none; }
body.touch #log.expanded { background: rgba(13, 11, 22, 0.88); border: 2px solid var(--con1); padding: 4px 6px; max-height: 50vh; overflow-y: auto; }
body.touch #log.expanded .log-line { display: block; }
body.touch.ui-open #log.expanded { display: none; }

/* drawers: grip on top, big ✕ at the bottom (thumb). Desktop: neither. */
.drawer-grip, .drawer-close { display: none; }
body.touch .drawer-grip { display: block; width: 48px; height: 6px; margin: 0 auto 8px; background: var(--con2); touch-action: none; }
body.touch .drawer-close {
  display: block; width: 100%; min-height: 48px; margin-top: 10px; font-family: var(--px); font-size: 16px; cursor: pointer;
  background: var(--gnd2); color: var(--cyn3); border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3);
}
body.touch .inv-header, body.touch .char-header { touch-action: none; }
body.touch #char-panel {
  top: auto; bottom: 0; left: 0; right: 0; transform: none; width: 100%;
  max-height: 80vh; padding: 10px 12px calc(12px + var(--sab)); border-width: 1px 0 0 0;
}
body.touch #char-close { width: 40px; height: 40px; }
body.touch .char-workspace { grid-template-columns: 1fr; }
@media (orientation: landscape) {
  body.touch .drawer-grip { width: 6px; height: 48px; margin: 0; position: absolute; left: 4px; top: 50%; transform: translateY(-50%); }
  body.touch #char-panel {
    left: auto; right: 0; top: 0; bottom: 0; width: min(520px, 70vw); max-height: 100vh;
    border-width: 0 0 0 2px; padding-top: calc(10px + var(--sat)); padding-right: calc(12px + var(--sar));
  }
}

/* =====================================================================================
   U4: PC = hotbar 1-8, docked side panel (I/C/J) that does not stop the game, chat hint, aim cursor.
   H6 (part): panels in the HUD look (palette, bevel), long text in a smooth font, headers/keys in Tiny5.
   Phone (body.touch) untouched: everything below is body:not(.touch) or desktop-only.
   ===================================================================================== */
:root { --abar: 580px; --dock: 320px; }
@media (max-width: 1180px) { :root { --abar: 500px; } }
body:not(.touch) #actionbar .act { position: relative; min-width: 0; gap: 0; padding: 14px 2px 2px; }
body:not(.touch) #actionbar .act .num { position: absolute; left: 4px; top: 2px; color: var(--con3); font-size: var(--hf); line-height: var(--hf); }
body:not(.touch) #actionbar .act .act-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body:not(.touch) #actionbar .act .key { font-size: var(--hf); line-height: calc(var(--hf) + 2px); }
#actionbar .act.item { color: var(--amb); }
#actionbar .act.item.empty { color: var(--con3); background: var(--gnd1); border-color: var(--con1) var(--ink) var(--ink) var(--con1); cursor: default; }

/* frame: panel tabs with their key, menu on its own row */
body:not(.touch) #hud .hud-btns { flex-wrap: wrap; }
.tab-btn { display: none; }
body:not(.touch) .tab-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1 1 0; min-width: 0; height: calc(var(--hf) * 2.75); padding: 0 2px;
  pointer-events: auto; cursor: pointer; border-radius: 0; font: var(--hf) var(--px); line-height: calc(var(--hf) + 2px); color: var(--cyn3); background: var(--gnd2);
  border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3);
}
body:not(.touch) .tab-btn .key { color: var(--con4); }
body:not(.touch) .tab-btn:hover { background: var(--gnd3); }
body:not(.touch) .tab-btn.on { background: var(--cyn1); color: var(--cyn4); border-color: var(--ink) var(--cyn2) var(--cyn2) var(--ink); }
body:not(.touch) #hud #menu-btn { flex: 1 0 100%; }
body:not(.touch) #backpack-btn { display: none; }

/* docked panel: a column between the map and the frame, full map height, the map keeps playing */
body:not(.touch) #inventory-panel, body.framed:not(.touch) #inventory-panel {
  left: auto; right: var(--side); top: var(--top, 0px); bottom: var(--bottom); transform: none;
  width: var(--dock); max-height: none; overflow-y: auto; z-index: 6; padding: 12px;
  background: var(--gnd1); color: var(--wht); border: 0; border-left: 2px solid var(--con2); box-shadow: inset 2px 0 0 var(--ink), -6px 0 12px rgba(13, 11, 22, 0.5);
}
body:not(.touch) #inventory-panel[data-tab="bag"] :is(#inv-char, #inv-quests),
body:not(.touch) #inventory-panel[data-tab="char"] :is(#inv-quests, #inv-equip, #inv-stats, #inv-grid, #inv-detail),
body:not(.touch) #inventory-panel[data-tab="quests"] :is(#inv-char, #inv-equip, #inv-stats, #inv-grid, #inv-detail) { display: none; }
body:not(.touch) #inventory-panel:not([data-tab="bag"]) #inv-count { visibility: hidden; }
body:not(.touch) #inventory-panel .inv-char, body:not(.touch) #inventory-panel .inv-quests { border: 0; font-size: 14px; }
/* target frame and the dialog move left so the docked panel never covers them */
body.panel-docked:not(.touch) #dialog { left: calc((100vw - var(--side) - var(--dock)) / 2); }

/* H6: one look for the panels (palette + bevel), readable body text, pixel font for headers and keys */
#inventory-panel, #char-panel, #dialog, .menu-box { border-radius: 0; }
#inventory-panel .inv-header, .menu-title, #dialog .name { font-family: var(--px); font-size: 16px; font-weight: 400; letter-spacing: 1px; -webkit-font-smoothing: none; }
#inventory-panel .inv-title, .menu-title, .inv-quests .q-head, .char-head { color: var(--cyn3); }
#inv-count { color: var(--con4); font-family: var(--px); }
#inv-close { border-radius: 0; font-family: var(--px); background: var(--gnd2); color: var(--con4); border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3); }
.inv-slot { border-radius: 0; background: var(--ink); border-color: var(--con1); }
.inv-slot.selected { border-color: var(--cyn3); }
.inv-use { border-radius: 0; }
.inv-detail { color: var(--wht); }
.hot-assign { margin-top: 8px; color: var(--con4); font-size: 12px; display: flex; align-items: center; gap: 4px; }
.hot-assign-btn {
  width: 28px; height: 26px; padding: 0; cursor: pointer; border-radius: 0; font: 16px var(--px); color: var(--amb); background: var(--gnd2);
  border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3);
}
.hot-assign-btn.on { background: var(--amb); color: var(--ink); }
body:not(.touch) #dialog { background: var(--gnd1); border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3); box-shadow: 0 0 0 2px var(--ink); }
body:not(.touch) #dialog .name { color: var(--mag4); }
body:not(.touch) #dialog-actions button { border-radius: 0; background: var(--gnd2); color: var(--cyn3); border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3); }
body:not(.touch) #dialog-actions button:hover:not(:disabled) { background: var(--cyn1); color: var(--cyn4); }
body:not(.touch) #dialog.terminal { border-color: var(--cyn3) var(--cyn1) var(--cyn1) var(--cyn3); }
.menu-box { background: var(--gnd1); border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3); }
.menu-box button, .menu-box .menu-link { border-radius: 0; background: var(--gnd2); color: var(--wht); border: 2px solid; border-color: var(--con3) var(--ink) var(--ink) var(--con3); }
.menu-box button:hover, .menu-box .menu-link:hover { background: var(--gnd3); border-color: var(--cyn2) var(--ink) var(--ink) var(--cyn2); }
.menu-content { color: var(--con4); }

/* chat: the hint sits in the log strip's right corner (online, desktop, chat closed); Enter opens it */
#chat-hint { display: none; }
body.online:not(.touch):not(.chat-open) #chat-hint {
  display: block; position: fixed; z-index: 6; bottom: 8px; right: calc(var(--side) + var(--abar) + 10px);
  font: var(--hf) var(--px); color: var(--con3); pointer-events: none; -webkit-font-smoothing: none;
}
body.online:not(.touch) #log { padding-right: 130px; }
/* mouse over an enemy = crosshair (click = target + walk + autoattack) */
body.aim:not(.touch) #game { cursor: crosshair; }
/* U4: item slots show the backpack icon (same shapes as .inv-slot), name in the tooltip */
#actionbar .act.item .icon { display: block; width: 0; height: 18px; margin: 2px 0; }
#actionbar .act.item .icon.stymulant { width: 8px; height: 18px; background: var(--amb); box-shadow: inset 0 3px 0 var(--wht); }
#actionbar .act.item .icon.medpak { width: 18px; height: 14px; margin: 4px 0 2px; background: var(--mag3); box-shadow: inset 0 2px 0 var(--mag4), inset 0 -2px 0 var(--mag2); }

/* =====================================================================================
   U5: HUD size S/M/L (ui.js prefs.hudSize -> body.hud-s / body.hud-l, M = no class = U3/U4 layout).
   PC: frame width, bottom strip, hotbar, docked panel; font only in whole Tiny5 steps (16/24) so it stays sharp.
   Phone: the thumb arc buttons (sizes and gap). Display only.
   ===================================================================================== */
body.hud-s:not(.touch) { --side: 216px; --bottom: 80px; --abar: 460px; --dock: 280px; }
body.hud-l:not(.touch) { --hf: 24px; --side: 360px; --bottom: 128px; --abar: 800px; --dock: 400px; }
/* L below 1600 px: a shorter hotbar (the log keeps room), slot names in 16 px so they are not cut; keys stay 24 */
@media (max-width: 1599px) { body.hud-l:not(.touch) { --abar: 640px; } body.hud-l:not(.touch) #actionbar .act .act-label { font-size: 16px; } }
@media (max-width: 1180px) { body.hud-s:not(.touch) { --abar: 400px; } body.hud-l:not(.touch) { --abar: 520px; } }
body.hud-l:not(.touch) #hud .bar { height: 28px; }
body.hud-l:not(.touch) .hud-quests { max-height: calc(100vh - 340px); }
body.touch.hud-s { --atk: 64px; --b56: 48px; --b48: 44px; --gap: 8px; }
body.touch.hud-l { --atk: 92px; --b56: 66px; --b48: 56px; --gap: 12px; }

/* S4: prolog, krok 0 (js/prologue-ui.js). Czarny ekran, 3 linie po kolei, POMIŃ od pierwszej sekundy. */
#intro-screen { position: fixed; inset: 0; z-index: 40; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 28px; background: var(--ink); color: #EAF5F6; text-align: center; padding: 24px; }
#intro-screen.on { display: flex; }
#intro-screen .intro-lines { display: flex; flex-direction: column; gap: 10px; }
#intro-screen .intro-l { margin: 0; font-size: clamp(16px, 4.2vw, 22px); letter-spacing: 1px; opacity: 0; animation: intro-in 0.9s ease-out forwards; }
#intro-screen .l2 { animation-delay: 1.1s; }
#intro-screen .l3 { animation-delay: 2.2s; color: var(--cyn4); }
#intro-screen .intro-wake { opacity: 0; animation: intro-in 0.6s ease-out 2.8s forwards; background: transparent; color: var(--cyn4); border: 2px solid var(--cyn3); padding: 12px 26px; font: inherit; font-size: 16px; letter-spacing: 2px; cursor: pointer; min-height: 48px; }
#intro-screen .intro-skip { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; background: transparent; color: var(--con4); border: 1px solid var(--con2); padding: 8px 14px; font: inherit; font-size: 13px; letter-spacing: 1px; cursor: pointer; min-height: 40px; }
@keyframes intro-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #intro-screen .intro-l, #intro-screen .intro-wake { animation: none; opacity: 1; } }
