/* Character status: one readable panel across the classic and wide layouts. */
#hud {
  box-sizing: border-box;
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center;
  gap: 6px !important;
  left: 8px !important;
  right: auto !important;
  width: min(850px, calc(100vw - 16px)) !important;
  max-width: none !important;
  padding: 6px 8px !important;
  border: 1px solid #b79756 !important;
  border-top: 0 !important;
  border-radius: 0 0 10px 10px;
  background: linear-gradient(180deg, #353022f5, #171710f2 72%, #10130ff2) !important;
  box-shadow: inset 0 1px #fae2a36b, inset 0 -1px #070806, 0 5px 16px #000b !important;
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  color: #f3e8cc;
  font-variant-numeric: tabular-nums;
}

body.u20 #hud {
  left: 188px !important;
  width: min(850px, calc(100vw - 430px)) !important;
  max-width: none !important;
  padding: 6px 8px !important;
  background: linear-gradient(180deg, #353022f5, #171710f2 72%, #10130ff2) !important;
  border: 1px solid #b79756 !important;
  border-top: 0 !important;
  box-shadow: inset 0 1px #fae2a36b, inset 0 -1px #070806, 0 5px 16px #000b !important;
  gap: 6px !important;
}

#hud .jxs {
  flex: 0 0 auto;
  height: 27px;
  gap: 5px;
  font-size: 11px;
  color: #d2c7a7;
}
#hud .jxs b {
  box-sizing: border-box;
  min-width: 32px;
  height: 24px;
  padding: 0 6px;
  line-height: 22px;
  border: 1px solid #a78a50;
  border-radius: 5px;
  background: linear-gradient(#514027, #211b13);
  box-shadow: inset 0 1px #ead09277, 0 1px 3px #0009;
  color: #ffe6a2;
  font-size: 12px;
  text-shadow: 0 1px #000;
}
#hud .jxs:first-child b {
  border-color: #e0b75d;
  background: linear-gradient(#80612a, #3c2b15);
  color: #fff4c5;
}

#hudAvatar {
  flex: 0 1 174px;
  min-width: 132px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 7px 2px 3px;
  border: 1px solid #806b3c;
  border-radius: 18px;
  background: linear-gradient(110deg, #443720eF, #1c1b15f5 72%);
  box-shadow: inset 0 1px #f7dda044, 0 1px 3px #0009;
  overflow: hidden;
}
#hudAvatarPortrait {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border: 1px solid #d2ad58;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #685132, #17140e 72%);
  background-position: center 24%;
  background-size: cover;
  box-shadow: 0 0 0 2px #100e0b, 0 0 8px #d3a94b66;
}
#hudAvatarInfo {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.1;
}
#hudAvatarInfo b, #hudAvatarInfo small { display: block; max-width: 100%; }
#hudAvatarName, #hudAvatarFaction {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#hudAvatarName { color: #ffe5a0; font-size: 10.5px; line-height: 12px; text-shadow: 0 1px 2px #000; }
#hudAvatarFaction { color: #c7b98f; font-size: 9px; line-height: 11px; }
#hudAvatar .jxs { flex: 0 0 auto; gap: 3px; margin: 0; font-size: 9px; white-space: nowrap; }
#hudAvatar .jxs b {
  min-width: 28px;
  height: 22px;
  padding: 0 4px;
  line-height: 20px;
  border-color: #e0b75d;
  background: linear-gradient(#80612a, #3c2b15);
  color: #fff4c5;
}

#hud .bar,
body.u20 #hud .bar {
  box-sizing: border-box;
  flex: 1 1 0;
  min-width: 0;
  max-width: none;
  height: 27px !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden;
  border: 1px solid #6e6346 !important;
  border-radius: 5px !important;
  background: linear-gradient(#080b0d, #171914) !important;
  box-shadow: inset 0 1px 3px #000, 0 1px #ebd39b33 !important;
}
#hud .bar i {
  top: 1px !important;
  bottom: 1px !important;
  left: 1px !important;
  right: auto !important;
  border-radius: 3px !important;
  transition: width .2s ease-out;
}
#hud .bar.hp i {
  background: linear-gradient(#ef7367 0%, #be342f 43%, #7a1c22 100%) !important;
  box-shadow: inset 0 1px #ffc0a799, 0 0 8px #e83b36aa !important;
}
#hud .bar.mp i {
  background: linear-gradient(#83c5fa 0%, #337fc4 43%, #17497e 100%) !important;
  box-shadow: inset 0 1px #d6ecff99, 0 0 8px #388bffaa !important;
}
#hud .bar.xp i {
  background: linear-gradient(#ffe28b 0%, #d4a52e 43%, #8c6117 100%) !important;
  box-shadow: inset 0 1px #fff1b199, 0 0 8px #e4b72faa !important;
}
#hud .bar em,
#hud .bar span {
  position: absolute;
  z-index: 1;
  top: 0;
  bottom: 0;
  height: auto;
  line-height: 25px;
  font-style: normal;
  font-size: 10.5px;
  font-weight: 700;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
  pointer-events: none;
}
#hud .bar em {
  left: 7px;
  right: auto;
  color: #fff0d4;
  opacity: .95;
}
#hud .bar span {
  left: 0;
  right: 7px;
  text-align: right;
  color: #fff;
  letter-spacing: 0;
}
#hud .bar.xp em { color: #fff0ba; }

#hud #u20rank {
  flex: 0 0 auto;
  height: 24px;
  padding: 0 8px;
  margin: 0;
  border-radius: 5px;
  background: linear-gradient(#745927, #392811);
  box-shadow: inset 0 1px #ffe0a266;
  font-size: 11px;
}
#hud #mysqlWorldStatus {
  display: none !important;
}
#hud #mainSk { display: none !important; }

/* Keep the six requested readouts on one compact line; bars take leftover width. */
#hud .bar.hp, #hud .bar.mp { flex-basis: 118px; }
#hud .bar.xp { flex-basis: 104px; }
#hud .jxs[title] { gap: 4px; }

/* Keep the floating server clock clear of the status HUD instead of painting over its right-side readouts. */
#serverClock.floating {
  left: auto;
  right: 8px;
  transform: none;
}
@media (max-width: 1100px) {
  #serverClock.floating { top: 50px; right: 8px; }
}

@media (max-width: 900px) {
  #hudAvatar { display: contents; }
  #hudAvatarPortrait, #hudAvatarInfo { display: none !important; }
  #hudAvatar .jxs { flex: 0 0 auto; }
  #hud .bar em { display: none; }
  #hud .bar span { right: 0; text-align: center; }
}
body.u2s #hud .bar em { display: none; }
body.u2s #hud .bar span { right: 0; text-align: center; }
body.u2s #hud .jxs[title] > span { display: none; }

@media (max-width: 700px) {
  #hud, body.u20 #hud {
    left: 4px !important;
    width: min(560px, calc(100vw - 8px)) !important;
    padding: 5px 6px !important;
    gap: 4px !important;
  }
  #hud .bar, body.u20 #hud .bar {
    flex: 1 1 0;
    min-width: 0;
    height: 24px !important;
  }
  #hud .bar em, #hud .bar span { line-height: 22px; font-size: 10px; }
  #hud .jxs { height: 24px; }
  body.u2s #hud {
    left: 4px !important;
    width: min(52vw, 460px) !important;
  }
}

@media (max-width: 440px) {
  #hud .bar em { display: none; }
  #hud .bar span { right: 0; text-align: center; font-size: 9px; }
  #hud .jxs[title] > span { display: none; }
  #hud .jxs b { min-width: 27px; padding: 0 3px; }
  #hud #u20rank { padding: 0 4px; }
}

/* Gọn hàng thông tin trên điện thoại dọc: không để các nút và số dư rớt
   thành nhiều dòng làm đẩy thanh trạng thái và sân chơi xuống thấp. */
@media (max-width: 560px), (pointer: coarse) and (orientation: portrait) {
  #top {
    min-height: 46px !important;
    height: auto !important;
    flex-wrap: nowrap !important;
    gap: 4px !important;
    padding: calc(4px + var(--safe-t, 0px)) 6px 4px !important;
    overflow: hidden;
  }
  #top .lvbox { width: 34px !important; height: 34px !important; }
  #top .lvbox #lv { min-width: 19px; height: 19px; font-size: 10px; }
  #top .topmid { flex: 1 1 44px; min-width: 0; overflow: hidden; }
  #top .topmid .row { display: block; margin: 0; font-size: 10px; line-height: 12px; }
  #top #heroName { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
  #top #stageLbl, #top #serverClock { display: none !important; }
  #shopQuickActions { flex: none; gap: 2px; margin: 0 !important; }
  #shopQuickActions button, #shopQuickActions #giftBtn,
  #shopQuickActions #ktcBtn, #shopQuickActions #marketBtn {
    width: 34px !important; min-width: 34px !important;
    height: 34px !important; min-height: 34px !important;
    padding: 1px !important; border-radius: 50% !important;
  }
  #shopQuickActions button > span { font-size: 14px; line-height: 15px; }
  #shopQuickActions button > small { display: none !important; }
  #top .gold { flex: none; gap: 3px; padding: 1px 4px; font-size: 10px; white-space: nowrap; }
  #top .gold .coin { width: 10px; height: 8px; }
  #top .gold .knbi { width: 13px; height: 13px; margin-left: 1px; }
  #top #gold, #top #knbTop { font-size: 10px; }
  #top #actBtn, #top #compactBtn { flex: none; width: 28px; height: 28px; line-height: 26px; font-size: 13px; }
}

@media (max-width: 400px) {
  #top .topmid { display: none !important; }
  #top { gap: 3px !important; padding-left: 4px !important; padding-right: 4px !important; }
  #shopQuickActions button, #shopQuickActions #giftBtn,
  #shopQuickActions #ktcBtn, #shopQuickActions #marketBtn {
    width: 31px !important; min-width: 31px !important;
    height: 31px !important; min-height: 31px !important;
  }
}

/* Portrait mobile HUD: a quiet control strip followed by one compact status row. */
@media (max-width: 560px), (pointer: coarse) and (orientation: portrait) {
  #top {
    display: grid !important;
    grid-template-columns: 34px minmax(36px, 1fr) auto minmax(66px, auto) 29px 29px !important;
    grid-template-rows: 34px !important;
    align-items: center !important;
    gap: 4px !important;
    min-height: 44px !important;
    padding: calc(5px + var(--safe-t, 0px)) 6px 5px !important;
    overflow: hidden !important;
    background: linear-gradient(180deg, #25271f, #121611 78%, #0d100d) !important;
    border-bottom: 1px solid #8d7441 !important;
    box-shadow: 0 2px 8px #0009, inset 0 1px #f1d58a2b !important;
  }
  #top .lvbox {
    grid-column: 1;
    width: 34px !important;
    height: 34px !important;
    border-radius: 6px !important;
  }
  #top .topmid {
    display: block !important;
    grid-column: 2;
    min-width: 0 !important;
    padding-left: 2px;
  }
  #top .topmid .row { display: block !important; margin: 0 !important; line-height: 1.1; }
  #top #heroName {
    display: block !important;
    overflow: hidden;
    color: #f4dfa5;
    font-size: 11px !important;
    line-height: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #top #stageLbl, #top #serverClock { display: none !important; }
  #shopQuickActions {
    grid-column: 3;
    display: flex !important;
    align-items: center;
    gap: 3px !important;
    margin: 0 !important;
  }
  #shopQuickActions button,
  #shopQuickActions #giftBtn,
  #shopQuickActions #ktcBtn,
  #shopQuickActions #marketBtn {
    width: 30px !important;
    min-width: 30px !important;
    height: 30px !important;
    min-height: 30px !important;
    padding: 0 !important;
    border: 1px solid #927843 !important;
    border-radius: 50% !important;
    box-shadow: inset 0 1px #f6df9c33, 0 1px 3px #0009 !important;
  }
  #shopQuickActions button > span { font-size: 13px !important; line-height: 28px; }
  #shopQuickActions button > small { display: none !important; }
  #top .gold {
    grid-column: 4;
    justify-content: center;
    min-width: 0;
    gap: 3px !important;
    padding: 2px 5px !important;
    border-color: #625638;
    border-radius: 12px;
    background: #090c0bde;
    box-shadow: inset 0 1px 3px #000;
    font-size: 9px !important;
    white-space: nowrap;
  }
  #top .gold .coin { width: 9px; height: 8px; }
  #top .gold .knbi { width: 12px; height: 12px; margin-left: 0 !important; }
  #top #gold, #top #knbTop { font-size: 9px !important; }
  #top #actBtn, #top #compactBtn {
    width: 29px !important;
    height: 29px !important;
    padding: 0 !important;
    line-height: 27px !important;
    font-size: 13px !important;
  }
  #top #actBtn { grid-column: 5; }
  #top #compactBtn { grid-column: 6; }

  #hud, body.u20 #hud {
    display: grid !important;
    grid-template-columns: 36px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.65fr) 42px 54px !important;
    align-items: center !important;
    gap: 4px !important;
    left: 5px !important;
    right: 5px !important;
    width: auto !important;
    max-width: none !important;
    padding: 5px !important;
    border: 1px solid #8d7441 !important;
    border-top: 0 !important;
    border-radius: 0 0 9px 9px !important;
    background: linear-gradient(180deg, #25271ff5, #111510f5 88%) !important;
    box-shadow: inset 0 1px #f1d58a2b, 0 4px 10px #0009 !important;
  }
  #hudAvatar { display: contents !important; }
  #hudAvatarPortrait, #hudAvatarInfo { display: none !important; }
  #hudAvatar .jxs {
    grid-column: 1;
    justify-content: center;
    height: 25px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 1px solid #8d7441;
    border-radius: 5px;
    background: linear-gradient(#574423, #21190e);
  }
  #hudAvatar .jxs > span { display: none !important; }
  #hudAvatar .jxs b {
    min-width: 0 !important;
    height: auto !important;
    padding: 0 3px !important;
    border: 0 !important;
    background: none !important;
    box-shadow: none !important;
    font-size: 10px !important;
    line-height: 1 !important;
  }
  #hud .bar, body.u20 #hud .bar {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 25px !important;
    border: 1px solid #685936 !important;
    border-radius: 5px !important;
  }
  #hud .bar.hp { grid-column: 2; }
  #hud .bar.mp { grid-column: 3; }
  #hud .bar.xp { grid-column: 4; }
  #hud .bar em { display: none !important; }
  #hud .bar span {
    right: 2px !important;
    left: 2px !important;
    overflow: hidden;
    font-size: 8px !important;
    line-height: 23px !important;
    text-align: center !important;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #hud .jxs[title] {
    grid-column: 5;
    justify-content: center;
    gap: 0 !important;
    height: 25px !important;
    margin: 0 !important;
    padding: 0 2px !important;
    border: 1px solid #625638;
    border-radius: 5px;
    background: #0b0e0bdc;
    font-size: 9px !important;
  }
  #hud .jxs[title] > span { display: none !important; }
  #hud .jxs[title] b {
    min-width: 0 !important;
    height: auto !important;
    padding: 0 !important;
    border: 0 !important;
    background: none !important;
    box-shadow: none !important;
    font-size: 9px !important;
    line-height: 1 !important;
  }
  #hud #u20rank {
    grid-column: 6;
    justify-self: stretch;
    height: 25px !important;
    min-width: 0;
    padding: 0 4px !important;
    border: 1px solid #9a7b3d;
    border-radius: 5px;
    font-size: 9px !important;
    line-height: 23px;
    white-space: nowrap;
  }
  #hud #mainSk { display: none !important; }
}

@media (max-width: 380px) {
  #top, body.u20 #top {
    grid-template-columns: 32px minmax(28px, 1fr) auto minmax(58px, auto) 27px 27px !important;
    gap: 3px !important;
    padding-right: 4px !important;
    padding-left: 4px !important;
  }
  #top .lvbox { width: 32px !important; height: 32px !important; }
  #shopQuickActions button,
  #shopQuickActions #giftBtn,
  #shopQuickActions #ktcBtn,
  #shopQuickActions #marketBtn { width: 27px !important; min-width: 27px !important; height: 27px !important; min-height: 27px !important; }
  #shopQuickActions button > span { line-height: 25px; font-size: 12px !important; }
  #top #actBtn, #top #compactBtn { width: 27px !important; height: 27px !important; line-height: 25px !important; }
  #hud, body.u20 #hud {
    grid-template-columns: 32px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.45fr) 37px 49px !important;
    gap: 3px !important;
    left: 3px !important;
    right: 3px !important;
    padding: 4px !important;
  }
  #hud .bar, body.u20 #hud .bar { height: 23px !important; }
  #hud .bar span { font-size: 7.5px !important; line-height: 21px !important; }
  #hud #u20rank { height: 23px !important; line-height: 21px; font-size: 8px !important; }
}

/* PC HUD: portrait with compact, stacked character bars. Phone rules above remain unchanged. */
@media (min-width: 901px) {
  #hud, body.u20 #hud {
    display: grid !important;
    grid-template-columns: 44px minmax(128px, 1fr) minmax(128px, 1fr) minmax(190px, 1.35fr) 52px !important;
    grid-template-rows: 30px !important;
    align-items: center !important;
    gap: 1px 5px !important;
    left: 50% !important;
    right: auto !important;
    top: 6px !important;
    width: min(760px, calc(100vw - 32px)) !important;
    min-width: 0 !important;
    max-width: 760px !important;
    padding: 5px 8px !important;
    box-sizing: border-box !important;
    border: 1px solid #94743b !important;
    border-radius: 13px !important;
    background: linear-gradient(180deg, rgba(48, 42, 29, .97), rgba(12, 15, 12, .96)) !important;
    box-shadow: 0 5px 18px #000b, inset 0 1px #fff3, 0 0 0 1px #0008 !important;
    transform: translateX(-50%) !important;
  }
  #hudAvatar, body.u20 #hudAvatar {
    grid-column: 1 !important;
    grid-row: 1 !important;
    position: relative !important;
    display: block !important;
    width: 40px !important;
    height: 30px !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }
  #hudAvatarPortrait, body.u20 #hudAvatarPortrait {
    position: absolute !important;
    top: 0 !important;
    left: 8px !important;
    display: block !important;
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
    border: 2px solid #e0bd69 !important;
    border-radius: 50% !important;
    background-color: #17150f !important;
    background-size: cover !important;
    background-position: center !important;
    box-shadow: 0 0 0 2px #17130c, 0 2px 9px #000c, 0 0 8px #e4c26355 !important;
  }
  #hudAvatarInfo, body.u20 #hudAvatarInfo {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    display: none !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 0 !important;
    overflow: hidden !important;
    text-align: center !important;
    line-height: 1.15 !important;
    text-shadow: 1px 1px 2px #000, 0 0 4px #000 !important;
  }
  #hudAvatarName, body.u20 #hudAvatarName {
    display: block !important;
    max-width: 100% !important;
    overflow: hidden !important;
    color: #f3d77f !important;
    font-size: 7px !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
  #hudAvatarFaction, body.u20 #hudAvatarFaction {
    display: block !important;
    max-width: 100% !important;
    overflow: hidden !important;
    color: #ddd0ae !important;
    font-size: 6px !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
  #hudAvatar .jxs, body.u20 #hudAvatar .jxs {
    position: absolute !important;
    z-index: 2 !important;
    left: 0 !important;
    bottom: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 20px !important;
    height: 16px !important;
    min-width: 20px !important;
    margin: 0 !important;
    padding: 0 2px !important;
    border: 1px solid #d5b15b !important;
    border-radius: 5px !important;
    background: linear-gradient(#42523b, #182016) !important;
    box-shadow: 0 1px 4px #000c !important;
  }
  #hudAvatar .jxs > span { display: none !important; }
  #hudAvatar .jxs b {
    min-width: 0 !important;
    height: auto !important;
    padding: 0 !important;
    border: 0 !important;
    background: none !important;
    box-shadow: none !important;
    color: #fff1bd !important;
    font-size: 8px !important;
    line-height: 1 !important;
  }
  #hud .bar, body.u20 #hud .bar {
    position: relative !important;
    grid-column: 2 !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 24px !important;
    margin: 0 !important;
    overflow: hidden !important;
    border: 1px solid #806b3d !important;
    border-radius: 10px !important;
    box-shadow: inset 0 1px 3px #000c, 0 1px 2px #0008 !important;
  }
  #hud .bar.hp { grid-column: 2 !important; grid-row: 1 !important; }
  #hud .bar.mp { grid-column: 3 !important; grid-row: 1 !important; }
  #hud .bar.xp { grid-column: 4 !important; grid-row: 1 !important; }
  #hud .bar i { border-radius: inherit !important; }
  #hud .bar::before {
    position: absolute;
    z-index: 1;
    left: 7px;
    top: 0;
    color: #fff4d2;
    font-size: 7px;
    font-weight: 700;
    line-height: 22px;
    letter-spacing: .04em;
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
  }
  #hud .bar.hp::before { content: "SINH LỰC"; }
  #hud .bar.mp::before { content: "NỘI LỰC"; }
  #hud .bar.xp::before { content: "KINH NGHIỆM"; }
  #hud .bar span {
    z-index: 2 !important;
    left: 54px !important;
    right: 4px !important;
    overflow: hidden !important;
    color: #fff9e8 !important;
    font-size: 9px !important;
    font-weight: 700 !important;
    line-height: 22px !important;
    text-align: right !important;
    text-overflow: ellipsis !important;
    text-shadow: 1px 1px 2px #000 !important;
    white-space: nowrap !important;
  }
  #hud .jxs[title], body.u20 #hud .jxs[title] {
    grid-column: 3 !important;
    grid-row: 1 !important;
    display: none !important;
    align-self: stretch !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
    height: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 3px !important;
    border: 1px solid #806b3d !important;
    border-radius: 9px !important;
    background: linear-gradient(#24271f, #11140f) !important;
    color: #e8d49b !important;
    font-size: 10px !important;
    box-shadow: inset 0 1px #fff1 !important;
  }
  #hud .jxs[title] > span { display: inline !important; }
  #hud .jxs[title] b {
    min-width: 0 !important;
    height: auto !important;
    padding: 0 !important;
    border: 0 !important;
    background: none !important;
    box-shadow: none !important;
    color: #fff0bd !important;
    font-size: 11px !important;
  }
  #hud #u20rank {
    grid-column: 5 !important;
    grid-row: 1 !important;
    justify-self: stretch !important;
    align-self: stretch !important;
    height: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 4px !important;
    border: 1px solid #b18a43 !important;
    border-radius: 9px !important;
    background: linear-gradient(#8b6b2e, #493316) !important;
    color: #ffe49a !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    line-height: 22px !important;
    white-space: nowrap !important;
  }
  #hud #mainSk { display: none !important; }
}

/* Final PC override: use a single flex row so the dynamic rank button cannot
   create an extra grid column or collapse the XP bar under a narrow viewport. */
@media (min-width: 901px) {
  #hud, body.u20 #hud {
    display: flex !important;
    flex-flow: row nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 8px !important;
    left: 50% !important;
    right: auto !important;
    top: 6px !important;
    width: min(760px, calc(100vw - 32px)) !important;
    min-width: 0 !important;
    max-width: 760px !important;
    min-height: 48px !important;
    padding: 5px 9px !important;
    transform: translateX(-50%) !important;
  }
  #hudAvatar, body.u20 #hudAvatar {
    position: relative !important;
    display: block !important;
    flex: 0 0 42px !important;
    width: 42px !important;
    height: 34px !important;
    grid-column: auto !important;
    grid-row: auto !important;
  }
  #hudAvatarPortrait, body.u20 #hudAvatarPortrait {
    top: 0 !important;
    left: 5px !important;
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
  }
  #hudAvatar .jxs, body.u20 #hudAvatar .jxs {
    left: -3px !important;
    bottom: -2px !important;
    width: 21px !important;
    height: 16px !important;
    min-width: 21px !important;
  }
  #hud .bar, body.u20 #hud .bar {
    display: block !important;
    flex: 1 1 0 !important;
    width: auto !important;
    min-width: 0 !important;
    height: 25px !important;
    grid-column: auto !important;
    grid-row: auto !important;
  }
  #hud .bar.hp { flex: 1 1 120px !important; }
  #hud .bar.mp { flex: 1 1 120px !important; }
  #hud .bar.xp { flex: 1.5 1 260px !important; min-width: 240px !important; }
  #hud .bar.hp::before { content: "SINH LỰC" !important; font-size: 8px !important; line-height: 23px !important; }
  #hud .bar.mp::before { content: "NỘI LỰC" !important; font-size: 8px !important; line-height: 23px !important; }
  #hud .bar.xp::before { content: "EXP" !important; left: 8px !important; font-size: 8px !important; line-height: 23px !important; }
  #hud .bar.hp span { left: 54px !important; line-height: 23px !important; font-size: 9px !important; }
  #hud .bar.mp span { left: 54px !important; line-height: 23px !important; font-size: 9px !important; }
  #hud .bar.xp span { left: 34px !important; line-height: 23px !important; font-size: 8px !important; }
  #hud .jxs[title], body.u20 #hud .jxs[title] { display: none !important; }
  #hud #u20rank {
    display: inline-flex;
    flex: 0 0 52px !important;
    align-items: center !important;
    justify-content: center !important;
    width: 52px !important;
    height: 25px !important;
    grid-column: auto !important;
    grid-row: auto !important;
    padding: 0 4px !important;
    line-height: 23px !important;
  }
  #hud #mainSk, #hud #mysqlWorldStatus { display: none !important; }
  /* Rank is injected inside the old power wrapper; flatten that wrapper so
     Rank becomes the final flex item while power itself stays hidden. */
  #hud .jxs[title], body.u20 #hud .jxs[title] { display: contents !important; }
  #hud .jxs[title] > span, #hud .jxs[title] > #pwS { display: none !important; }
  #hud #u20rank {
    display: inline-flex;
    position: relative !important;
    z-index: 3 !important;
    flex: 0 0 56px !important;
    width: 56px !important;
    min-width: 56px !important;
    margin-left: 0 !important;
  }
  /* Leave room on the right for the reward, KTC and market shortcuts. */
  #hud, body.u20 #hud {
    left: calc((100vw - 192px) / 2) !important;
    width: min(760px, calc(100vw - 192px)) !important;
    max-width: calc(100vw - 192px) !important;
  }
}

/* Responsive HUD below desktop width. Flatten the power wrapper here too so
   the dynamically injected Rank remains visible on every screen size. */
@media (max-width: 900px) {
  #hud .jxs[title], body.u20 #hud .jxs[title] { display: contents !important; }
  #hud .jxs[title] > span, #hud .jxs[title] > #pwS { display: none !important; }
  #hud #u20rank {
    display: inline-flex;
    position: relative !important;
    z-index: 3 !important;
    flex: 0 0 46px !important;
    width: 46px !important;
    min-width: 46px !important;
    margin: 0 !important;
  }
  #hud .bar { flex: 1 1 0 !important; min-width: 0 !important; }
  #hud .bar.xp { min-width: 0 !important; }
}

@media (min-width: 561px) and (max-width: 900px) and (orientation: landscape) {
  #hud, body.u20 #hud {
    left: calc((100vw - 176px) / 2) !important;
    right: auto !important;
    width: min(760px, calc(100vw - 192px)) !important;
    max-width: calc(100vw - 192px) !important;
    padding: 4px !important;
    gap: 4px !important;
    transform: translateX(-50%) !important;
  }
  #hud .bar.xp { flex-basis: 120px !important; }
  #hud #u20rank { flex-basis: 44px !important; width: 44px !important; min-width: 44px !important; }
}

@media (max-width: 560px), (pointer: coarse) and (orientation: portrait) {
  #hud, body.u20 #hud {
    grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.45fr) 46px !important;
    grid-template-rows: 28px !important;
    gap: 3px !important;
    left: 4px !important;
    right: 4px !important;
    width: auto !important;
    max-width: none !important;
    min-height: 0 !important;
    padding: 4px !important;
    transform: none !important;
  }
  #hud .bar.hp { grid-column: 2 !important; grid-row: 1 !important; }
  #hud .bar.mp { grid-column: 3 !important; grid-row: 1 !important; }
  #hud .bar.xp { grid-column: 4 !important; grid-row: 1 !important; }
  #hud #u20rank {
    grid-column: 5 !important;
    grid-row: 1 !important;
    justify-self: stretch !important;
    align-self: center !important;
    flex: none !important;
    width: 46px !important;
    min-width: 0 !important;
    height: 23px !important;
    padding: 0 2px !important;
    font-size: 8px !important;
    line-height: 21px !important;
  }
}
