/* Shared profile popup styles (copied from room-lobby baseline) */
.room-lobby-profile-overlay {
  position: fixed;
  inset: 0;
  z-index: 10060;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.room-lobby-profile-overlay.is-hidden {
  display: none !important;
}
.room-lobby-profile-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
}
.room-lobby-profile-dialog {
  position: relative;
  z-index: 1;
  width: min(
    1701px,
    calc(100vw - 24px),
    calc((100dvh - 24px) * (1701 / 951))
  );
  height: auto;
  aspect-ratio: 1701 / 951;
  max-height: calc(100dvh - 24px);
  padding: 0;
  background: url(../img/03-6-Profile/profile-pop-bg.webp) center/100% 100% no-repeat;
  border: none;
  border-radius: 0;
  box-shadow: none;
  color: #eaf8ff;
  box-sizing: border-box;
  --rp-scale: 1;
  /* [2026-08-11] QA P11: ปุ่มปิดโปรไฟล์ 62px*scale เล็กเกินกดบนมือถือ — floor ของ --rp-scale (0.12)
     ทำให้ปุ่มเหลือ ~7px จริง (จอ 667x375 วัดได้ ~23px) ปุ่มนี้ position:absolute เดี่ยว ๆ ไม่มีพี่น้องที่ต้อง
     แบ่งพื้นที่แถว จึงยกพื้นตรง ๆ ได้โดยไม่กระทบเลย์เอาต์อื่น */
  --rp-close-hit-size: max(calc(62px * var(--rp-scale)), 28px);
  --rp-close-hit-top: 9.5%;
  --rp-close-hit-right: 5.5%;
}
.room-lobby-profile-title {
  display: none !important;
}
.room-lobby-profile-close {
  position: absolute;
  top: var(--rp-close-hit-top);
  right: var(--rp-close-hit-right);
  width: var(--rp-close-hit-size);
  height: var(--rp-close-hit-size);
  border: none;
  border-radius: 0;
  background: rgba(0, 255, 255, 0);
  color: transparent;
  font-size: 0;
  line-height: 1;
  cursor: pointer;
  text-shadow: none;
  z-index: 3;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.5;
}
.room-lobby-profile-content {
  position: absolute;
  top: 17%;
  right: 7%;
  bottom: 11%;
  left: 7%;
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.3fr);
  gap: 0;
  align-items: stretch;
  height: auto;
  padding: 0;
  box-sizing: border-box;
}
.room-lobby-profile-left-pane,
.room-lobby-profile-right-pane {
  border: 2px solid rgba(92, 233, 255, 0.65);
  border-radius: 12px;
  background: transparent;
  padding: clamp(10px, 1.4vw, 16px);
  box-sizing: border-box;
}
.room-lobby-profile-left-pane {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: calc(3px * var(--rp-scale)) calc(4px * var(--rp-scale)) calc(5px * var(--rp-scale));
  width: 100%;
  height: 97%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) calc(58px * var(--rp-scale));
  justify-items: center;
  align-items: stretch;
  row-gap: calc(10px * var(--rp-scale));
}
.room-lobby-profile-inner-frame {
  width: min(100%, 100%);
  max-width: 100%;
  aspect-ratio: 621 / 626;
  height: 100%;
  max-height: 100%;
  min-width: 0;
  background: url(../img/03-6-Profile/profile-char-frame.webp) center/100% 100% no-repeat;
  --pf-scale: var(--rp-scale, 1);
  font-size: calc(16px * var(--pf-scale));
  padding: calc(12px * var(--pf-scale)) calc(11px * var(--pf-scale)) calc(9px * var(--pf-scale));
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  align-self: stretch;
  overflow: hidden;
  margin-top: -1.5%;
}
.room-lobby-profile-coins {
  margin: calc(13px * var(--pf-scale)) 0 calc(10px * var(--pf-scale));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(8px * var(--pf-scale));
  font-size: calc(30px * var(--pf-scale));
  font-weight: 700;
  width: 100%;
  text-align: center;
  line-height: 1;
}
.room-lobby-profile-coins strong {
  color: #fff;
  font-size: calc(48px * var(--pf-scale));
  font-weight: 700;
  line-height: 1;
}
.room-lobby-profile-coins-icon {
  width: calc(30px * var(--pf-scale));
  height: calc(30px * var(--pf-scale));
}
.room-lobby-profile-coins-label {
  height: calc(62px * var(--pf-scale));
  width: auto;
  object-fit: contain;
  margin-top: calc(6px * var(--pf-scale));
}
.room-lobby-profile-char-card {
  border: none;
  border-radius: 0;
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: calc(3px * var(--pf-scale));
  background: transparent;
  padding: calc(4px * var(--pf-scale)) 0 calc(6px * var(--pf-scale));
  box-sizing: border-box;
  overflow: hidden;
}
.room-lobby-profile-char-card #room-lobby-profile-overlay-avatar {
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  max-height: 83%;
  margin-top: calc(-28px * var(--pf-scale));
  margin-bottom: calc(-9px * var(--pf-scale));
}
.room-lobby-profile-overlay-name {
  margin-top: 0;
  font-size: calc(38px * var(--pf-scale));
  font-weight: 700;
  color: #fff;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-lobby-profile-overlay-name-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: calc(6px * var(--pf-scale));
  width: 100%;
  min-width: 0;
  padding-left: calc(92px * var(--pf-scale));
  padding-right: calc(92px * var(--pf-scale));
  box-sizing: border-box;
  margin-top: calc(-6px * var(--pf-scale));
  flex-shrink: 0;
  min-height: calc(70px * var(--pf-scale));
  overflow: visible;
}
.room-lobby-profile-edit-btn {
  padding: 0;
  margin: 0;
  position: absolute;
  right: 4%;
  top: 50%;
  transform: translateY(-50%);
  /* [2026-08-11] QA P11: ปุ่มแก้ไขชื่อ 88px*scale วัดได้ 19x19px บนบางวิวพอร์ต — ปุ่มนี้
     position:absolute เดี่ยว ๆ ไม่มีพี่น้องแบ่งพื้นที่แถว ยกพื้นตรง ๆ ได้ */
  width: max(calc(88px * var(--pf-scale)), 28px);
  height: max(calc(88px * var(--pf-scale)), 28px);
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}
.room-lobby-profile-edit-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.room-lobby-profile-name-sep {
  margin-top: calc(-10px * var(--pf-scale));
  width: min(100%, 505px);
  height: auto;
  object-fit: contain;
}
.room-lobby-profile-overlay-agent {
  margin-top: 0;
  font-size: calc(18px * var(--pf-scale));
  color: #F856E2;
  font-weight: 500;
  line-height: 1;
  margin-bottom: 0;
  flex-shrink: 0;
}
.room-lobby-profile-agent-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: calc(8px * var(--pf-scale));
  width: 100%;
  margin-top: calc(4px * var(--pf-scale));
  margin-bottom: calc(4px * var(--pf-scale));
  flex-shrink: 0;
  box-sizing: border-box;
  padding: 0 calc(8px * var(--pf-scale));
}
.jd-link-trigger {
  position: relative;
  top: auto;
  left: auto;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: calc(6px * var(--pf-scale));
  min-height: calc(36px * var(--pf-scale));
  padding: calc(6px * var(--pf-scale)) calc(14px * var(--pf-scale));
  border: none;
  border-radius: 0;
  background: url("../img/Room-id-BG.webp") center / 100% 100% no-repeat;
  box-shadow: none;
  color: #dff6ff;
  font-family: 'Kanit', 'Segoe UI', system-ui, sans-serif;
  font-size: calc(14px * var(--pf-scale));
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.jd-link-trigger:hover {
  filter: brightness(1.12);
}
.room-lobby-profile-logout {
  margin-top: 0;
  margin-bottom: 7%;
  width: min(50%, calc(256px * var(--rp-scale)));
  max-width: calc(256px * var(--rp-scale));
  aspect-ratio: 256 / 94;
  height: auto;
  /* [2026-08-11] QA P11: ปุ่มออกจากระบบสูง 94px*scale เตี้ยเกินที่ scale ต่ำสุด (floor 0.12 ของ --rp-scale)
     ปุ่มนี้เป็นแถวเดี่ยวในกริดแถวของตัวเอง (ไม่มีพี่น้องแบ่งพื้นที่แนวนอน) ยก min-height ตรง ๆ ได้
     ไม่กระทบสัดส่วนภาพเพราะ img ข้างในใช้ object-fit: contain */
  min-height: 28px;
  border-radius: 0;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 0;
  font-weight: 400;
  cursor: pointer;
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.room-lobby-profile-logout img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
}
.room-lobby-profile-right-pane {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: calc(14px * var(--rp-scale));
  padding-top: calc(6px * var(--rp-scale));
  margin-left: calc(-32px * var(--rp-scale));
  min-width: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 0;
}
.room-lobby-profile-archiv-groups {
  --room-lobby-profile-archiv-overlap: calc(-38px * var(--rp-scale));
  --room-lobby-profile-archiv-group-scale: 1.031;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding-left: calc(45px * var(--rp-scale));
  height: calc(60px * var(--rp-scale));
  overflow: visible;
  transform: scale(var(--room-lobby-profile-archiv-group-scale));
  transform-origin: left bottom;
  margin-left: 1%;
  position: relative;
  z-index: 4;
}
.room-lobby-profile-archiv-group-btn {
  /* [2026-08-11] QA P11: แท็บสถิติ 190x60*scale เล็ก/เตี้ยเกินกดที่ scale ต่ำ (วัดได้ ~13-22px สูง) —
     .room-lobby-profile-archiv-groups กำหนด height คงที่ของตัวเอง (ไม่ยืดตามลูก) ปุ่มแต่ละอันจึง
     "ล้น" ขึ้นด้านบนได้อิสระ (align-items: flex-end) โดยไม่ดันเลย์เอาต์ถัดไป ยกพื้นตรง ๆ ปลอดภัย
     ปุ่มเรียงแบบซ้อนทับกันด้วย margin ติดลบอยู่แล้วโดยดีไซน์ (แท็บสไตล์โฟลเดอร์) การยกพื้นความกว้าง
     เล็กน้อยจึงไม่ทำให้พังต่างจากเดิม */
  width: max(calc(190px * var(--rp-scale)), 28px);
  height: max(calc(60px * var(--rp-scale)), 28px);
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}
.room-lobby-profile-archiv-group-btn + .room-lobby-profile-archiv-group-btn {
  margin-left: var(--room-lobby-profile-archiv-overlap);
}
.room-lobby-profile-archiv-group-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.room-lobby-profile-archiv-frame {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  width: min(100%, calc(872px * var(--rp-scale)));
  aspect-ratio: 872 / 515;
  max-height: 100%;
  overflow: hidden;
  isolation: isolate;
  background: url(../img/03-6-Profile/archiv-frame.webp) center/contain no-repeat;
  padding: 4.8% 9.5% 3.8% 11.2%;
  box-sizing: border-box;
  margin-top: -4.5%;
  margin-left: 1%;
  pointer-events: none;
}
.room-lobby-profile-achievements-list {
  list-style: none;
  margin: 0;
  padding: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: calc(16px * var(--rp-scale));
  padding-right: calc(6px * var(--rp-scale));
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  scrollbar-gutter: stable;
  pointer-events: auto;
}
.room-lobby-profile-achievements-list::-webkit-scrollbar {
  width: 0;
  height: 0;
}
.room-lobby-profile-archiv-item {
  --room-lobby-profile-archiv-icon-col-width: calc((131px + 14px) * var(--rp-scale));
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-start;
  align-items: center;
  gap: calc(14px * var(--rp-scale));
  min-height: calc(123px * var(--rp-scale));
}
.room-lobby-profile-archiv-icon-bg {
  width: calc(131px * var(--rp-scale));
  height: calc(123px * var(--rp-scale));
  aspect-ratio: 131 / 123;
  object-fit: contain;
  display: block;
}
.room-lobby-profile-archiv-main {
  --room-lobby-profile-archiv-title-progress-offset: calc(-8px * var(--rp-scale));
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.room-lobby-profile-archiv-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(8px, 0.8vw, 12px);
}
.room-lobby-profile-archiv-name {
  width: calc(421px * var(--rp-scale));
  height: calc(72px * var(--rp-scale));
  max-width: 100%;
  aspect-ratio: 421 / 72;
  object-fit: contain;
  display: block;
}
.room-lobby-profile-archiv-count {
  color: #ffe95a;
  font-size: calc(38px * var(--rp-scale));
  line-height: 1;
  font-weight: 700;
  font-family: 'NotoSansThai', 'Kanit', system-ui, sans-serif;
}
.room-lobby-profile-archiv-progress-wrap {
  position: relative;
  margin-top: var(--room-lobby-profile-archiv-title-progress-offset);
  width: calc(571px * var(--rp-scale));
  max-width: 100%;
  aspect-ratio: 571 / 56;
  height: calc(56px * var(--rp-scale));
}
.room-lobby-profile-archiv-progress-bg,
.room-lobby-profile-archiv-progress {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.room-lobby-profile-archiv-progress {
  clip-path: inset(0 calc(100% - var(--archiv-progress, 0%)) 0 0);
}
.room-lobby-profile-archiv-line {
  width: calc(100% + var(--room-lobby-profile-archiv-icon-col-width));
  margin-left: calc(-1 * var(--room-lobby-profile-archiv-icon-col-width));
  height: calc(4px * var(--rp-scale));
  aspect-ratio: auto;
  object-fit: fill;
  display: block;
  margin-bottom: -3%;
}
/* ===== Achievements แบบข้อความ (แทนรูปชื่อ archiv-name-N.png) ===== */
.room-lobby-profile-archiv-item.rlpa-text-item {
  min-height: calc(118px * var(--rp-scale));
}
.rlpa-title-col {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: calc(4px * var(--rp-scale));
  padding: calc(2px * var(--rp-scale)) 0;
}
.rlpa-title {
  font-family: 'Kanit', 'NotoSansThai', system-ui, sans-serif;
  font-weight: 800;
  font-size: calc(34px * var(--rp-scale));
  line-height: 1.05;
  color: #eafcff;
  text-shadow: 0 calc(2px * var(--rp-scale)) calc(6px * var(--rp-scale)) rgba(0, 0, 0, 0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rlpa-title .rlpa-check {
  color: #5dffa0;
  font-size: 0.82em;
  margin-left: 0.2em;
}
.rlpa-desc {
  font-family: 'NotoSansThai', 'Kanit', system-ui, sans-serif;
  font-weight: 500;
  font-size: calc(21px * var(--rp-scale));
  line-height: 1.25;
  color: #b9c6e6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rlpa-text-item.is-unlocked .rlpa-title {
  color: #ffe95a;
  text-shadow: 0 0 calc(12px * var(--rp-scale)) rgba(255, 220, 90, 0.5);
}
.rlpa-text-item.is-unlocked .room-lobby-profile-archiv-count {
  color: #5dffa0;
}
.rlpa-text-item:not(.is-unlocked) .room-lobby-profile-archiv-count {
  color: #ffe95a;
}
.room-lobby-profile-archiv-scroll {
  position: absolute;
  top: 10%;
  right: 4.6%;
  bottom: 8%;
  width: calc(13px * var(--rp-scale));
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.room-lobby-profile-archiv-scroll.is-hidden {
  display: none !important;
}
.room-lobby-profile-archiv-scroll-bg,
.room-lobby-profile-archiv-scroll-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  display: block;
  border-radius: 999px;
}
.room-lobby-profile-archiv-scroll-bg {
  top: 0;
  bottom: 0;
  height: 100%;
  background: #1b2740;
  border: 1px solid #22324f;
  box-shadow: inset 0 0 6px rgba(8, 13, 24, 0.45);
}
.room-lobby-profile-archiv-scroll-bar {
  top: 0;
  height: 42%;
  min-height: 18%;
  background: #f04cdc;
  border: 1px solid #ffb8f5;
  box-shadow: 0 0 6px rgba(240, 76, 220, 0.55);
}
.room-lobby-profile-settings {
  position: relative;
  width: min(100%, calc(824px * var(--rp-scale)));
  aspect-ratio: 824 / 169;
  margin-top: auto;
}
.room-lobby-profile-settings-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  margin-left: 7%;
  margin-top: -4%;
}
.room-lobby-profile-settings-row {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px calc(11px * var(--rp-scale)) 13px calc(163px * var(--rp-scale));
  box-sizing: border-box;
}
.room-lobby-profile-setting-item {
  display: inline-flex;
  align-items: center;
  gap: calc(14px * var(--rp-scale));
}
.room-lobby-profile-setting-label {
  width: calc(99px * var(--rp-scale));
  height: calc(39px * var(--rp-scale));
  aspect-ratio: 99 / 39;
  object-fit: contain;
  display: block;
}
.room-lobby-profile-toggle {
  margin: 0;
  width: calc(152px * var(--rp-scale));
  height: calc(94px * var(--rp-scale));
  aspect-ratio: 152 / 94;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  margin-left: -11%;
}
.room-lobby-profile-toggle img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Profile popup: compact by width */
@media (max-width: 1100px) {
  .room-lobby-profile-content {
    top: 13%;
    right: 4%;
    bottom: 8%;
    left: 4%;
    gap: clamp(8px, 1vw, 14px);
    grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.12fr);
  }
  .room-lobby-profile-left-pane {
    grid-template-rows: minmax(0, 1fr) auto;
    row-gap: clamp(3px, 0.5vw, 6px);
  }
  .room-lobby-profile-logout {
    width: min(58%, 100%);
  }
  .room-lobby-profile-char-card #room-lobby-profile-overlay-avatar {
    width: 74%;
    max-width: 74%;
    max-height: 60%;
  }
}
/* Profile popup: compact by width (small) */
@media (max-width: 900px) {
  .room-lobby-profile-content {
    top: 11%;
    right: 3%;
    bottom: 7%;
    left: 3%;
    gap: 8px;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.08fr);
  }
  .room-lobby-profile-logout {
    width: min(62%, 100%);
  }
  .room-lobby-profile-char-card #room-lobby-profile-overlay-avatar {
    width: 64%;
    max-width: 64%;
    max-height: 56%;
  }
}

/* Profile popup: compact by height without breaking object ratios */
@media (max-height: 700px) {
  .room-lobby-profile-content {
    top: 15%;
    right: 5.2%;
    bottom: 9%;
    left: 5.2%;
    gap: calc(10px * var(--rp-scale));
    grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.22fr);
  }
  .room-lobby-profile-right-pane {
    gap: calc(10px * var(--rp-scale));
  }
  .room-lobby-profile-archiv-groups {
    --room-lobby-profile-archiv-group-scale: 1;
  }
}

@media (max-height: 560px) {
  .room-lobby-profile-content {
    top: 13.5%;
    right: 4%;
    bottom: 7.5%;
    left: 4%;
    gap: calc(8px * var(--rp-scale));
  }
  .room-lobby-profile-left-pane {
    row-gap: calc(6px * var(--rp-scale));
  }
  .room-lobby-profile-logout {
    margin-bottom: 3.5%;
  }
}

/* ===== [2026-08-04] แก้ตามภาพจากเจ้าของเกม (ไฟล์นี้โหลดทีหลัง room-lobby.css จึงต้องแก้ที่นี่) ===== */
/* ปุ่มออกจากระบบ: กรอบปุ่มสัดส่วนถูก (256/94) แต่ padding ไม่เท่ากันบีบ img ข้างในเป็น 3.3:1 ตัวหนังสือแบน
   ล็อกสัดส่วนที่ img ตรงๆ และตัด padding ที่ทำให้เพี้ยน */
.room-lobby-profile-logout { padding: 0; }
.room-lobby-profile-logout img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 256 / 94;
  object-fit: contain;
}
/* ซ่อนเหรียญเล็กหน้า My Coins (ซ้ำกับป้าย) + เพิ่มระยะหายใจด้านบนทั้งสอง pane */
.room-lobby-profile-coins-icon { display: none !important; }
.room-lobby-profile-left-pane { padding-top: .5em; }
.room-lobby-profile-right-pane { padding-top: .5em; }
