/* ===== Phone HUD "แบบเกมมือถือ" (js/m2_hud.js, owner 2026-11-19) =====
   Everything here is under body.touch.m2 #hud, so the classic phone HUD and the desktop are untouched.
   Sizes are HUD px (the game scales #hud by the player's UI size); !important only where an older script
   writes an inline style on the same element (touch_fit.js on the chat, quests.js on the tracker, drag on windows). */

/* ---- what this layout replaces ---- */
body.touch.m2 #hud .rail.left,
body.touch.m2 #hud .rail.right,
body.touch.m2 #hud .mm-dock .rail.side,
body.touch.m2 #hud .panel.status .vip-top,
body.touch.m2 #hud .hud-hide-btn,
body.touch.m2 #hud .mcp-quest-chip,
body.touch.m2 #hud .mcp-map-chip,
body.touch.m2 #hud .panel.status .bar.job,
body.touch.m2 #hud .mm-foot { display: none !important; }
/* version 3 (owner 2026-11-26: "เหลือพื้นที่เกมเยอะๆหน่อย หน้าจอเอาแค่จำเป็น"): off the screen, still one tap away -
   the money (head of the ☰ sheet, and the bag), online / FPS / ping (Settings shows FPS), the quest tracker
   (the quest button opens the same list) */
body.touch.m2 #hud .purse,
body.touch.m2 #hud #questTracker { display: none !important; }
/* (.net-chips came back in version 4, small at the bottom left: see below) */

/* ---- top left: the card, money, buffs, quests ---- */
body.touch.m2 #hud .panel.status {
  top: 4px; left: 6px; translate: var(--safe-l, 0) 0; transform: scale(.8); transform-origin: top left;
}
/* under the card, one below the other: buffs, the party list, the world boss's damage board. Their place is the variable
   --m2-top, set by js/m2_hud.js leftColumn() and applied HERE with !important: js/status.js and js/world_boss.js write an inline `top` from the button rail this layout hides (the party list stood on the stick
   and the board on the HP bars; the board's is written again every second while a world boss is fought). */
body.touch.m2 #hud #buffBar,
body.touch.m2 #hud .party-box,
body.touch.m2 #hud .wb-live { top: var(--m2-top, 58px) !important; }
/* version 4 (owner 2026-11-28, "ที่ทำบัฟรอบก่อน..."): the buffs are the 11-07 look's glowing tiles (css/style.css
   body.char-v3 .st-row, which this layout cannot take whole: that body class moves the computer's HUD) - one row of
   four and a "+N" (js/m2_hud.js buffDress); open, every tile, five to a line. Not scaled with the card: a tile is
   a thing to tap. */
body.touch.m2 #hud #buffBar {
  bottom: auto !important; left: 8px !important; translate: var(--safe-l, 0) 0; transform: none;
  /* (display without !important: body.talking hides the whole HUD with an !important rule while an NPC talks) */
  display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 5px;
  width: 172px; max-height: 31px; overflow: visible; pointer-events: none;
}
/* the bar is its own stacking context (its translate): while a name bubble is open it rises over the party list and
   the world boss's board (z 29), which stand right under it; still under the chat strip's sheet (40) and windows */
body.touch.m2 #hud #buffBar.m2-tipping { z-index: 30; }
body.touch.m2 #hud #buffBar.m2-open { max-height: none; }
body.touch.m2 #hud #buffBar .st-row {
  --st-glow: 150, 200, 255;
  position: relative; flex: none; width: 30px; height: 30px; padding: 0; gap: 0; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center; overflow: visible; pointer-events: auto;
  border-radius: 8px; border: 1.5px solid rgba(var(--st-glow), .9); background: rgba(8, 14, 26, .45);
  box-shadow: 0 0 8px rgba(var(--st-glow), .6), inset 0 0 8px rgba(var(--st-glow), .28);
}
body.touch.m2 #hud #buffBar .st-row.bad { --st-glow: 255, 110, 100; }
body.touch.m2 #hud #buffBar .st-row.m2-fold { display: none; }
body.touch.m2 #hud #buffBar .st-row .st-name,
body.touch.m2 #hud #buffBar .st-row .st-left,
body.touch.m2 #hud #buffBar .st-row .st-bar { display: none; }
body.touch.m2 #hud #buffBar .st-row .st-ico {
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .8)) drop-shadow(0 0 3px rgba(var(--st-glow), .5));
}
body.touch.m2 #hud #buffBar .st-row .st-ico > * { width: 24px !important; height: 24px !important; image-rendering: pixelated; }
/* the time eats the tile, clockwise (--st-gone, js/status.js) */
body.touch.m2 #hud #buffBar .st-row::before {
  content: ""; position: absolute; inset: 0; border-radius: 7px; pointer-events: none; z-index: 1;
  background: conic-gradient(rgba(4, 8, 16, .55) calc(var(--st-gone, 0) * 1turn), transparent 0);
}
/* the last minute counts down over the icon (owner, 2026-10-21: "นับถอยหลังกลางรูปเมื่อจะหมดเวลา") */
body.touch.m2 #hud #buffBar .st-row .m2-count {
  position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center;
  font: 800 14px/1 "Segoe UI", Tahoma, sans-serif; color: #fff; pointer-events: none;
  text-shadow: 0 0 4px #000, 0 1px 2px #000, 0 -1px 2px #000, 1px 0 2px #000, -1px 0 2px #000;
}
body.touch.m2 #hud #buffBar .st-row.m2-soon .m2-count { color: #ff8e82; }
/* a tap names it, with its time (css/style.css's hover bubble sticks after a tap on a phone: this one is timed) */
body.touch.m2 #hud #buffBar .st-row::after,
body.touch.m2 #hud #buffBar .st-row:hover::after { display: none; }
body.touch.m2 #hud #buffBar .st-row.m2-tip { z-index: 300; }
body.touch.m2 #hud #buffBar .st-row.m2-tip::after {
  content: attr(data-tip); display: block; position: absolute; left: 0; right: auto; top: calc(100% + 6px);
  transform: none; z-index: 80; white-space: nowrap; padding: 4px 8px; border-radius: 7px; pointer-events: none;
  font: 400 11px/1.3 "Segoe UI", Tahoma, sans-serif; color: #f4e6c4;
  background: rgba(10, 14, 24, .96); border: 1px solid rgba(201, 146, 63, .55); box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
}
body.touch.m2 #hud #buffBar .m2-bmore {
  flex: none; width: 30px; height: 30px; padding: 0; margin: 0; pointer-events: auto; cursor: pointer;
  font: 700 11px/1 "Segoe UI", Tahoma, sans-serif; color: #ffe9b8; text-shadow: 0 1px 2px #000;
  border-radius: 8px; border: 1px solid rgba(217, 169, 62, .7);
  background: linear-gradient(180deg, rgba(40, 52, 88, .88), rgba(14, 19, 36, .9));
}

/* ---- version 4: EXP and Job along the very bottom edge (owner, 2026-10-21 for the computer: "เอาหลอด อีเอ็กพีกับ
   จ๊อปเล็กๆไว้ด้านล่าง แบบเขาไม่เกะกะ"; 2026-11-28 for this layout). EXP the left half, Job the right half, each
   with its number. Under the thumb buttons, which stand a little higher for it. ---- */
.m2-exp { display: none; }
body.touch.m2 #hud .m2-exp {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; height: 11px;
  display: flex; flex-direction: row; gap: 2px; pointer-events: none;
  padding: 0 var(--safe-r, 0px) 0 var(--safe-l, 0px); box-sizing: border-box; background: rgba(6, 9, 16, .55);
}
body.touch.m2 #hud .m2-exp .bar {
  position: relative; flex: 1 1 50%; min-width: 0; height: 11px; width: auto; margin: 0; padding: 0;
  border: 0; border-radius: 0; box-shadow: none; background: rgba(6, 9, 16, .72); overflow: hidden;
}
body.touch.m2 #hud .m2-exp .bar .fill { height: 100%; border-radius: 0; box-shadow: none; }
body.touch.m2 #hud .m2-exp .bar.xp .fill { background: linear-gradient(#ffe38a, #d9a53a); }
body.touch.m2 #hud .m2-exp .bar.job .fill { background: linear-gradient(#8fe6d4, #2f9c8c); }
body.touch.m2 #hud .m2-exp .bar span,
body.touch.m2 #hud .m2-exp .bar .m2-job-pct {
  position: absolute; top: 0; bottom: 0; display: flex; align-items: center; height: 11px; margin: 0;
  font: 700 9px/11px "Segoe UI", Tahoma, sans-serif; color: #ffeec0; white-space: nowrap; font-variant-numeric: tabular-nums;
  text-shadow: 0 0 2px #000, 0 1px 1px #000; pointer-events: none;
}
body.touch.m2 #hud .m2-exp .bar.xp span { left: 8px; right: auto; justify-content: flex-start; }
/* Job: its name and level from the left of its half, its share in the middle of it */
body.touch.m2 #hud .m2-exp .bar.job span { left: 8px; right: auto; justify-content: flex-start; color: #c8f4ea; }
body.touch.m2 #hud .m2-exp .bar.job .m2-job-pct { left: 50%; transform: translateX(-50%); color: #c8f4ea; }
/* (the stick, the thumb buttons and the chat strip stand on the line, not over it: their own rules below) */
body.touch.m2 #hud .party-box,
body.touch.m2 #hud .wb-live {
  left: 6px !important; translate: var(--safe-l, 0) 0; transform: scale(.8); transform-origin: top left;
}
body.touch.m2 #hud .wb-live { max-height: 232px; overflow: hidden; }
body.touch.m2 #hud #questTracker {
  top: auto !important; bottom: 236px !important; left: 6px !important; right: auto !important;
  width: 196px !important; max-width: 196px !important; max-height: 112px; overflow: hidden;
  translate: var(--safe-l, 0) 0; transform: none !important; opacity: .92;
}

/* ---- top right: the icon bar next to the minimap ---- */
body.touch.m2 #hud .mm-dock {
  top: 4px; right: 6px; transform: scale(.7) !important; transform-origin: top right;
}
/* the world boss's big HP bar (js/world_boss.js wbPlaceBar) measures its room up to the online chips, which are
   not on this screen: it ran under the icon bar and the map. It gets the room between the card and the bar. */
body.touch.m2 #hud .wb-bar {
  left: 244px !important; top: 6px !important; transform: none !important;
  width: max(200px, min(440px, calc(100% - 244px - var(--m2-dock, 170px) - 146px))) !important;
}
/* version 4: the bar of buttons is wider now (อีเวนต์ / บอสโลก / VIP): the boss bar takes exactly the gap between the
   card and it (js/m2_hud.js targetPlace: --m2-gap-l, --m2-tgt-w); the monster's plate goes under it */
body.touch.m2 #hud .wb-bar {
  left: var(--m2-gap-l, 244px) !important;
  width: min(440px, var(--m2-tgt-w, 200px)) !important;
}
/* js/touch_fit.js still writes --mm-fit for the classic layout's map (this one scales the dock itself) and the
   channel chip / fold button divide their size by it: they grew up to twice as big and pushed the map down */
body.touch.m2 #hud .mm-dock { --mm-fit: 1 !important; }
/* the PvP target list (js/pvp_targets.js: fixed, right edge, 40% down) lay on the skill arcs and the attack button */
body.touch.m2 .pvpt {
  right: auto; left: calc(8px + env(safe-area-inset-left, 0px)); top: 64px; max-height: 34vh; align-items: flex-start;
}
body.touch.m2 .pvpt .pvpt-head { text-align: left; }
/* on the player's own island: "จัดเกาะ" and the hoe (js/quests.js puts them under the map, at the right edge - on the
   top skill when the browser's bar is showing): under the icon bar, left of the map */
body.touch.m2 #hud #islandEditBtn { top: 52px !important; right: var(--m2-dock, 170px) !important; }
body.touch.m2 #hud #islandHoeBtn  { top: 52px !important; right: calc(var(--m2-dock, 170px) + 78px) !important; }
/* "a new release is ready" (js/pwa.js, top centre, 460 px) lay on the icon bar: one row down */
body.touch.m2 .update-bar { top: max(54px, env(safe-area-inset-top)); }
.m2-bar { display: none; }
body.touch.m2 #hud .m2-bar {
  position: absolute; top: 4px; right: var(--m2-dock, 210px); z-index: 12;
  display: flex; gap: 4px; pointer-events: auto;
}
body.touch.m2 #hud .m2-tile {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  width: 42px; height: 42px; padding: 0; margin: 0; box-sizing: border-box; cursor: pointer;
  font: inherit; color: #f4e6c4; text-shadow: 0 1px 2px #000;
  border: 1px solid rgba(217, 169, 62, .65); border-radius: 10px;
  background: linear-gradient(180deg, rgba(40, 52, 88, .88), rgba(14, 19, 36, .9));
  box-shadow: inset 0 1px 0 rgba(255, 235, 170, .18), 0 2px 4px rgba(0, 0, 0, .45);
}
body.touch.m2 #hud .m2-tile:active { transform: translateY(1px); filter: brightness(1.2); }
/* version 4: small tiles in a row UNDER the minimap - อีเวนต์ · บอสโลก · VIP · ร้านแคช (owner 2026-11-28: "ทำขนาดเล็ก
   หน่อย จะได้ไม่บังชื่อมอนเวลาตี", "เอาไปไว้ใต้มินิแมปพวกอีเว้นเพิ่มแคชชอป"). --m2-dock-b = the dock's foot, folded
   or open (js/m2_hud.js sync). */
.m2-dockrow { display: none; }
body.touch.m2 #hud .m2-dockrow {
  position: absolute; top: var(--m2-dock-b, 30px); right: 6px; z-index: 12; translate: calc(-1 * var(--safe-r, 0px)) 0;
  display: flex; flex-direction: row; flex-wrap: wrap; justify-content: flex-end; gap: 4px; pointer-events: auto;
  /* never wider than the minimap (--m2-dock-w): with the map folded a wider row ran left onto ☰ and the island
     buttons; a fifth tile wraps to a second line instead */
  max-width: var(--m2-dock-w, 150px);
}
/* the world boss's list, opened under its tile (js/m2_hud.js): never past the screen's foot - it scrolls */
body.touch.m2 #hud .wb-pop { max-height: calc(100% - 16px); overflow-y: auto; box-sizing: border-box; }
body.touch.m2 #hud .m2-small { width: 32px; height: 32px; border-radius: 8px; }
body.touch.m2 #hud .m2-small .m2-ico { width: 17px; height: 17px; font-size: 12px; }
body.touch.m2 #hud .m2-small .m2-lbl { font-size: 7px; line-height: 8px; padding: 0 1px; }
body.touch.m2 #hud .m2-small .m2-badge { top: -6px; right: -6px; min-width: 12px; font-size: 8px; line-height: 12px; }

/* version 4: online / FPS / ping back on the screen, small white letters in the bottom-left corner over the EXP line
   (owner 2026-11-28: "ส่วนพวกคนออนไลน เฟรมเรทปิงทำให้เล็กไว้ซ้ายล่าง"); the clock stays off */
body.touch.m2 #hud .net-chips {
  display: flex !important; position: absolute; top: auto !important; right: auto !important; left: 6px !important;
  bottom: 13px !important; transform: none !important; translate: var(--safe-l, 0) 0 !important;
  gap: 6px; z-index: 5;
  pointer-events: none;   /* inside the stick's unseen catch ring: a touch there must reach the stick */
}
body.touch.m2 #hud .net-chips > .chip { pointer-events: none !important; }
body.touch.m2 #hud .net-chips > .chip {
  height: auto; min-height: 0; padding: 0; margin: 0; border: 0 !important; border-image: none !important;
  background: none !important; box-shadow: none !important; font-size: 8px; line-height: 10px;
  text-shadow: 0 0 2px #000, 0 1px 1px #000;
}
body.touch.m2 #hud .net-chips > .chip .txt { font-size: 8px; line-height: 10px; }
body.touch.m2 #hud .net-chips .online-chip .txt { color: #eef2fa; }
body.touch.m2 #hud .net-chips .online-chip .dot { width: 5px; height: 5px; margin: 0 3px 0 0; box-shadow: 0 0 3px #5ee07a; }
body.touch.m2 #hud .net-chips .clock-chip { display: none !important; }
body.touch.m2 #hud .m2-tile.hidden { display: none; }
body.touch.m2 #hud .m2-ico {
  display: flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  background: center / contain no-repeat; image-rendering: pixelated; font-size: 16px; line-height: 1;
}
body.touch.m2 #hud .m2-lbl {
  max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: 8px; line-height: 10px; font-weight: 700; padding: 0 2px;
}
body.touch.m2 #hud .m2-tile.alert::after {
  content: ""; position: absolute; top: -3px; right: -3px; width: 9px; height: 9px; border-radius: 50%;
  background: #ff4d3d; border: 1px solid #2a0c08; box-shadow: 0 0 4px rgba(255, 80, 60, .8);
}
body.touch.m2 #hud .m2-badge {
  position: absolute; top: -5px; right: -5px; min-width: 14px; padding: 0 3px; border-radius: 7px;
  font: 700 9px/14px sans-serif; font-style: normal; color: #fff; background: #c8321f; border: 1px solid #2a0c08;
}

/* ---- bottom left: joystick ---- */
body.touch.m2 #hud .joy {
  left: 18px; bottom: 26px; opacity: .6; transition: opacity .15s;   /* version 4: 18 -> 26, over the EXP line */
  transform: scale(calc(.92 * var(--pad-k, 1))) !important; transform-origin: bottom left;
}
body.touch.m2 #hud .joy:active, body.touch.m2 #hud .joy.on, body.touch.m2 #hud .joy.active { opacity: 1; }

/* ---- bottom right: attack in the corner, skills on two arcs round it ----
   attack centre 54,54 from the corner; inner arc r112 (s0-s3, 52px), outer arc r176 (s4-s7, 50px),
   both from left (180deg) to up (90deg) in 30deg steps; potions left of the outer arc's foot;
   auto / pick up / sit / dash on an arc r236 above. Gaps >= 6px everywhere. */
body.touch.m2 #hud .tc {
  right: 6px; bottom: 14px; width: 316px; height: 312px;              /* version 4: 6 -> 14, over the EXP line */
  transform: scale(calc(.8 * var(--pad-k, 1))) !important; transform-origin: bottom right;
}
body.touch.m2 #hud .tc-attack { right: 6px; bottom: 6px; width: 96px; height: 96px; }
body.touch.m2 #hud .tc-skill { width: 52px; height: 52px; }
body.touch.m2 #hud .tc-skill.s0 { right: 140px; bottom: 28px; }
body.touch.m2 #hud .tc-skill.s1 { right: 125px; bottom: 84px; }
body.touch.m2 #hud .tc-skill.s2 { right: 84px; bottom: 125px; }
body.touch.m2 #hud .tc-skill.s3 { right: 28px; bottom: 140px; }
body.touch.m2 #hud .tc-skill.s4, body.touch.m2 #hud .tc-skill.s5,
body.touch.m2 #hud .tc-skill.s6, body.touch.m2 #hud .tc-skill.s7 { width: 50px; height: 50px; }
body.touch.m2 #hud .tc-skill.s4 { right: 205px; bottom: 29px; }
body.touch.m2 #hud .tc-skill.s5 { right: 181px; bottom: 117px; }
body.touch.m2 #hud .tc-skill.s6 { right: 117px; bottom: 181px; }
body.touch.m2 #hud .tc-skill.s7 { right: 29px; bottom: 205px; }
body.touch.m2 #hud .tc-skill .tc-slot { bottom: -12px; }
/* version 4 (owner 2026-11-28: "พวกรูปสกิล ให้รูปอยู่ในปุ่มวงกลมสิ"): the square skill picture sat high in the round
   button with its own dark square frame showing. It fills the circle now, cut round, its frame cut away (118%); the
   level stays over its foot. */
body.touch.m2 #hud .tc-skill .tc-ico {
  position: absolute; inset: 3px; border-radius: 50%; overflow: hidden;   /* (no z-index: the cooldown sweep and
     js/tc_skill_look.js's lit ring paint over it in their own order, as in version 3) */
  display: flex; align-items: center; justify-content: center;
}
body.touch.m2 #hud .tc-skill .tc-ico > canvas,
body.touch.m2 #hud .tc-skill .tc-ico > img { flex: none; width: 118% !important; height: 118% !important; }
body.touch.m2 #hud .tc-skill > b {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: 2px; text-align: center;
  text-shadow: 0 0 2px #000, 0 1px 1px #000, 1px 0 1px #000, -1px 0 1px #000;
}
body.touch.m2 #hud .tc-pot { width: 46px; height: 46px; right: 264px; }
body.touch.m2 #hud .tc-pot.hp { bottom: 6px; }
body.touch.m2 #hud .tc-pot.sp { bottom: 60px; }
body.touch.m2 #hud .tc-small { width: 40px; height: 40px; }
body.touch.m2 #hud .tc-auto { right: 238px; bottom: 152px; }
body.touch.m2 #hud .tc-pick { right: 169px; bottom: 227px; }
body.touch.m2 #hud .tc-sit  { right: 75px;  bottom: 266px; }
body.touch.m2 #hud .tc-dash { right: 9px;   bottom: 266px; }
/* version 3: a slot with nothing on it is not drawn - until a skill can be put there (the skill window is open,
   js/m2_hud.js bindState, or the game's own drag) */
body.touch.m2:not(.m2-bind):not(.skill-dragging) #hud .tc-skill.empty { display: none; }
body.touch.m2.m2-bind #hud .tc-skill.empty, body.touch.m2.skill-dragging #hud .tc-skill.empty { opacity: .75; }
/* version 3: the small buttons stood out on a third arc (auto at 8 o'clock ... sit above the top skill), which
   scattered them over the picture once the empty slots were gone and put "sit" on the minimap when the browser's
   bar is showing (about 330 px of height on a Note8). They stand in a block with the potions now, low and left of
   the skills: potions + sit in one column, auto / pick up / dash in the next. */
body.touch.m2 #hud .tc { width: 364px; }
body.touch.m2 #hud .tc-sit  { right: 267px; bottom: 114px; }
body.touch.m2 #hud .tc-auto { right: 318px; bottom: 9px; }
body.touch.m2 #hud .tc-pick { right: 318px; bottom: 57px; }
body.touch.m2 #hud .tc-dash { right: 318px; bottom: 105px; }
/* by the water with a rod (body.fish-ready, js/fishing.js): sit and pick up step aside there, and its four buttons
   kept the old two-row layout's places - on the outer arc's 6th and 7th skill. They take the block's free places. */
body.touch.m2 #hud .tc .fish-btn     { right: 258px; bottom: 114px; }
body.touch.m2 #hud .tc .fish-bait    { right: 318px; bottom: 57px; }
body.touch.m2 #hud .tc .fish-auto    { right: 322px; bottom: 180px; }
body.touch.m2 #hud .tc .fish-mapchip { right: 276px; bottom: 182px; }
/* version 4 (owner 2026-11-28, a picture: "ขยับไปทางขวาหน่อย"): with the outer arc's two low slots (s4, s5) empty -
   they are not drawn then - the block comes 64 px right, next to the inner arc (8 px from s0), and the cluster is that
   much narrower, so the chat strip and the 💬 follow it. js/m2_hud.js sync sets .m2-near; a skill put on s4 or s5 (or
   the skill window open, which shows the empty slots) puts the block back where the full arcs need it. */
body.touch.m2 #hud .tc.m2-near { width: 300px; }
body.touch.m2 #hud .tc.m2-near .tc-pot   { right: 200px; }
body.touch.m2 #hud .tc.m2-near .tc-sit   { right: 203px; }
body.touch.m2 #hud .tc.m2-near .tc-auto,
body.touch.m2 #hud .tc.m2-near .tc-pick,
body.touch.m2 #hud .tc.m2-near .tc-dash  { right: 254px; }
body.touch.m2 #hud .tc.m2-near .fish-btn     { right: 194px; }
body.touch.m2 #hud .tc.m2-near .fish-bait    { right: 254px; }
body.touch.m2 #hud .tc.m2-near .fish-auto    { right: 258px; }
body.touch.m2 #hud .tc.m2-near .fish-mapchip { right: 212px; }

/* ---- bottom middle: two chat lines; a tap opens the chat ---- */
.m2-chat, .m2-chat-x { display: none; }
body.touch.m2 #hud .m2-chat {
  /* between the stick's catch ring and the thumb buttons, wherever their own size puts them (js/m2_hud.js sync:
     --m2-joy-r, --m2-tc-w; fixed px sat on the HP potion at UI 80% or buttons 110%) */
  position: absolute; left: var(--m2-joy-r, 200px); right: calc(var(--m2-tc-w, 340px) + 2px); bottom: 16px; z-index: 11; height: 34px;
  display: flex; align-items: center; gap: 6px; padding: 2px 8px; box-sizing: border-box; overflow: hidden;
  background: rgba(8, 12, 24, .5); border: 1px solid rgba(217, 169, 62, .3); border-radius: 10px;
  pointer-events: auto; cursor: pointer; translate: var(--safe-l, 0) 0;
}
body.touch.m2 #hud .m2-chat-ico { flex: none; font-size: 14px; opacity: .85; }
body.touch.m2 #hud .m2-chat-log { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; }
body.touch.m2 #hud .m2-chat-log .chat-line {
  margin: 0; padding: 0; font-size: 10px; line-height: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: none; border: 0;
}
body.touch.m2 #hud .m2-chat-log .chat-line b, body.touch.m2 #hud .m2-chat-log .chat-line span { font-size: 10px; line-height: 15px; }
/* version 3: nothing said for a while - only the 💬 stays, at the thumb buttons' end (a tap still opens the chat) */
body.touch.m2 #hud .m2-chat.idle {
  left: auto; width: 34px; padding: 0; justify-content: center; border-radius: 50%; background: rgba(8, 12, 24, .35);
  /* version 4 (owner 2026-11-28, a picture with an arrow: "ขยับแชทไปทางซ้าย"): the folded 💬 waits at the strip's LEFT
     end, just past the stick, where the talk opens from - not at the thumb buttons, where on a notched phone it had
     landed on the auto button (it was placed from the right while the strip's translate moves it right by --safe-l;
     from the left the two agree) */
  left: var(--m2-joy-r, 200px); right: auto;
}
body.touch.m2 #hud .m2-chat.idle .m2-chat-log { display: none; }

/* the real chat: off the screen until the strip is tapped, then a sheet down the left side */
body.touch.m2:not(.m2-chat-open) #hud .chat-panel { display: none !important; }
body.touch.m2.m2-chat-open #hud .m2-chat { display: none; }
body.touch.m2.m2-chat-open #hud .chat-panel {
  display: flex !important; flex-direction: column;
  position: absolute !important; left: 0 !important; top: 0 !important; bottom: 0 !important; right: auto !important;
  width: 48% !important; max-width: 520px; height: auto !important; max-height: none !important;
  transform: none !important; translate: none !important; z-index: 40;
  padding-left: var(--safe-l, 0); box-sizing: border-box;
  background: rgba(8, 12, 24, .93); border-right: 2px solid rgba(217, 169, 62, .55);
}
body.touch.m2.m2-chat-open #hud .chat-panel .chat-tabs {
  flex: none; display: flex; flex-wrap: wrap; gap: 2px; height: auto !important; overflow: visible !important;
  padding: 4px 48px 4px 4px; box-sizing: border-box;
}
body.touch.m2.m2-chat-open #hud .chat-panel .chat-tabs > button {
  height: 32px; min-height: 32px; min-width: 0; padding: 0 9px; font-size: 12px;
}
body.touch.m2.m2-chat-open #hud .chat-panel .ui-chat-tools {
  position: absolute !important; top: 4px !important; right: 4px !important; left: auto !important; bottom: auto !important;
  width: auto !important; height: auto !important;
}
body.touch.m2.m2-chat-open #hud .chat-panel .ui-chat-tools .chat-say { width: 40px; height: 32px; min-height: 32px; }
body.touch.m2.m2-chat-open #hud .chat-panel .chat-log {
  flex: 1 1 auto; height: auto !important; max-height: none !important; min-height: 0; overflow-y: auto;
  padding-bottom: 54px;                           /* the message box rides over the sheet's foot: the last lines stay readable */
}
/* the "อัปเดต" tab's list (js/updates.js: 45vh, and a height copied from the log) takes the sheet's height too */
body.touch.m2.m2-chat-open #hud .chat-panel .chat-updates {
  flex: 1 1 auto; height: auto !important; max-height: none !important; min-height: 0; overflow-y: auto;
}
/* a whisper's own window (css/style.css .whisper-win, z 21, left edge) opened UNDER the sheet: beside it, on top */
body.touch.m2.m2-chat-open #hud .whisper-win {
  z-index: 44; left: calc(min(48%, 520px) + 54px) !important; right: auto !important;
}
body.touch.m2.m2-chat-open #hud .chat-panel .chat-hide,
body.touch.m2.m2-chat-open #hud .chat-panel .chat-grow { display: none !important; }
body.touch.m2.m2-chat-open #hud .m2-chat-x {
  display: flex; align-items: center; justify-content: center;
  position: absolute; top: 6px; left: calc(min(48%, 520px) + 6px); z-index: 41; width: 40px; height: 40px;
  font: 700 18px/1 sans-serif; color: #f4e6c4; border-radius: 50%; pointer-events: auto;
  background: rgba(14, 19, 36, .92); border: 1px solid rgba(217, 169, 62, .65);
}
/* the message box rides in the sheet's lower part */
body.touch.m2.m2-chat-open .chat-box {
  left: calc(min(24%, 260px)); bottom: 8px; width: calc(min(48%, 520px) - 16px); z-index: 42;
}

/* ---- ☰ the whole menu ---- */
body.touch.m2 #hud .m2-menu {
  position: absolute; inset: 0; z-index: 90; display: flex; flex-direction: column; gap: 8px;
  padding: 10px calc(14px + var(--safe-r, 0)) 10px calc(14px + var(--safe-l, 0)); box-sizing: border-box;
  background: rgba(8, 12, 24, .94); pointer-events: auto;
}
body.touch.m2 #hud .m2-menu.hidden { display: none; }
body.touch.m2 #hud .m2-menu-head { display: flex; align-items: center; gap: 12px; flex: none; }
body.touch.m2 #hud .m2-menu-title { font-size: 16px; color: #ffe293; }
body.touch.m2 #hud .m2-purse { flex: 1; font-size: 12px; color: #f4e6c4; opacity: .9; }
body.touch.m2 #hud .m2-x {
  width: 44px; height: 44px; font: 700 20px/1 sans-serif; color: #f4e6c4; border-radius: 50%;
  background: rgba(40, 52, 88, .9); border: 1px solid rgba(217, 169, 62, .65);
}
body.touch.m2 #hud .m2-grid {
  flex: 1; min-height: 0; overflow-y: auto; display: grid; gap: 8px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
}
body.touch.m2 #hud .m2-grid .m2-tile { width: auto; height: 66px; border-radius: 12px; }
body.touch.m2 #hud .m2-grid .m2-ico { width: 30px; height: 30px; font-size: 20px; }
body.touch.m2 #hud .m2-grid .m2-lbl { font-size: 11px; line-height: 13px; white-space: normal; text-align: center; }

/* ---- big windows: full screen ---- */
body.touch.m2 #hud .window.m2-sheet {
  position: absolute !important; left: 0 !important; top: 0 !important; right: 0 !important; bottom: 0 !important;
  width: auto !important; height: auto !important; max-width: none !important; max-height: none !important;
  transform: none !important; translate: none !important; margin: 0 !important;
  display: flex; flex-direction: column; box-sizing: border-box;
  padding-left: calc(var(--safe-l, 0px) + 4px); padding-right: calc(var(--safe-r, 0px) + 4px);
}
/* (not the gacha boxes: theirs is the hall picture, css/ui_gacha_cinematic.css) */
body.touch.m2 #hud .window.m2-sheet:not(.pxc-gacha) {
  background-image: linear-gradient(rgb(36, 51, 90), rgb(15, 22, 41)) !important;
}
body.touch.m2 #hud .window.m2-sheet.hidden { display: none !important; }
body.touch.m2 #hud .window.m2-sheet > .win-title { flex: none; min-height: 40px; display: flex; align-items: center; }
body.touch.m2 #hud .window.m2-sheet > .win-title .win-close { width: 44px; height: 40px; margin-left: auto; font-size: 18px; }
body.touch.m2 #hud .window.m2-sheet > .win-body {
  flex: 1 1 auto; min-height: 0; max-height: none !important; overflow: auto;
}
/* a side sheet (the skill window): left of the thumb buttons, which stay live for "tap a skill, then a button" */
body.touch.m2 #hud .window.m2-sheet.m2-side { right: calc(var(--m2-tc-w, 270px) + var(--safe-r, 0px)) !important; }
body.touch.m2 #hud #skillWindow.m2-sheet > .win-body { display: flex; flex-direction: column; }
body.touch.m2 #hud #skillWindow.m2-sheet .skill-list { flex: 1 1 auto; max-height: none; min-height: 0; }
/* while a full-screen window is up the thumbs and the strips step back */
body.touch.m2.m2-win-open #hud .touch-ui,
body.touch.m2.m2-win-open #hud .m2-bar,
body.touch.m2.m2-win-open #hud .m2-dockrow,
body.touch.m2.m2-win-open #hud .net-chips { visibility: hidden; }
/* ... the 💬 stays, at the sheet's lower left corner: a trade's window cannot be shut without calling the trade off,
   and the two must be able to talk (a red dot = somebody just spoke); the chat sheet (z 40) opens over the window */
body.touch.m2.m2-win-open #hud .m2-chat {
  z-index: 38; left: calc(6px + var(--safe-l, 0px)); right: auto; width: 34px; padding: 0; justify-content: center;
  border-radius: 50%; background: rgba(8, 12, 24, .82);
}
body.touch.m2.m2-win-open #hud .m2-chat .m2-chat-log { display: none; }
body.touch.m2.m2-win-open #hud .m2-chat:not(.idle)::after {
  content: ""; position: absolute; top: 0; right: 0; width: 9px; height: 9px; border-radius: 50%;
  background: #ff4d3d; border: 1px solid #2a0c08;
}
/* fallen with the chat sheet open: the "คุณสลบ!" card (css/style.css .death-panel, z 40 like the sheet, drawn
   earlier) lay half under it - over the sheet, its ✕ and the message box; the chat stays usable to ask for a revive */
body.touch.m2 #hud .death-panel { z-index: 45; }
/* a whisper's own window (css/style.css .whisper-win, z 21) stood behind every sheet: over them */
body.touch.m2 #hud .whisper-win { z-index: 44; }
/* ... but not "turn the phone" (js/mobile.js .rotate-note lives in .touch-ui: with a sheet open an upright phone
   showed the sheet squeezed instead of the note and its way out of an in-app browser) */
body.touch.m2.m2-win-open #hud .touch-ui .rotate-note { visibility: visible; }
/* a toast ("the bag is full", "level too low") answers a press made inside a sheet: over it, not under */
body.touch.m2 #hud .toast { z-index: 96; }

/* ---- the monster's HP plate keeps the game's own place (top centre). Version 2 put it one row down, under the
   five-button bar's line - the row of the news ticker, the duel bar and the travel chips, which then covered it.
   With three buttons in the bar it fits where the game draws it. ----
   Version 4 (owner 2026-11-28, his own phone: the plate lay on bag / quests / ☰ - a wide map dock or a big UI size
   puts the bar left of the screen's middle): the plate stands in the middle of the gap between the card and the
   bar and is never wider than it (js/m2_hud.js targetPlace: --m2-tgt-x / -w, and -y under a world boss's bar). */
body.touch.m2 #hud #targetPanel {
  left: var(--m2-tgt-x, 50%); top: var(--m2-tgt-y, 12px); max-width: var(--m2-tgt-w, 60%); box-sizing: border-box;
  transform: translateX(-50%);
}
body.touch.m2 #hud #targetPanel .tgt-name { overflow: hidden; text-overflow: ellipsis; }
body.touch.m2 #hud #targetPanel .tgt-hp { width: min(180px, calc(var(--m2-tgt-w, 220px) - 28px)); }

/* ---- the test server's gold chip (js/test_server.js, test server only): top centre sat on the icon bar and on
   every full-screen window's title, so it goes just above the chat strip ---- */
body.touch.m2 #tsChip { top: auto !important; bottom: calc(60px + var(--safe-b, 0px)) !important; }
body.touch.m2.m2-win-open #tsChip, body.touch.m2.m2-chat-open #tsChip { visibility: hidden; }

/* ---- version 6 (2026-11-29). A player's picture (Hamtokun, UI 100%, in the capital), the owner: "ทำไมอยู่สภาพนี้":
   the minimap's panel stood much wider than its picture - an empty navy block beside the map - because the head row
   (map name · coordinates · PK · CH n ▾ · ▲) is wider than the picture: css/ui_hud_usability.css makes the channel
   chip and the fold arrow finger targets (44 x 32 and 40 screen px), the fold arrow's room was kept twice (panel and
   head), and a capital's picture is near square, so at 100 px high it is far narrower than that row.
   The player's own ask: "อยากให้กดย่อแล้ว ปุ่มต่างๆ และแผนที่ ย่อเข้าทางขวาไปเหมือน ui อันเก่า จะได้เห็นชื่อกับเลเวลของ
   มอนเต็มๆ". So: the chip and the arrow are smaller here (still tappable), open the head no longer sets the panel's
   width (PK / CH wrap to a second line), and folded the head keeps only PK · CH · ▼ - the dock is then narrow at the
   right edge, the top bar follows it right (js/m2_hud.js --m2-dock) and the small tiles stand under both. ---- */
body.touch.m2 #hud .mm-dock { --ui-mm-base: .7; }
body.touch.m2 #hud .mm-head .ch-chip {
  min-width: calc(34px * var(--ui-inv, 1) / var(--ui-mm-base, 1)); min-height: calc(22px * var(--ui-inv, 1) / var(--ui-mm-base, 1));
  font-size: calc(10px * var(--ui-inv, 1) / var(--ui-mm-base, 1)); padding: 0 calc(5px / var(--ui-mm-base, 1)); margin-right: 0;
}
body.touch.m2 #hud .mini-map .mm-toggle {
  width: calc(26px * var(--ui-inv, 1) / var(--ui-mm-base, 1)); height: calc(22px * var(--ui-inv, 1) / var(--ui-mm-base, 1));
}
/* the fold arrow stands in the panel's corner (absolute): its room is kept once, by the head, not twice */
body.touch.m2 #hud .mini-map { padding-right: 6px; }
body.touch.m2 #hud .mm-head { padding-right: calc(30px * var(--ui-inv, 1) / var(--ui-mm-base, 1)); gap: 6px; }
/* open: two lines - the map's name (beside the fold arrow), then coordinates · PK · CH. The head adds no width of
   its own (width 0 / min-width 100%): the panel is as wide as its picture, at least the room those two lines need
   (110 screen px at UI 100%), and a narrower picture (a capital's near-square one) is centred in it */
body.touch.m2 #hud .mini-map:not(.folded) { min-width: calc(157px * var(--ui-inv, 1)); box-sizing: border-box; }
body.touch.m2 #hud .mini-map:not(.folded) canvas { margin-left: auto; margin-right: auto; }
body.touch.m2 #hud .mini-map:not(.folded) .mm-head {
  width: 0; min-width: 100%; box-sizing: border-box; padding-right: 0; flex-wrap: wrap; row-gap: 3px; column-gap: 4px;
  align-items: center;
}
body.touch.m2 #hud .mini-map:not(.folded) .mm-head .mm-title {
  order: 0; flex: 0 1 auto; max-width: calc(100% - 30px * var(--ui-inv, 1) / var(--ui-mm-base, 1));
  min-height: calc(22px * var(--ui-inv, 1) / var(--ui-mm-base, 1)); display: flex; align-items: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
body.touch.m2 #hud .mini-map:not(.folded) .mm-head::before { content: ""; order: 1; flex: 0 0 100%; height: 0; }
body.touch.m2 #hud .mini-map:not(.folded) .mm-head .mm-coords { order: 2; }
body.touch.m2 #hud .mini-map:not(.folded) .mm-head .pk-chip,
body.touch.m2 #hud .mini-map:not(.folded) .mm-head .ch-chip { order: 3; }
body.touch.m2 #hud .mini-map:not(.folded) .mm-head .pk-chip { margin-left: auto; }
body.touch.m2 #hud .mini-map:not(.folded) .mm-head .pk-chip.hidden + .ch-chip { margin-left: auto; }
/* folded, the small tiles stand under the top bar too (js/m2_hud.js): the island's "จัดเกาะ" goes below them */
body.touch.m2 #hud.m2-mmfold #islandEditBtn { top: calc(var(--m2-dock-b, 52px) + 36px) !important; }
/* open minimap, but the row under it would reach the thumb cluster's top skills (a short screen at a big UI size):
   js/m2_hud.js sets .m2-rowleft and the row stands under the top bar, left of the minimap; จัดเกาะ goes below it */
body.touch.m2 #hud.m2-rowleft .m2-dockrow { top: 50px; right: var(--m2-dock, 170px); max-width: none; }
body.touch.m2 #hud.m2-rowleft #islandEditBtn { top: 88px !important; }
/* folded: only PK · CH · ▼ */
body.touch.m2 #hud .mini-map.folded .mm-title,
body.touch.m2 #hud .mini-map.folded .mm-coords { display: none !important; }
body.touch.m2 #hud .mini-map.folded .mm-head .pk-chip + .ch-chip { margin-left: 4px; }
