/* v164 — Top HUD cleanup + real opponent chat. Loaded last on purpose. */
body.chat-hud-v164{--v164-gold:#f2bd39;--v164-navy:#06233b;--v164-navy2:#0a3655;--v164-cyan:#40dbe9}

/* ---------- TOP HUD: one hierarchy, no stacked ticker/badge ---------- */
body.chat-hud-v164 #marketTicker,
body.chat-hud-v164 #onlineBadge{display:none!important}
body.chat-hud-v164 .classic-top-center{
  position:fixed!important;top:9px!important;left:50%!important;right:auto!important;
  transform:translateX(-50%)!important;z-index:72!important;width:auto!important;
  display:flex!important;flex-direction:column!important;align-items:center!important;justify-content:flex-start!important;
  gap:7px!important;isolation:isolate;pointer-events:none!important
}
body.chat-hud-v164 .classic-top-center>*{pointer-events:auto!important}
body.chat-hud-v164 .classic-top-center .round-chip{
  position:static!important;inset:auto!important;transform:none!important;margin:0!important;
  min-width:170px!important;max-width:230px!important;height:auto!important;padding:9px 20px!important;
  font-size:14px!important;line-height:1.15!important;text-align:center!important;white-space:nowrap!important;
  border:2px solid #fff0a1!important;border-radius:13px!important;
  background:linear-gradient(180deg,#ffec91,#f3bc31 62%,#d9900b)!important;
  color:#3d2606!important;box-shadow:0 5px 0 #74470a,0 9px 18px #00182c66!important
}
body.chat-hud-v164 .classic-stage-bar{
  position:static!important;inset:auto!important;transform:none!important;margin:0!important;
  width:auto!important;max-width:330px!important;min-height:27px!important;padding:3px!important;
  display:flex!important;align-items:center!important;justify-content:center!important;gap:3px!important;overflow:hidden!important;
  border:1px solid #d8aa3a!important;border-radius:10px!important;background:#062641f5!important;
  box-shadow:0 3px 0 #4f340d,0 7px 14px #00182b55!important;white-space:nowrap!important
}
body.chat-hud-v164 .classic-stage-bar b,
body.chat-hud-v164 .classic-stage-bar span{
  position:static!important;margin:0!important;min-width:0!important;padding:4px 8px!important;
  font-size:9px!important;line-height:1.15!important;border-radius:7px!important;overflow:hidden!important;text-overflow:ellipsis!important;white-space:nowrap!important
}
body.chat-hud-v164 .classic-stage-bar b{max-width:145px!important}

/* Old lightweight chat surfaces are replaced by one real chat panel. */
body.chat-hud-v164 .classic-chat-shell,
body.chat-hud-v164 #emoteBtn,
body.chat-hud-v164 #emoteMenu,
body.chat-hud-v164 #chatRail{display:none!important}

/* ---------- CHAT PANEL ---------- */
.chat-panel-v164{
  position:fixed;left:22px;bottom:96px;z-index:770;width:min(370px,calc(100vw - 44px));height:min(520px,68svh);
  display:flex;flex-direction:column;direction:rtl;overflow:hidden;color:#fff;
  border:2px solid var(--v164-gold);border-radius:18px;background:linear-gradient(180deg,#0a3959f8,#041b2dfc);
  box-shadow:0 18px 55px #00101dcc,0 5px 0 #65410d,inset 0 0 0 1px #ffffff14
}
.chat-panel-v164.hidden{display:none!important}
.chat-v164-head{display:flex;align-items:center;gap:9px;padding:10px 12px;border-bottom:1px solid #d5a538;background:#072945f8}
.chat-v164-head>i{font-style:normal;width:38px;height:38px;border-radius:12px;display:grid;place-items:center;background:#0b3858;border:1px solid #d8aa3b;font-size:19px}
.chat-v164-head>div{min-width:0;flex:1}.chat-v164-head b{display:block;color:#ffe477;font-size:13px}.chat-v164-head small{display:block;color:#a9d8eb;font-size:8px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:2px}
.chat-v164-close{width:34px;height:34px;border:1px solid #d3a33a;border-radius:9px;background:#102f48;color:#fff;font-size:18px;cursor:pointer}
.chat-v164-messages{flex:1;overflow:auto;overscroll-behavior:contain;padding:10px;display:flex;flex-direction:column;gap:7px;scrollbar-width:thin}
.chat-v164-empty{margin:auto;text-align:center;color:#9cc9dc;font-size:10px;line-height:1.7;padding:20px}
.chat-msg-v164{max-width:84%;padding:7px 9px;border:1px solid #315d7e;border-radius:13px 13px 4px 13px;background:#0d304b;box-shadow:0 4px 12px #00152655;align-self:flex-start}
.chat-msg-v164.mine{align-self:flex-end;border-color:#c99c32;background:linear-gradient(180deg,#5d4314,#3d2b0e);border-radius:13px 13px 13px 4px}
.chat-msg-v164 b{display:block;color:#8fe6f0;font-size:8px;margin-bottom:2px}.chat-msg-v164.mine b{color:#ffe278}.chat-msg-v164 span{display:block;font-size:11px;line-height:1.45;overflow-wrap:anywhere}
.chat-msg-v164 time{display:block;margin-top:3px;color:#7da6bb;font-size:7px;direction:ltr;text-align:left}
.chat-v164-quick-wrap{border-top:1px solid #244e6d;padding:8px 9px 5px;background:#06233a}
.chat-v164-quick-title{display:flex;align-items:center;justify-content:space-between;color:#b9ddeb;font-size:8px;margin:0 2px 5px}.chat-v164-quick-title b{color:#ffe06c;font-size:9px}
.chat-v164-quick{display:flex;gap:5px;overflow-x:auto;padding-bottom:3px;scrollbar-width:none}.chat-v164-quick::-webkit-scrollbar{display:none}
.chat-v164-quick button{flex:0 0 auto;min-height:30px;padding:5px 9px;border:1px solid #4b7793;border-radius:999px;background:#0c314d;color:#fff;font:800 8px Cairo,sans-serif;cursor:pointer;white-space:nowrap}.chat-v164-quick button:hover{border-color:#f0bc3d;color:#ffe477}
.chat-v164-form{display:grid;grid-template-columns:1fr auto;gap:7px;padding:8px 9px calc(8px + env(safe-area-inset-bottom,0px));border-top:1px solid #3e6179;background:#041b2d}
.chat-v164-form input{min-width:0;height:40px;border:1px solid #456b83;border-radius:11px;background:#0a2c46;color:#fff;padding:0 11px;font:700 10px Cairo,sans-serif;outline:none}.chat-v164-form input:focus{border-color:#f0bc3d;box-shadow:0 0 0 2px #f0bc3d22}.chat-v164-form input::placeholder{color:#83a9bb}
.chat-v164-send{min-width:66px;border:1px solid #fff0a0;border-radius:11px;background:linear-gradient(180deg,#ffe37a,#e8a923);color:#422805;box-shadow:0 3px 0 #70460b;font:900 10px Cairo,sans-serif;cursor:pointer}
.chat-v164-send:disabled{opacity:.45;cursor:not-allowed}
.chat-v164-note{padding:4px 10px 7px;background:#041b2d;color:#86adc0;font-size:7px;text-align:center}

/* Chat button badge starts clean; JS only shows real unread count. */
body.chat-hud-v164 #refChatBtn em{display:none!important}
body.chat-hud-v164 #refChatBtn.has-unread em{display:grid!important}
body.chat-hud-v164 #refChatBtn.chat-open{border-color:#49dbe7!important;box-shadow:0 0 0 2px #49dbe733,0 4px 0 #51350e,0 8px 14px #00172866!important}

/* ---------- TABLET ---------- */
@media (min-width:761px) and (max-width:1279px){
  body.chat-hud-v164 .classic-top-center{top:5px!important;gap:5px!important}
  body.chat-hud-v164 .classic-top-center .round-chip{min-width:148px!important;padding:7px 13px!important;font-size:12px!important}
  body.chat-hud-v164 .classic-stage-bar{min-height:24px!important;max-width:255px!important}
  body.chat-hud-v164 .classic-stage-bar b,body.chat-hud-v164 .classic-stage-bar span{font-size:7px!important;padding:3px 6px!important}
  body.chat-hud-v164 .classic-stage-bar span:first-child{display:none!important}
  .chat-panel-v164{left:10px;right:10px;bottom:58px;width:auto;height:min(520px,64svh)}
}

/* ---------- PHONE: central header then player row; no overlap ---------- */
@media (max-width:760px){
  body.chat-hud-v164 .classic-top-center{top:4px!important;gap:4px!important;z-index:74!important}
  body.chat-hud-v164 .classic-top-center .round-chip{min-width:126px!important;max-width:155px!important;padding:6px 10px!important;font-size:10px!important;border-radius:10px!important}
  body.chat-hud-v164 .classic-stage-bar{display:flex!important;min-height:22px!important;max-width:205px!important;padding:2px!important;border-radius:8px!important}
  body.chat-hud-v164 .classic-stage-bar span:first-child{display:none!important}
  body.chat-hud-v164 .classic-stage-bar b,body.chat-hud-v164 .classic-stage-bar span{font-size:6px!important;padding:3px 5px!important;max-width:104px!important}
  body.chat-hud-v164.reference-v120 .hud-players{top:69px!important;left:4px!important;right:4px!important;z-index:62!important;gap:4px!important}
  body.chat-hud-v164.reference-v120 .phud{height:49px!important;width:calc(50vw - 8px)!important;padding:3px 4px!important}
  body.chat-hud-v164.reference-v120 .phud>img{width:33px!important;height:40px!important}
  body.chat-hud-v164.reference-v120 .phud-meta>b{font-size:8px!important}.chat-hud-v164.reference-v120 .phud .cash-coin{font-size:7px!important}.chat-hud-v164.reference-v120 .phud .worth{font-size:6px!important}
  body.chat-hud-v164.reference-v120 .stage#stage3d{padding-top:124px!important}
  .chat-panel-v164{left:6px;right:6px;bottom:55px;width:auto;height:min(590px,72svh);border-radius:15px}
  .chat-v164-head{padding:8px 9px}.chat-v164-head>i{width:32px;height:32px;font-size:16px}.chat-v164-head b{font-size:11px}.chat-v164-head small{font-size:7px}
  .chat-v164-messages{padding:8px}.chat-msg-v164{max-width:90%}.chat-msg-v164 span{font-size:10px}
  .chat-v164-quick-wrap{padding:7px 7px 4px}.chat-v164-quick button{min-height:28px;font-size:7px;padding:4px 8px}
  .chat-v164-form{padding:7px}.chat-v164-form input{height:38px;font-size:9px}.chat-v164-send{min-width:58px;font-size:9px}
}

@media (max-height:650px) and (orientation:landscape){
  body.chat-hud-v164 .classic-top-center{top:2px!important;gap:2px!important}.chat-hud-v164 .classic-top-center .round-chip{padding:4px 9px!important;font-size:9px!important}.chat-hud-v164 .classic-stage-bar{min-height:20px!important}
  .chat-panel-v164{height:min(86svh,440px);bottom:52px}
}
@media (max-width:1279px){body.chat-hud-v164 .v162-mobile-nav{grid-template-columns:repeat(6,minmax(0,1fr))!important}.chat-hud-v164 .v162-mobile-nav button{font-size:7px!important}.chat-hud-v164 .v162-mobile-nav button i{font-size:13px!important}}
