/* Main Lobby — CSS ชุดเดิม (ปรับ body → .lobby-page) + guide / toast / overlay / vignette */

* { box-sizing: border-box; }

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

/* [2026-08-11] ฟอนต์ไทยไม่มีหัว — เดิมหน้านี้ประกาศแค่ ExtraBold ตัวเดียว (ครอบคลุมทุก
   font-weight ทางเทคนิค แต่ตัวอักษรหน้าตาเป็น ExtraBold เสมอ) เติมน้ำหนักที่เหลือให้ครบ
   เพื่อให้กฎที่ขอ font-weight 500/600/700/800-900 ได้ไฟล์ที่ตรงน้ำหนักจริง
   path ใช้ /Create%20Room/FONTS/ (absolute) เพราะไฟล์ SemiBold/Bold/Black มีอยู่จริงเฉพาะ
   ในโฟลเดอร์นั้น — โฟลเดอร์ FONTS/ ที่ root มีแค่ Medium/ExtraBold
   ⚠️ ต้องประกาศบล็อกเหล่านี้ "ก่อน" ExtraBold(100-900) ด้านล่าง — วัดจริงพบว่าเมื่อสอง
   @font-face ประกาศ font-weight เป็น "ช่วง" ทับกัน (เช่น 800 900 กับ 100 900) เบราว์เซอร์
   จะเลือกไฟล์ที่ "ประกาศก่อน" เสมอ ไม่ใช่ไฟล์ที่ช่วงแคบกว่า/ตรงกว่า ต่อให้ Black คือคำตอบที่
   ถูกต้องกว่าสำหรับ weight 800-900 ก็ตาม (ส่วน Medium/SemiBold/Bold ใช้ weight เป็นค่าเดี่ยว
   ไม่ใช่ช่วง จึงชนะ ExtraBold(ช่วง) ได้เสมอไม่ว่าจะประกาศก่อนหรือหลัง) */
@font-face { font-family:'NotoSansThai'; src:url('/Create%20Room/FONTS/NotoSansThai-Medium.ttf') format('truetype');
  font-weight:500; font-style:normal; font-display:swap; }
@font-face { font-family:'NotoSansThai'; src:url('/Create%20Room/FONTS/NotoSansThai-SemiBold.ttf') format('truetype');
  font-weight:600; font-style:normal; font-display:swap; }
@font-face { font-family:'NotoSansThai'; src:url('/Create%20Room/FONTS/NotoSansThai-Bold.ttf') format('truetype');
  font-weight:700; font-style:normal; font-display:swap; }
@font-face { font-family:'NotoSansThai'; src:url('/Create%20Room/FONTS/NotoSansThai-Black.ttf') format('truetype');
  font-weight:800 900; font-style:normal; font-display:swap; }

@font-face {
  font-family: 'NotoSansThai';
  src: url('../FONTS/NotoSansThai-ExtraBold.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --lobby-character-height: 62cqh; /* ความสูงตัวละครแบบพิกเซลคงที่ */
  --lobby-character-stand-y: 0px; /* จุดยืนเท้าจากด้านล่างจอแบบพิกเซลคงที่ */
  --lobby-character-foot-offset: 18cqh; /* จูนละเอียดเพิ่ม/ลดจากจุดยืนหลัก */
  --lobby-character-anchor-x: 50%; /* จุดยึดตัวละครแนวนอน */
  --lobby-character-anchor-shift-x: -50%; /* ชดเชยให้อยู่กึ่งกลางจาก anchor-x */
  --lobby-character-anchor-y: 50%; /* จุดยึดตัวละครแนวตั้ง (100%=ยึดเท้า) */
  --lobby-bg-anchor-x: 50%;
  --lobby-bg-anchor-y: 88%; /* จุดฐานของฉากหลังที่ต้องการยึดเป็นหลัก */
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

body.lobby-page {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: 'NotoSansThai', 'Kanit', sans-serif;
  color: #fff;
  background: #060818;
  -webkit-tap-highlight-color: transparent;
}

body.lobby-page button,
body.lobby-page input,
body.lobby-page textarea,
body.lobby-page select {
  font-family: inherit;
}

body.lobby-page,
body.lobby-page * {
  font-family: 'NotoSansThai', 'Kanit', sans-serif;
}

/* ปุ่มที่กดง่ายบนมือถือ */
@media (hover: none) and (pointer: coarse) {
  .lobby-btn-cloth,
  .lobby-btn-start,
  .lobby-btn-quiz,
  .lobby-btn-daily,
  .lobby-btn-tutorial,
  .lobby-btn-profile,
  .lobby-btn-ai-chat {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ---- vignette (เสริม) ---- */
.lobby-vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse 85% 75% at 50% 48%, transparent 0%, rgba(0, 0, 0, 0.08) 40%, rgba(0, 0, 0, 0.45) 100%);
}

/* ---- พื้นหลัง ---- */
.lobby-bg {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  overflow: hidden;
}

.lobby-bg-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--lobby-bg-anchor-x) var(--lobby-bg-anchor-y);
}

/* ---- ชั้น UI ทั้งหมด ---- */
.lobby-ui {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---- Header ---- */
.lobby-header {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0.5rem clamp(1rem, 4vw, 2rem);
  padding: clamp(0.5rem, 2vw, 1rem) clamp(1rem, 4vw, 2rem);
  align-items: start;
  flex-shrink: 0;
  position: relative;
  z-index: 6;
}

@media (min-width: 768px) {
  .lobby-header {
    grid-template-columns: 1fr min(320px, 28vw);
    padding-right: 24px;
  }
  .lobby-news-wrap { width: 100%; max-width: 320px; }
  .lobby-btn-daily { margin-left: auto; }
  .lobby-footer { padding-right: 24px; }
}

@media (min-width: 1200px) {
  .lobby-header { grid-template-columns: 1fr 320px; }
}

@media (max-width: 767px) {
  .lobby-header { grid-template-columns: 1fr auto; padding-right: clamp(1rem, 4vw, 2rem); }
  .lobby-news-wrap { max-width: min(320px, 28vw); }
  .lobby-btn-daily { max-width: min(200px, 18vw); width: auto; }
  .lobby-footer { padding-right: clamp(1rem, 4vw, 2rem); }
}

.lobby-profile-panel { grid-column: 1; grid-row: 1; }
.lobby-news-wrap { grid-column: 2; grid-row: 1; }
.lobby-header-row2-left { grid-column: 1; grid-row: 2; display: flex; align-items: center; gap: 0.5rem; }
.lobby-btn-daily { grid-column: 2; grid-row: 2; }

.lobby-btn-help {
  z-index: 10;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: rgba(0, 180, 220, 0.25);
  color: #00d4ff;
  font-size: 1.25rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.4);
}

.lobby-btn-help:hover { background: rgba(0, 180, 220, 0.4); }

.lobby-profile-panel {
  position: relative;
  flex-shrink: 0;
  width: fit-content;
  max-width: 280px;
}

.lobby-profile-bg {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  object-fit: contain;
  vertical-align: top;
}

.lobby-profile-inner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: clamp(0.3rem, 1.2vw, 0.5rem);
  padding: 8% 6% 8% 5%;
  box-sizing: border-box;
  overflow: hidden;
}

.lobby-avatar-wrap {
  width: 30%;
  max-width: 72px;
  flex-shrink: 0;
  aspect-ratio: 1;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 6px;
  height: 55px;
  padding-left: 14px;
}

.lobby-avatar-mask {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center -10%;
  display: block;
  -webkit-touch-callout: none;
}

.lobby-profile-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  padding-left: clamp(0.15rem, 0.6vw, 0.35rem);
}

.lobby-profile-name {
  margin: 0 0 0.1em;
  font-size: clamp(0.85rem, 1.5vw, 1.15rem);
  font-weight: bold;
  color: #fff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lobby-profile-meta {
  margin: 0;
  font-size: clamp(11px, 0.9vw, 13px);   /* [2026-08-22] เดิม clamp(0.55rem,0.9vw,0.65rem) = 8.8-10.4px เล็กเกินอ่าน */
  color: #da62aa;
  line-height: 1.3;
}

.lobby-profile-coins {
  margin: 0.2em 0 0;
  font-size: clamp(11px, 0.9vw, 13px);   /* [2026-08-22] เดิม clamp(0.55rem,0.9vw,0.65rem) = 8.8-10.4px เล็กเกินอ่าน */
  color: #b0b0b0;
  display: flex;
  align-items: center;
  gap: 0.25em;
  line-height: 1.3;
}

.lobby-coin-icon {
  width: 1.2em;
  height: 1.2em;
  object-fit: contain;
}

.lobby-news-wrap {
  position: relative;
  max-width: 320px;
  width: 320px;
  justify-self: end;
  display: block;
  /* [2026-08-10] ต้องล็อกอัตราส่วนให้เท่าภาพกรอบ news-banner-bg.png (517×213) เสมอ
     เพราะช่องแบนเนอร์ (.lobby-news-banner) วางด้วย % ของ "กล่อง wrap"
     ถ้า wrap สูงกว่าอัตราส่วนภาพ ภาพกรอบจะถูก contain ให้เตี้ยลงแล้วลอยกลางกล่อง (letterbox)
     ⇒ % ที่คำนวณจาก wrap จะไม่ตรงกับกรอบขาวในภาพ แบนเนอร์เลยล้นออกนอกกรอบ
     วัดจริงตอนเจอ: viewport 961px → wrap 362×182 (1.99) แต่ภาพวาดจริง 362×149 ⇒ แบนเนอร์สูงเกิน 23px และเลื่อนขึ้น 12px */
  aspect-ratio: 517 / 213;
}

.lobby-news-bg {
  display: block;
  width: 100%;
  /* คู่กับ aspect-ratio ด้านบน — ให้ภาพกรอบเต็มกล่องพอดี ไม่เหลือ letterbox ให้ % เพี้ยน */
  height: 100%;
  object-fit: contain;
  vertical-align: top;
}

.lobby-news-img {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  min-width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
  object-position: top center;
  transform: translateX(5.5%);
}

/* ---- [2026-08-10] แบนเนอร์ข่าวสาร (ตั้งค่าจาก Admin › Banner ข่าวสาร) ----
   inset วัดจากพื้นที่ขาวจริงใน news-banner-bg.png (517×213 → กล่องขาว 457×150)
   หลายรูปวางซ้อนกันทั้งหมด แล้วสลับ opacity ทีละใบ (ไม่สลับ src) — กันภาพกะพริบขาว
   ตอนโหลดใบถัดไป และ browser cache ทุกใบไว้แล้วตั้งแต่เรนเดอร์รอบแรก */
.lobby-news-banner {
  position: absolute;
  left: 5.8%;
  right: 5.8%;
  top: 14.55%;
  bottom: 15.02%;
  overflow: hidden;
  background: #0b1226;
}

.lobby-news-banner-img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.lobby-news-banner-img.is-on {
  opacity: 1;
}

/* จุดบอกลำดับ — โชว์เฉพาะตอนมีมากกว่า 1 ใบ (JS ใส่คลาสให้) */
.lobby-news-banner-dots {
  position: absolute;
  right: 2.4%;
  bottom: 4%;
  display: none;
  gap: 0.32em;
  font-size: clamp(7px, 1.1cqh, 11px);
  z-index: 2;
}

.lobby-news-banner.has-many .lobby-news-banner-dots {
  display: flex;
}

.lobby-news-banner-dot {
  width: 0.55em;
  height: 0.55em;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
  transition: background 0.3s ease;
}

.lobby-news-banner-dot.is-on {
  background: #7fe9ff;
}

@media (prefers-reduced-motion: reduce) {
  .lobby-news-banner-img { transition: none; }
}

.lobby-btn-daily {
  position: relative;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  max-width: min(320px, 26vw);
  width: min(320px, 26vw);
  justify-self: end;
}

.lobby-daily-img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  max-width: 100%;
}

.lobby-daily-dot {
  position: absolute;
  top: 7%;
  right: 5%;
  width: 8.5%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: #e53935;
}

/* ---- กลุ่มตัวละคร + ปุ่มห้องแต่งตัว ---- */
.lobby-character-area {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 19%;
  z-index: 3;
  pointer-events: none;
  min-height: 50vh;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(0.5rem, 2vw, 1.5rem);
}

.lobby-character-area .lobby-btn-cloth { pointer-events: auto; }

.lobby-character-center {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%) scale(3);
  transform-origin: center bottom;
  width: min(160px, 14vw);
  height: min(142px, 18vh);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.lobby-character-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center bottom;
  visibility: hidden;
}

@keyframes lobby-char-idle-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-0.35cqh); }
}

.lobby-character-img.lobby-character-img--visible {
  visibility: visible;
  animation: lobby-char-idle-bob 2.6s ease-in-out infinite;
  transform-origin: center bottom;
  will-change: transform;
}

/* ---- ปุ่มห้องแต่งตัว ---- */
.lobby-center-left {
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  transform: translate(calc(-50% - 12vw), -5em);
}

.lobby-btn-cloth {
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  max-width: min(117px, 13vw);
}

.lobby-btn-cloth-img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

/* ---- ลีดเดอร์บอร์ด ---- */
.lobby-leaderboard {
  --lobby-leaderboard-height: 38cqh; /* ปรับความสูง leaderboard */
  --lobby-daily-leaderboard-gap: 0cqh; /* ระยะห่างจากปุ่มรางวัลประจำวัน (ติดลบได้) */
  --lobby-leaderboard-row-height: 7cqh; /* ปรับความสูงแต่ละรายชื่อ */
  --lobby-leaderboard-rank-icon-size: 2.3em; /* ปรับขนาดไอคอนอันดับ 1-3 */
  --lobby-leaderboard-scrollbar-width: max(8px, 1.1cqh); /* ความอ้วน scrollbar */
  --lobby-leaderboard-scrollbar-safe-gap: 10px; /* เว้นช่องกันทับตัวหนังสือ */
  --lobby-leaderboard-scrollbar-thumb-inset: 1px;
  --lobby-leaderboard-scrollbar-offset-x: 0px; /* ตำแหน่งแถบ scrollbar */
  --lobby-leaderboard-font-size: max(12px, 2.1cqh);   /* [2026-08-22] เดิม 2.1cqh ล้วน ไม่มีพื้น จอเตี้ยเหลือ 8.2px */
  --lobby-leaderboard-content-inset-top: 37%;
  --lobby-leaderboard-content-inset-right: 8.5%;
  --lobby-leaderboard-content-inset-bottom: 8%;
  --lobby-leaderboard-content-inset-left: 6%;
  position: absolute;
  top: 19em;
  right: clamp(0.5rem, 2vw, 1.5rem);
  height: var(--lobby-leaderboard-height);
  width: calc(var(--lobby-leaderboard-height) * (417 / 443));
  aspect-ratio: 417 / 443;
  z-index: 5;
  overflow: hidden;
  isolation: isolate;
}

.lobby-leaderboard-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  z-index: 0;
}

.lobby-leaderboard-mask {
  position: absolute;
  top: var(--lobby-leaderboard-content-inset-top);
  right: var(--lobby-leaderboard-content-inset-right);
  bottom: var(--lobby-leaderboard-content-inset-bottom);
  left: var(--lobby-leaderboard-content-inset-left);
  z-index: 1;
  overflow: hidden;
  border-radius: 10px;
}

.lobby-leaderboard-inner {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: clamp(0.45rem, 0.95cqh, 0.9rem) clamp(0.45rem, 1cqh, 0.85rem) clamp(0.45rem, 0.95cqh, 0.9rem);
  overflow-y: hidden;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.lobby-leaderboard-scroll {
  position: relative;
  width: 100%;
  height: 100%;
  margin-right: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: calc(var(--lobby-leaderboard-scrollbar-width) + var(--lobby-leaderboard-scrollbar-safe-gap));
  scrollbar-width: none;
  cursor: grab;
  /* [2026-08-23] ขอบล่างค่อย ๆ จาง — แถวที่โผล่ไม่เต็มจะดูเป็น "ยังมีต่อ" แทน "ถูกตัดกลางตัวอักษร"
     ที่มา: บนมือถือแนวนอน 667x375 กล่องนี้สูง 58.6px แต่ 3 แถวต้องใช้ 63.6px
       ⇒ แถวที่ 3 โผล่มาแค่ 37% แล้วโดนตัดตรงกลางพอดี ดูเหมือนจอพัง
     ทำไมไม่คำนวณความสูงให้ลงตัวแทน: ความสูงแถวขึ้นกับเนื้อหาจริง (ชื่อยาว/สั้น) และต่างกันทุกขนาดจอ
       ที่ 926x428 กล่องสูง 68.9px แต่ 3 แถวใช้ 65.2px ⇒ เหลือเศษ 3.7px ไปโผล่แถวที่ 4 อีก
       ตั้งค่าตายตัวให้พอดีทุกเครื่องไม่ได้ mask จึงตอบโจทย์กว่า
     ⚠️ ห้ามแก้ด้วยการย่อฟอนต์ — 12px นี้คือผลของการแก้คอมเมนต์ลูกค้าที่บ่นว่าอ่านไม่ออก
        (ของเดิมบน PROD คือ 7.875px ดู ClickUp 86d43w4hv) */
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 16px), rgba(0, 0, 0, 0) 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 16px), rgba(0, 0, 0, 0) 100%);
  /* เลื่อนแล้วให้หยุดตรงหัวแถว ไม่ค้างกลางแถว */
  scroll-snap-type: y proximity;
}

.lobby-leaderboard-list > li {
  scroll-snap-align: start;
}

.lobby-leaderboard-scroll.is-dragging {
  cursor: grabbing;
}

body.lobby-page.lobby-leaderboard-dragging,
body.lobby-page.lobby-leaderboard-dragging * {
  user-select: none !important;
}

.lobby-leaderboard-scroll-track {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--lobby-leaderboard-scrollbar-width);
  height: 100%;
  pointer-events: none;
  opacity: 1;
  border-radius: 999px;
  background: #1b2740;
  border: 1px solid #22324f;
  z-index: 1;
}

.lobby-leaderboard-scroll-thumb {
  position: absolute;
  right: var(--lobby-leaderboard-scrollbar-thumb-inset);
  top: var(--lobby-leaderboard-scrollbar-thumb-inset);
  width: calc(var(--lobby-leaderboard-scrollbar-width) - (var(--lobby-leaderboard-scrollbar-thumb-inset) * 2));
  min-height: 18px;
  border-radius: 999px;
  pointer-events: auto;
  z-index: 2;
  background: #f04cdc;
  box-shadow:
    inset 0 0 0 1px rgba(255, 210, 240, 0.52),
    0 0 8px rgba(255, 83, 181, 0.45);
  display: block;
  cursor: grab;
}

.lobby-leaderboard-scroll-thumb.is-dragging {
  cursor: grabbing;
}

.lobby-leaderboard-scroll::-webkit-scrollbar {
  width: 0;
  height: 0;
}
.lobby-leaderboard-scroll::-webkit-scrollbar-track {
  background: transparent;
  border: 0;
}
.lobby-leaderboard-scroll::-webkit-scrollbar-thumb {
  background: transparent;
  border: 0;
}

.lobby-leaderboard-list {
  list-style: none;
  margin: 0 auto;
  margin-top: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  padding-right: 2px;
  min-height: 0;
  overflow: visible;
  display: flex;
  flex-direction: column;
  gap: clamp(0.2rem, 0.5cqh, 0.45rem);
  align-self: center;
}

.lobby-leaderboard-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
  font-size: var(--lobby-leaderboard-font-size);
  color: #fff;
  min-height: var(--lobby-leaderboard-row-height);
}

.lobby-rank-icon {
  width: var(--lobby-leaderboard-rank-icon-size);
  height: var(--lobby-leaderboard-rank-icon-size);
  flex-shrink: 0;
}

.lobby-rank-icon {
  object-fit: contain;
}

.lobby-rank-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--lobby-leaderboard-rank-icon-size);
  height: var(--lobby-leaderboard-rank-icon-size);
  font-weight: 700;
  color: #ffffff;
  border-radius: 50%;
  background: rgba(118, 145, 212, 0);
  border: 1px solid rgba(201, 219, 255, 0);
  line-height: 1.2;
  flex-shrink: 0;
  opacity: 1;
}

.lobby-rank-num::after {
  content: '.';
}

.lobby-rank-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.05em;
}

.lobby-rank-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.lobby-rank-case {
  font-size: max(10px, 0.82em);   /* [2026-08-22] เดิม 0.82em ล้วน จอเตี้ยเหลือ 6.7px */
  color: rgba(255, 255, 255, 0.78);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.lobby-rank-score {
  flex-shrink: 0;
  margin-left: auto;
  color: #ffffff;
  font-weight: 700;
  line-height: 1.3;
}

.lobby-leaderboard,
.lobby-leaderboard * {
  font-family: 'NotoSansThai', 'Kanit', sans-serif;
  font-weight: 500;
}

/* ---- Footer ---- */
.lobby-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: clamp(0.5rem, 2vw, 1rem) clamp(1rem, 4vw, 2rem);
  gap: 1rem;
  flex-shrink: 0;
  position: relative;
}

.lobby-footer-left,
.lobby-footer-right {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  position: relative;
  z-index: 1;
}

.lobby-footer-left {
  max-width: 135px;
  width: 135px;
}

.lobby-footer-right {
  max-width: 104px;
  width: 104px;
}

.lobby-btn-tutorial,
.lobby-btn-profile,
.lobby-btn-ai-chat {
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  display: block;
  max-width: 135px;
  width: 135px;
}

.lobby-btn-tutorial-img {
  display: block;
  width: 104px;
  height: auto;
  object-fit: contain;
  transform: translateX(-14.5%);
}

.lobby-btn-profile-img,
.lobby-btn-ai-chat-img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

.lobby-footer-center {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(0.5rem, 2vw, 1rem);
  flex: 1;
  min-width: 0;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: clamp(0.5rem, 2vw, 1rem);
  z-index: 10;
}

.lobby-btn-start,
.lobby-btn-quiz {
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  max-width: 260px;
}

.lobby-btn-start-img,
.lobby-btn-quiz-img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

/* ========== RESPONSIVE ========== */
@media (min-width: 1920px) {
  .lobby-profile-panel { max-width: 280px; }
  .lobby-profile-bg { max-width: 280px; }
  .lobby-news-wrap { max-width: 320px; }
  .lobby-btn-daily { max-width: 320px; width: 320px; }
  .lobby-character-center { transform: translateX(-50%) scale(3); width: 160px; height: 142px; }
  .lobby-character-area { bottom: 19%; }
  .lobby-leaderboard { right: 24px; top: 19em; }
  .lobby-btn-start, .lobby-btn-quiz { max-width: 260px; }
  .lobby-footer-left { max-width: 135px; width: 135px; }
  .lobby-footer-right { max-width: 104px; width: 104px; }
  .lobby-btn-tutorial, .lobby-btn-profile { max-width: 104px; width: 104px; }
  .lobby-btn-ai-chat { max-width: 135px; width: 135px; }
}

@media (min-width: 1200px) and (max-width: 1919px) {
  .lobby-character-center {
    transform: translateX(-50%) scale(2.5);
    width: 140px;
    height: 124px;
  }
  .lobby-center-left {
    transform: translate(calc(-50% - 11vw), -4em);
  }
  .lobby-leaderboard { right: clamp(0.5rem, 2vw, 1.5rem); }
}

@media (max-width: 1199px) {
  .lobby-header {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 1rem;
  }
  .lobby-profile-panel { max-width: 280px; }
  .lobby-news-wrap { max-width: 320px; width: 320px; }
  .lobby-character-area {
    bottom: 20%;
    min-height: 45vh;
  }
  .lobby-character-center {
    transform: translateX(-50%) scale(2.5);
    width: 130px;
    height: 115px;
  }
  .lobby-center-left {
    transform: translate(calc(-50% - 10vw), -4em);
  }
  .lobby-btn-cloth { max-width: 98px; }
  .lobby-leaderboard {
    right: 12px;
    top: 19em;
  }
  .lobby-leaderboard-list { width: 100%; max-width: 100%; }
  .lobby-leaderboard-list li { width: 100%; }
  .lobby-footer-center { gap: 0.75rem; }
  .lobby-btn-start, .lobby-btn-quiz { max-width: 240px; }
}

@media (max-width: 767px) {
  .lobby-ui {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }
  .lobby-header {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    padding: 0.5rem 0.75rem;
  }
  .lobby-profile-panel { grid-column: 1; grid-row: 1; max-width: 280px; }
  .lobby-news-wrap { grid-column: 2; grid-row: 1; max-width: 320px; width: 320px; }
  .lobby-header-row2-left { grid-column: 1; grid-row: 2; }
  .lobby-btn-daily { grid-column: 2; grid-row: 2; max-width: min(320px, 26vw); width: min(320px, 26vw); }
  .lobby-profile-name { font-size: 0.85rem; }
  .lobby-profile-meta, .lobby-profile-coins { font-size: 0.5rem; }  /* [2026-08-23] คืนให้เท่า PROD ตามที่สั่ง */
  .lobby-character-area {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    flex: 1;
    min-height: 140px;
  }
  .lobby-character-center {
    transform: translateX(-50%) scale(2.5);
    width: 100px;
    height: 90px;
  }
  .lobby-center-left {
    transform: translate(calc(-50% - 9vw), -3em);
  }
  .lobby-btn-cloth { max-width: 72px; }
  .lobby-leaderboard {
    position: relative;
    top: auto;
    right: auto;
    --lobby-leaderboard-height: min(50cqh, 430px);
    width: min(calc(var(--lobby-leaderboard-height) * (417 / 443)), 90vw);
    max-width: none;
    margin: 0 auto;
    flex-shrink: 0;
  }
  .lobby-leaderboard-mask { border-radius: 9px; }
  .lobby-leaderboard-list {
    margin: 0 auto;
    width: 100%;
    max-width: 100%;
  }
  .lobby-leaderboard-list li {
    font-size: var(--lobby-leaderboard-font-size);
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .lobby-rank-score { flex-shrink: 0; margin-left: auto; color: #ffc107; }
  .lobby-footer {
    flex-wrap: wrap;
    justify-content: center;
    padding: 0.75rem;
  }
  .lobby-footer-left {
    position: absolute;
    left: 0.5rem;
    bottom: 0.75rem;
  }
  .lobby-footer-right {
    position: absolute;
    right: 0.5rem;
    bottom: 0.75rem;
  }
  .lobby-footer-center {
    position: relative;
    left: auto;
    transform: none;
    flex: 1 1 100%;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
  }
  .lobby-btn-start, .lobby-btn-quiz { max-width: 200px; }
  .lobby-footer-left { max-width: 104px; width: 104px; }
  .lobby-footer-right { max-width: 80px; width: 80px; }
  .lobby-btn-tutorial-img { width: 80px; }
}

@media (max-width: 479px) {
  .lobby-profile-panel { max-width: min(280px, 42vw); }
  .lobby-news-wrap { max-width: min(320px, 48vw); width: min(320px, 48vw); }
  .lobby-btn-daily { max-width: min(200px, 42vw); width: min(200px, 42vw); }
  .lobby-daily-dot { width: 9%; top: 2.2%; right: 2.2%; }
  .lobby-character-center {
    transform: translateX(-50%) scale(3.2);
    width: 80px;
    height: 70px;
  }
  .lobby-center-left {
    transform: translate(calc(-50% - 10vw), -3em);
  }
  .lobby-btn-cloth { max-width: 59px; }
  .lobby-leaderboard {
    --lobby-leaderboard-height: min(47cqh, 390px);
    width: min(calc(var(--lobby-leaderboard-height) * (417 / 443)), 92vw);
    max-width: none;
  }
  .lobby-leaderboard-list {
    width: 100%;
    max-width: 100%;
  }
  .lobby-leaderboard-list li {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .lobby-rank-score { flex-shrink: 0; margin-left: auto; color: #ffc107; }
  .lobby-btn-start, .lobby-btn-quiz { max-width: min(200px, 44vw); }
  .lobby-footer-left { max-width: min(104px, 23vw); width: min(104px, 23vw); }
  .lobby-footer-right { max-width: min(80px, 18vw); width: min(80px, 18vw); }
}

/* ========== MOBILE LANDSCAPE — Scale ตาม mock (จอ ≤932px landscape) ========== */
@media (max-width: 932px) and (orientation: landscape) {
  html,
  body.lobby-page {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body.lobby-page {
    position: fixed;
    inset: 0;
    min-height: 100dvh;
    min-height: 100svh;
    touch-action: none;
    /* ความกว้างคอลัมน์ขวา: daily กับ leaderboard ใช้ค่าเดียวกัน */
    --lobby-right-rail-width: min(calc(min(46cqh, 240px) * (417 / 443)), 24vw);
  }

  .lobby-ui {
    min-height: 100dvh;
    min-height: 100svh;
    max-height: 100dvh;
    max-height: 100svh;
    overflow: hidden;
    padding: max(0.25rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right)) max(0.25rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
  }

  /* ---- Header ---- */
  .lobby-header {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: min(0.4rem, 1svh) min(0.75rem, 1.5vw);
    padding: min(0.4rem, 1svh) min(0.75rem, 1.5vw);
    --lobby-header-daily-btn-width: var(--lobby-right-rail-width);
  }

  .lobby-profile-panel {
    max-width: min(180px, 20vw);
  }

  .lobby-profile-bg {
    max-width: min(180px, 20vw);
  }

  .lobby-profile-inner {
    padding: 6% 5% 6% 4%;
    gap: min(0.25rem, 0.8vw);
  }

  .lobby-profile-name {
    font-size: clamp(13px, 1.6svh, 16px);   /* [2026-08-22] เดิม clamp(0.55rem,1.6svh,0.75rem) = 8.8-12px */
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .lobby-profile-meta,
  .lobby-profile-coins {
    font-size: clamp(11px, 1.2svh, 13px);   /* [2026-08-22] เดิม clamp(0.42rem,1.2svh,0.55rem) วัดจริงได้ 5.7px */
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .lobby-avatar-wrap {
    width: 54%;
    max-width: min(55px, 11svh);
    /* [2026-08-23] ตัด max-height ออก — มันคือตัวที่ทำให้กรอบรูปไม่เป็นจัตุรัสบนมือถือแนวนอน
       ขนาดกรอบตัวจริงมาจากกฎท้ายไฟล์ (--lobby-profile-avatar-size + aspect-ratio:1/1 + height:auto !important)
       แต่กฎนั้นไม่ได้ล้าง max-height ทิ้ง พอจอสูง 375px ค่า 8svh = 26px จึงบีบความสูงลงข้างเดียว
       ผลคือกรอบกลายเป็น 44x29 (1.53:1) แล้ว object-fit:cover ครอปหน้าตัวละครหายไปราว 35%
       height: 75px ด้านล่างก็ตายอยู่แล้ว (โดน height:auto !important ทับ) เก็บไว้เฉย ๆ ไม่ได้ ลบด้วย */
    padding-left: 12px;
  }

  .lobby-news-wrap {
    max-width: min(200px, 22vw);
    width: min(200px, 22vw);
    overflow: hidden;
  }

  .lobby-news-img {
    max-height: 100%;
    object-fit: contain;
  }

  .lobby-btn-daily {
    max-width: var(--lobby-right-rail-width);
    width: var(--lobby-right-rail-width);
  }

  .lobby-daily-dot {
    width: 9%;
    top: 2.2%;
    right: 2.2%;
  }

  .lobby-header-row2-left {
    gap: min(0.4rem, 1vw);
  }

  .lobby-btn-tutorial,
  .lobby-btn-profile {
    max-width: min(48px, 5.5vw);
    width: min(48px, 5.5vw);
  }

  .lobby-btn-ai-chat {
    max-width: min(62px, 7vw);
    width: min(62px, 7vw);
  }

  .lobby-btn-tutorial-img {
    width: min(48px, 5.5vw);
    transform: translateX(-14.5%);
  }

  /* ---- ตัวละคร (ขยายใหญ่ตาม mock) ---- */
  .lobby-character-area {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 12%;
    min-height: 40svh;
  }

  .lobby-character-center {
    transform: translateX(-50%) scale(2.5);
    width: min(120px, 13vw);
    height: min(110px, 22svh);
  }

  .lobby-center-left {
    transform: translate(calc(-50% - 10vw), -3em);
  }

  .lobby-btn-cloth {
    max-width: min(80px, 9vw);
  }

  /* ---- ลีดเดอร์บอร์ด ---- */
  .lobby-leaderboard {
    position: absolute;
    top: auto;
    bottom: max(50px, 12svh);
    right: max(0.5rem, env(safe-area-inset-right));
    --lobby-leaderboard-height: min(46cqh, 240px);
    width: var(--lobby-right-rail-width);
    margin: 0;
  }

  .lobby-leaderboard-list {
    max-width: 100%;
    gap: 0.35rem;
    margin-top: 0.4rem;
  }

  .lobby-leaderboard-list li {
    font-size: var(--lobby-leaderboard-font-size);
    gap: 0.3rem;
    min-height: 1.4em;
  }

  .lobby-rank-icon,
  .lobby-rank-num {
    width: var(--lobby-leaderboard-rank-icon-size);
    height: var(--lobby-leaderboard-rank-icon-size);
  }

  /* ---- Footer (ลดขนาดปุ่ม landscape) ----
     ยึดแถบ footer ไว้กับขอบล่างของ viewport โดยตรง เพื่อไม่ให้ความสูงของ
     content ด้านบน (หรือ padding ที่กฎอื่นเติมเข้ามา) ดันปุ่มหลักตกใต้จอ */
  .lobby-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin-top: 0;
    /* padding ซ้าย/ขวา ≥12px เพราะ .lobby-btn-ai-chat ถูก translateX(-1cqw) ออกไปทางซ้าย */
    padding: min(0.3rem, 0.8svh) max(12px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    gap: 0.4rem;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 6;
  }

  .lobby-footer-left {
    max-width: min(70px, 8vw);
    width: min(70px, 8vw);
  }

  .lobby-footer-right {
    max-width: min(54px, 6.5vw);
    width: min(54px, 6.5vw);
  }

  .lobby-footer-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: max(6px, env(safe-area-inset-bottom));
    gap: min(0.6rem, 1.2vw);
    flex: 0 1 auto;
    margin-top: 0;
    padding-top: 0;
    max-width: calc(100vw - 2 * max(56px, 13vw));
  }

  .lobby-footer-left {
    position: relative;
    left: auto;
    bottom: auto;
    z-index: 2;
  }

  .lobby-footer-right {
    position: relative;
    right: auto;
    bottom: auto;
    z-index: 2;
  }

  .lobby-btn-start,
  .lobby-btn-quiz {
    max-width: min(170px, 19vw);
  }

  /* ---- Guide bar ---- */
  .lobby-guide-img {
    max-height: min(34svh, 200px);
  }

  .lobby-guide-bar--top .lobby-guide-img {
    max-height: min(38svh, 220px);
  }

  .lobby-guide-next img {
    height: clamp(30px, 7vw, 40px);
  }

  /* ---- AI Chat ---- */
  #lobby-ai-chat-panel:not(.lobby-ai-chat-hidden) {
    max-height: min(72svh, 280px);
    width: min(300px, 42vw);
    font-size: 0.8rem;
    padding: 3.3rem;
    padding-left: 2.6rem;  /* เพิ่ม = ขยับเนื้อหาขวา */
    padding-right: 1.4rem; /* ลดเพื่อชดเชยพื้นที่ */
  }
}

/* จอเตี้ยมาก (landscape + height ≤ 380px) — ลดอีกนิด */
@media (max-height: 380px) and (orientation: landscape) {
  body.lobby-page {
    --lobby-right-rail-width: min(calc(min(40cqh, 180px) * (417 / 443)), 22vw);
  }

  .lobby-header {
    padding: 0.2rem 0.5rem;
    gap: 0.2rem 0.5rem;
    --lobby-header-daily-btn-width: var(--lobby-right-rail-width);
  }

  .lobby-profile-panel {
    max-width: min(150px, 18vw);
  }

  .lobby-profile-bg {
    max-width: min(150px, 18vw);
  }

  .lobby-profile-inner {
    padding: 5% 4% 5% 3%;
    gap: min(0.15rem, 0.6vw);
  }

  .lobby-profile-name {
    font-size: clamp(0.45rem, 1.3svh, 0.62rem);
  }

  .lobby-profile-meta,
  .lobby-profile-coins {
    font-size: clamp(0.36rem, 1svh, 0.48rem);
  }

  .lobby-avatar-wrap {
    width: 26%;
    max-width: min(30px, 7svh);
    /* [2026-08-23] ตัด max-height ออกด้วยเหตุผลเดียวกับบล็อก 932px ข้างบน */
  }

  .lobby-news-wrap {
    max-width: min(160px, 20vw);
    width: min(160px, 20vw);
  }

  .lobby-btn-daily {
    max-width: var(--lobby-right-rail-width);
    width: var(--lobby-right-rail-width);
  }

  .lobby-btn-tutorial,
  .lobby-btn-profile {
    max-width: min(40px, 5vw);
    width: min(40px, 5vw);
  }

  .lobby-btn-ai-chat {
    max-width: min(52px, 6.5vw);
    width: min(52px, 6.5vw);
  }

  .lobby-btn-tutorial-img {
    width: min(40px, 5vw);
  }

  .lobby-character-center {
    transform: translateX(-50%) scale(2.2);
    width: min(100px, 12vw);
    height: min(90px, 20svh);
  }

  .lobby-center-left {
    transform: translate(calc(-50% - 8vw), -2em);
  }

  .lobby-btn-cloth {
    max-width: min(68px, 8vw);
  }

  .lobby-leaderboard {
    --lobby-leaderboard-height: min(40cqh, 180px);
    width: var(--lobby-right-rail-width);
    bottom: max(44px, 11svh);
  }

  .lobby-leaderboard-list {
    max-width: 100%;
    gap: 0.3rem;
  }

  .lobby-leaderboard-list li {
    font-size: var(--lobby-leaderboard-font-size);
  }

  /* padding ซ้าย/ขวา ≥12px เพราะ .lobby-btn-ai-chat ถูก translateX(-1cqw) ออกไปทางซ้าย
     (เดิม 0.4rem = 6.4px ทำให้ปุ่มเทพความรู้โผล่ออกนอกขอบซ้ายที่ 812x375 / 740x360) */
  .lobby-footer {
    padding: 0.2rem max(12px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .lobby-footer-left {
    max-width: min(57px, 7vw);
    width: min(57px, 7vw);
  }

  .lobby-footer-right {
    max-width: min(44px, 5.5vw);
    width: min(44px, 5.5vw);
  }

  .lobby-btn-start,
  .lobby-btn-quiz {
    max-width: min(145px, 17vw);
  }
}

/* ========== LANDSCAPE จอกว้างแต่เตี้ย (>932px กว้าง, ≤620px สูง) ==========
   ช่วงนี้เดิมไม่มี breakpoint คุมเลย (เช่น 1024x600, 1180x430) — footer ยังเป็น
   flex item ปลายคอลัมน์ ถ้าเนื้อหาด้านบนสูงขึ้นเมื่อไร ปุ่มหลักจะถูกดันตกใต้จอ
   แบบเดียวกับกรณี ≤932px จึงยึด footer ไว้กับขอบล่างของ viewport ให้เหมือนกัน */
@media (min-width: 933px) and (max-height: 620px) and (orientation: landscape) {
  .lobby-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin-top: 0;
    padding: clamp(0.25rem, 1svh, 0.75rem) max(16px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    z-index: 6;
  }

  .lobby-footer-center {
    bottom: max(8px, env(safe-area-inset-bottom));
    max-width: calc(100vw - 2 * max(96px, 16vw));
  }
}

/* ---- แชท AI (อ้างอิง room-lobby) ---- */
#lobby-ai-chat-panel.lobby-ai-chat-hidden {
  display: none !important;
}

#lobby-ai-chat-panel:not(.lobby-ai-chat-hidden) {
  position: fixed;
  left: 8px;
  right: auto;
  z-index: 20;
  display: flex;
  flex-flow: column;
  box-sizing: border-box;
  margin: 0;
  overflow: visible;
  background: url(/Game/img/chat-msg-bg-alpha.png) center/100% 100% no-repeat;
  background-color: transparent;
  border: none;
  box-shadow: none;
  border-radius: 12px;
  padding: 2.6rem;
  width: 454px;
  height: 526px;
  max-width: calc(100vw - 2.5rem);
  bottom: clamp(0.5rem, 2vw, 1rem);
  pointer-events: none;
}

/* พื้นแผงโปร่งไม่ดักคลิก — เปิด/ปิดเฉพาะจากปุ่ม footer + ปิดในแผง */

#lobby-ai-chat-panel:not(.lobby-ai-chat-hidden) .lobby-ai-chat-header,
#lobby-ai-chat-panel:not(.lobby-ai-chat-hidden) .lobby-ai-chat-messages,
#lobby-ai-chat-panel:not(.lobby-ai-chat-hidden) .lobby-ai-chat-form,
#lobby-ai-chat-panel:not(.lobby-ai-chat-hidden) .lobby-ai-chat-admin-link {
  pointer-events: auto;
}

#lobby-ai-chat-panel .lobby-ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  margin: 0px -2rem 0 -2rem;
  padding: 0px 1rem;
  min-height: 50px;
  height: 50px;
  overflow: visible;
  background: url(/Game/img/AI-chat-line.png) bottom repeat-x;
  background-size: 100% 3px;
  background-color: transparent;
}

#lobby-ai-chat-panel .lobby-ai-chat-title {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  line-height: 0;
}

#lobby-ai-chat-panel .lobby-ai-chat-title > img:first-child {
  width: 100px;
  height: 116px;
  object-fit: cover;
  margin-top: -39px;
  margin-left: 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

#lobby-ai-chat-panel .lobby-ai-chat-title-label {
  height: 75px;
  width: auto;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
  margin-bottom: -2px;
}

#lobby-ai-chat-panel .lobby-ai-chat-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  margin-left: auto;
}

#lobby-ai-chat-panel .lobby-ai-chat-close img {
  width: 60px;
  height: 60px;
  object-fit: contain;
}

#lobby-ai-chat-panel .lobby-ai-chat-close:hover {
  opacity: 0.9;
}

#lobby-ai-chat-panel .lobby-ai-chat-messages {
  flex: 1;
  min-height: 0;
  height: auto;
  overflow-y: auto;
  padding: 0.2rem 0.35rem 0.25rem 0;
  font-size: 1.05rem;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: none;
  border: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(244, 252, 255, 0.98) rgba(53, 110, 167, 0.28);
}

#lobby-ai-chat-panel .lobby-ai-chat-messages::-webkit-scrollbar {
  width: 1rem;
  scrollbar-width: auto;
}

#lobby-ai-chat-panel .lobby-ai-chat-messages::-webkit-scrollbar-track {
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(38, 77, 125, 0.45) 0%, rgba(32, 66, 106, 0.38) 100%);
  box-shadow: inset 0 0 0 1px rgba(107, 193, 255, 0.25);
}

#lobby-ai-chat-panel .lobby-ai-chat-messages::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(221, 244, 255, 0.96) 100%);
  box-shadow:
    0 0 10px rgba(169, 239, 255, 0.55),
    inset 0 0 0 1px rgba(180, 235, 255, 0.9);
}

#lobby-ai-chat-panel .lobby-ai-chat-form {
  display: flex;
  gap: 0rem;
  align-items: center;
  padding: 0.6rem 0;
  flex-shrink: 0;
  background: none;
  border: none;
  width: calc(100% + 3rem);   /* ขยายกว้างกว่าเดิม */
  margin-left: 0rem;         /* ดันออกซ้าย */
  margin-right: 0rem;        /* ดันออกขวา */
}

#lobby-ai-chat-panel #lobby-ai-chat-input {
  flex: 0.85;
  min-width: 0;
  min-height: 50px; 
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  border: 1px solid rgba(0, 212, 255, 0.32);
  background: rgba(30, 35, 50, 0.55);
  color: #c0caf5;
  font-family: 'NotoSansThai', 'Kanit', sans-serif;
  font-size: 1.05rem;
  font-weight: 400;
  margin: 0;
}

#lobby-ai-chat-panel #lobby-ai-chat-input::placeholder {
  font-family: 'NotoSansThai', 'Kanit', sans-serif;
  font-weight: 400;
  opacity: 0.65;
}

#lobby-ai-chat-panel #lobby-ai-chat-input::-webkit-input-placeholder {
  font-family: 'NotoSansThai', 'Kanit', sans-serif;
  font-weight: 400;
  opacity: 0.65;
}

#lobby-ai-chat-panel #lobby-ai-chat-input::-moz-placeholder {
  font-family: 'NotoSansThai', 'Kanit', sans-serif;
  font-weight: 400;
  opacity: 0.65;
}

#lobby-ai-chat-panel .lobby-ai-chat-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 73px;
  height: 73px;
  flex-shrink: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  outline: none;
  position: relative;
  margin-left: 0rem;         /* ดันออกซ้าย */
  margin-right: -0.7rem;  
}

#lobby-ai-chat-panel .lobby-ai-chat-send:focus,
#lobby-ai-chat-panel .lobby-ai-chat-send:focus-visible {
  outline: none !important;
  box-shadow: none !important;
  border-color: transparent !important;
}

#lobby-ai-chat-panel .lobby-ai-chat-send img {
  width: 102px;
  height: 98px;
  object-fit: contain;
  pointer-events: none;
}

#lobby-ai-chat-panel .lobby-ai-chat-send img:focus,
#lobby-ai-chat-panel .lobby-ai-chat-send img:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

#lobby-ai-chat-panel .lobby-ai-chat-send:hover {
  opacity: 0.9;
}

#lobby-ai-chat-panel .lobby-ai-chat-msg {
  padding: 0.58rem 0.92rem;
  border-radius: 12px;
  max-width: 90%;
  font-family: 'NotoSansThai', 'Kanit', sans-serif;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.33;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  border: none;
  box-shadow: none;
}

#lobby-ai-chat-panel .lobby-ai-chat-msg-user {
  align-self: flex-end;
  text-align: right;
  background-image: url(/Game/img/chat-bubble-me.png);
  background-color: rgba(122, 162, 247, 0.2);
  color: #f787e4;
}

#lobby-ai-chat-panel .lobby-ai-chat-msg-ai {
  align-self: flex-start;
  text-align: left;
  background-image: url(/Game/img/chat-bubble-friend.png);
  background-color: rgba(158, 206, 106, 0.2);
  color: #f2f8ff;
}

#lobby-ai-chat-panel .lobby-ai-chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
  min-height: 28px;
  flex-shrink: 0;
  background-image: url(/Game/img/chat-bubble-friend.png);
  background-color: rgba(158, 206, 106, 0.32);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
}

#lobby-ai-chat-panel .lobby-ai-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f2f8ff;
  animation: lobby-ai-typing-bounce 1.4s ease-in-out infinite both;
}

#lobby-ai-chat-panel .lobby-ai-typing-dot:nth-child(1) { animation-delay: 0s; }
#lobby-ai-chat-panel .lobby-ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
#lobby-ai-chat-panel .lobby-ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes lobby-ai-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

#lobby-ai-chat-panel .lobby-ai-chat-admin-link {
  margin: 0.35rem 0 0 0;
  font-size: 0.75rem;
  flex-shrink: 0;
}

#lobby-ai-chat-panel .lobby-ai-chat-admin-link a {
  color: #9ece6a;
}

/* ==========================================================================
   แชท AI "เทพความรู้" — คุมขนาดบนมือถือแนวนอน
   --------------------------------------------------------------------------
   ต้องวางบล็อกนี้ "ท้ายสุด" ของส่วนแชท AI โดยตั้งใจ:
   กฎ responsive ชุดเดิมอยู่ในบล็อก @media (max-width:932px) ... บรรทัด ~1132
   ซึ่งเขียนไว้ "ก่อน" กฎฐานที่ตั้ง width:454px / height:526px (บรรทัด ~1295)
   specificity เท่ากันเป๊ะ (#id + :not()) → ตัวที่อยู่หลังชนะ
   ผลคือ width ของชุด responsive ไม่เคยมีผลเลย (แผงกว้าง 454px ทุกจอ
   = 49% ที่ 932px, 68% ที่ 667px) มีแต่ max-height ที่รอดเพราะกฎฐานไม่ได้ตั้งไว้

   คุมด้วย "ความสูงจอ" ไม่ใช่ความกว้าง เพราะจอ 956x440 (iPhone 16 Pro Max
   แนวนอน) กว้างเกิน 932px จึงหลุดกฎเดิม แล้วได้ height:526px ในจอสูง 440px
   → หัวแผงโผล่พ้นขอบบน -102px
   ========================================================================== */

/* กันล้นจอทุกอุปกรณ์ ต่อให้หลุดทุก breakpoint */
#lobby-ai-chat-panel:not(.lobby-ai-chat-hidden) {
  width: min(454px, calc(100vw - 1rem));
  max-height: calc(100vh - 1rem);
  max-height: calc(100dvh - 1rem);
}

/* มือถือแนวนอน — ย่อทั้งแผงด้วยตัวคูณเดียว (--ai-s) ให้สัดส่วนคงเดิม */
@media (max-height: 620px) and (orientation: landscape) {
  #lobby-ai-chat-panel:not(.lobby-ai-chat-hidden) {
    --ai-s: 0.62;
    width: min(340px, 40vw);
    height: min(300px, 72svh);
    height: min(300px, 72dvh);
    padding: calc(2.6rem * var(--ai-s));
    font-size: 0.8rem;
    left: max(6px, env(safe-area-inset-left));
    bottom: max(6px, env(safe-area-inset-bottom));
  }

  /* เมื่อคีย์บอร์ดเปิด ให้แผงแชทยึดกลาง visual viewport แทนการติดขอบล่าง */
  #lobby-ai-chat-panel.lobby-ai-chat-keyboard-open:not(.lobby-ai-chat-hidden) {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
  }

  #lobby-ai-chat-panel .lobby-ai-chat-header {
    min-height: calc(50px * var(--ai-s));
    height: calc(50px * var(--ai-s));
    margin: 0 calc(-2rem * var(--ai-s));
    padding: 0 calc(1rem * var(--ai-s));
  }

  #lobby-ai-chat-panel .lobby-ai-chat-title > img:first-child {
    width: calc(100px * var(--ai-s));
    height: calc(116px * var(--ai-s));
    margin-top: calc(-39px * var(--ai-s));
    margin-left: calc(16px * var(--ai-s));
  }

  #lobby-ai-chat-panel .lobby-ai-chat-title-label {
    height: calc(75px * var(--ai-s));
  }

  #lobby-ai-chat-panel .lobby-ai-chat-close,
  #lobby-ai-chat-panel .lobby-ai-chat-close img {
    /* ปุ่มปิดคงพื้นที่แตะ 44px ไว้ ไม่ย่อตาม --ai-s (นิ้วต้องกดติด) */
    width: max(44px, calc(60px * var(--ai-s)));
    height: max(44px, calc(60px * var(--ai-s)));
  }

  #lobby-ai-chat-panel .lobby-ai-chat-form {
    width: calc(100% + 3rem * var(--ai-s));
    padding: calc(0.6rem * var(--ai-s)) 0;
  }

  /* ช่องพิมพ์: สัดส่วนตามดีไซน์คือ 9.5% ของความสูงแผง (เดสก์ท็อป 50px จากแผง 526px)
     เดิมล็อกไว้ 44px ทำให้สูงเกินสัดส่วนไป 1.5-1.85 เท่า (14.7% ที่ 932x430, 17.6% ที่ 667x375)
     จึงย่อตาม --ai-s พร้อมพื้น 32px ให้ยังพอแตะสะดวก → ได้ ~10.7% ใกล้ดีไซน์เดิม */
  #lobby-ai-chat-panel #lobby-ai-chat-input {
    min-height: max(32px, calc(50px * var(--ai-s)));
    height: max(32px, calc(50px * var(--ai-s)));
    padding: 0 calc(0.85rem * var(--ai-s));
    font-size: 14px;
    line-height: 1.2;
    border-radius: 5px;
    border: 0;
    margin-left: 5px;
  }

  /* ข้อความในแชทเดิมค้างที่ 1.05rem (16.8px) ทุกขนาด ไม่ย่อตามแผง — ใหญ่เกินไปบนแผงเล็ก */
  #lobby-ai-chat-panel .lobby-ai-chat-messages {
    font-size: max(12px, calc(1.05rem * var(--ai-s)));
    gap: calc(0.5rem * var(--ai-s));
    padding: calc(0.2rem * var(--ai-s)) calc(0.35rem * var(--ai-s)) calc(0.25rem * var(--ai-s)) 0;
  }

  /* ฟองข้อความมี font-size: 1.05rem ของตัวเอง จึงทับค่าที่ตั้งบนกล่องด้านบน ต้องสั่งตรงนี้ด้วย
     วัดก่อนแก้ที่ 568x320: ฟองคำตอบ AI สูง 130px ในพื้นที่แชท 129px = เต็มพื้นที่ด้วยข้อความเดียว
     (เนื้อหาล้นไปแล้ว 112px) · ที่ 932x430 ล้น 17px, 667x375 ล้น 66px
     พื้นต่ำสุด 12px — ต่ำกว่านี้อ่านภาษาไทยบนมือถือไม่ออก (สระบน/ล่างเบียดกัน) */
  #lobby-ai-chat-panel .lobby-ai-chat-msg {
    font-size: max(12px, calc(1.05rem * var(--ai-s)));
    padding: calc(0.58rem * var(--ai-s)) calc(0.92rem * var(--ai-s));
    border-radius: calc(12px * var(--ai-s));
    line-height: 1.32;
    max-width: 92%;
    margin-right: 4px;
  }

  #lobby-ai-chat-panel .lobby-ai-chat-msg-ai {
    margin-left: 8px;
  }

  /* ฟอง "กำลังพิมพ์" (3 จุด) ก็เป็น px ตายตัวเช่นกัน */
  #lobby-ai-chat-panel .lobby-ai-chat-typing {
    padding: calc(14px * var(--ai-s)) calc(18px * var(--ai-s));
    min-height: calc(28px * var(--ai-s));
    gap: calc(4px * var(--ai-s));
  }

  #lobby-ai-chat-panel .lobby-ai-typing-dot {
    width: max(5px, calc(8px * var(--ai-s)));
    height: max(5px, calc(8px * var(--ai-s)));
  }

  #lobby-ai-chat-panel .lobby-ai-chat-send {
    width: max(44px, calc(73px * var(--ai-s)));
    height: max(44px, calc(73px * var(--ai-s)));
    margin-right: calc(-0.7rem * var(--ai-s));
  }

  #lobby-ai-chat-panel .lobby-ai-chat-send img {
    width: calc(102px * var(--ai-s));
    height: calc(98px * var(--ai-s));
  }

  #lobby-ai-chat-panel .lobby-ai-chat-admin-link {
    margin-top: calc(0.35rem * var(--ai-s));
    font-size: calc(0.75rem * var(--ai-s));
  }
}

/* แนวนอนเตี้ยมาก (เช่น 667x375, 568x320) — ย่ออีกขั้น */
@media (max-height: 400px) and (orientation: landscape) {
  #lobby-ai-chat-panel:not(.lobby-ai-chat-hidden) {
    --ai-s: 0.5;
    width: min(300px, 44vw);
    height: min(250px, 78svh);
    height: min(250px, 78dvh);
  }
}

/* ---- Guide ทีละขั้น — asset /Main-Lobby/IMAGE/guide (guide-01…05, btn-next) ---- */
.lobby-guide-dim {
  position: fixed;
  inset: 0;
  z-index: 21;
  background: rgba(2, 8, 22, 0.74);
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.lobby-guide-dim.hidden {
  display: none !important;
}

/* Overlay cutout — เจาะรูตรงปุ่มเป้าหมาย มืดทั้งจอยกเว้นจุดไฮไลต์ */
.lobby-guide-focus {
  position: fixed;
  z-index: 21;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border: 2px solid rgba(34, 211, 238, 0.85);
  border-radius: 14px;
  box-shadow:
    0 0 0 9999px rgba(2, 8, 22, 0.78),
    0 0 24px 4px rgba(34, 211, 238, 0.45),
    inset 0 0 10px rgba(34, 211, 238, 0.12);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, left 0.25s ease, top 0.25s ease, width 0.25s ease, height 0.25s ease, border-radius 0.25s ease;
  box-sizing: border-box;
}

.lobby-guide-focus:not(.hidden) {
  opacity: 1;
}

.lobby-guide-focus.hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

.lobby-guide-bar {
  position: fixed;
  z-index: 22;
  left: 0;
  right: 0;
  bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
  pointer-events: none;
}

.lobby-guide-bar--top {
  top: 0;
  bottom: auto;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: 0;
}

.lobby-guide-bar:not(.hidden) {
  pointer-events: none;
}

/* รูป guide ไม่ดักคลิก — คลิกตกไปที่เลเยอร์มืดด้านล่าง; กดได้เฉพาะปุ่มถัดไป/รับทราบ */
.lobby-guide-bar:not(.hidden) .lobby-guide-img {
  pointer-events: none;
}

.lobby-guide-bar:not(.hidden) .lobby-guide-next {
  pointer-events: auto;
}

.lobby-guide-frame {
  --lobby-guide-next-width: 10%; /* ขนาดปุ่ม next เทียบกับความกว้าง guide-frame */
  position: relative;
  width: 97vw;
  max-width: none;
  aspect-ratio: 1863 / 251;
  margin: 0 auto;
}

.lobby-guide-img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: contain;
  object-position: bottom center;
}

.lobby-guide-bar--top .lobby-guide-img {
  object-position: top center;
}

/* ปุ่ม "ถัดไป" ของ overlay สอนเล่น — ต้องกดได้อย่างน้อย 44x44px ทุกขนาดจอ
   (เดิมเหลือ 32px ที่ 667x375 และ 19px ที่ 390x844)
   ขยายเฉพาะกล่องปุ่ม ส่วนภาพยังยึดมุมขวาล่างเท่าเดิม → ตำแหน่ง/ขนาดภาพไม่ขยับ */
.lobby-guide-next {
  position: absolute;
  right: 1%;
  bottom: 16%;
  width: var(--lobby-guide-next-width);
  min-width: 44px;
  min-height: 44px;
  aspect-ratio: 169 / 84;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  filter: drop-shadow(0 0 8px rgba(236, 72, 153, 0.5));
}

/* touch target สำรอง เผื่อกฎอื่นบีบกล่องปุ่มให้เล็กลง (แพตเทิร์นเดียวกับ .qb-card-start::after) */
.lobby-guide-next::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  min-width: 44px;
  min-height: 44px;
  background: transparent;
}

.lobby-guide-bar--top .lobby-guide-next {
  right: 1%;
  bottom: 16%;
}

.lobby-guide-next img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: right bottom; /* กล่องปุ่มโตขึ้นได้ แต่ภาพยังทับตำแหน่งเดิมบนแถบ guide */
}

.lobby-guide-bar.hidden {
  display: none !important;
}

/* เว้นพื้นที่ footer เฉพาะตอนแถบคำแนะนำอยู่ล่าง (ขั้น 1–3)
   [fix] เดิมกฎนี้ทำงานทุกขนาดจอ → กล่อง .lobby-footer สูงขึ้น 42vh แล้ว
   .lobby-footer-center (absolute + bottom) ถูกดันตกใต้ขอบจอ ซึ่งบนแนวนอน
   .lobby-ui ตั้ง overflow:hidden ไว้ หน้าจึงไม่ scroll → ปุ่ม "เริ่มภารกิจ" กับ
   "Quiz Battle" ถูกตัดหายถาวร  ตอนนี้จำกัดให้ทำงานเฉพาะแนวตั้งซึ่งหน้าเลื่อนได้จริง */
@media (orientation: portrait) and (min-height: 640px) {
  body.lobby-guide-active:not(.lobby-guide-top-step) .lobby-footer {
    padding-bottom: min(42vh, 280px);
  }
}

@media (orientation: portrait) and (min-height: 640px) and (max-width: 767px) {
  body.lobby-guide-active:not(.lobby-guide-top-step) .lobby-footer {
    padding-bottom: min(48vh, 320px);
  }
}

/* ---- Howto overlay ---- */
.lobby-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 6, 18, 0.88);
  backdrop-filter: blur(8px);
}

.lobby-overlay.hidden {
  display: none !important;
}

.lobby-howto-inner {
  max-width: min(96vw, 560px);
  text-align: center;
}

.lobby-howto-inner > img:first-of-type {
  max-width: 100%;
  height: auto;
}

.lobby-howto-close {
  margin-top: 12px;
}

.lobby-icon-btn {
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

.lobby-howto-close img {
  max-width: min(88vw, 420px);
  height: auto;
}

/* ---- Toast ---- */
.lobby-toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%);
  max-width: min(90vw, 360px);
  padding: 10px 14px;
  font-size: 0.85rem;
  text-align: center;
  color: #ecfeff;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(34, 211, 238, 0.4);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.lobby-toast.lobby-toast--show {
  opacity: 1;
}

/* ---- Character lock to platform ---- */
.lobby-character-center {
  position: fixed !important;
  left: var(--lobby-character-anchor-x) !important;
  bottom: calc(var(--lobby-character-stand-y) + var(--lobby-character-foot-offset)) !important;
  transform: translateX(var(--lobby-character-anchor-shift-x)) !important;
  transform-origin: center bottom !important; /* pivot ที่เท้า */
  width: auto !important;
  height: var(--lobby-character-height) !important;
  min-height: 0 !important;
  z-index: 4;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.lobby-character-img {
  height: 100% !important;
  width: auto !important;
  max-height: none !important;
  max-width: none !important;
  object-fit: contain;
  object-position: 50% var(--lobby-character-anchor-y);
}

/* ---- Cloth button image ratio lock ---- */
.lobby-btn-cloth {
  --lobby-btn-cloth-shift-y: -50px; /* ขยับตำแหน่งปุ่มขึ้น/ลง */
  max-width: none !important;
  width: auto !important;
  transform: translateY(var(--lobby-btn-cloth-shift-y));
}

.lobby-btn-cloth-img {
  --lobby-btn-cloth-height: 20cqh; /* ปรับความสูงปุ่มห้องแต่งตัว */
  display: block;
  height: var(--lobby-btn-cloth-height) !important;
  width: calc(var(--lobby-btn-cloth-height) * (161 / 176)) !important;
  aspect-ratio: 161 / 176;
  max-width: none !important;
  object-fit: contain;
}

/* ---- Footer buttons size control (cqh) ---- */
.lobby-footer {
  --lobby-footer-side-btn-width: 20cqh; /* AI chat */
  --lobby-footer-profile-btn-width: 12cqh; /* profile / tutorial */
  --lobby-footer-main-btn-width: 40cqh; /* start / quiz */
  --lobby-footer-center-gap: 1.1cqh;
  --lobby-footer-tutorial-img-width: 9.6cqh;
}

.lobby-footer-left {
  width: var(--lobby-footer-side-btn-width) !important;
  max-width: var(--lobby-footer-side-btn-width) !important;
}

.lobby-footer-right {
  width: var(--lobby-footer-profile-btn-width) !important;
  max-width: var(--lobby-footer-profile-btn-width) !important;
}

.lobby-btn-ai-chat {
  width: var(--lobby-footer-side-btn-width) !important;
  max-width: var(--lobby-footer-side-btn-width) !important;
  transform: translateX(-1cqw) !important;
}

.lobby-btn-profile,
.lobby-btn-tutorial {
  width: var(--lobby-footer-profile-btn-width) !important;
  max-width: var(--lobby-footer-profile-btn-width) !important;
}

.lobby-btn-tutorial-img {
  width: var(--lobby-footer-tutorial-img-width) !important;
}

.lobby-footer-center {
  gap: var(--lobby-footer-center-gap) !important;
}

.lobby-btn-start,
.lobby-btn-quiz {
  width: var(--lobby-footer-main-btn-width) !important;
  max-width: var(--lobby-footer-main-btn-width) !important;
}

/* ---- Header buttons size control (cqh) ---- */
.lobby-header {
  --lobby-header-daily-btn-width: 36cqh;
  --lobby-header-tutorial-size: 12cqh;
}

/* ---- แท็บเล็ตแนวตั้ง (≥768px, portrait) ----
   ค่า cqh ทั้งชุดอิงความสูงจอล้วน ๆ พอจอสูงกว่ากว้าง (เช่น 768x1024)
   ปุ่ม start/quiz กลายเป็น 40cqh = 410px ต่อปุ่ม (410+410+gap > 768) และปุ่ม
   daily กลายเป็น 36cqh = 369px จนล้นขอบขวา — จึงเพิ่มเพดานตามความกว้างจอ */
@media (min-width: 768px) and (orientation: portrait) {
  .lobby-footer {
    --lobby-footer-main-btn-width: min(40cqh, 42vw);
    --lobby-footer-side-btn-width: min(20cqh, 16vw);
    --lobby-footer-profile-btn-width: min(12cqh, 11vw);
    --lobby-footer-tutorial-img-width: min(9.6cqh, 9vw);
  }

  .lobby-header {
    --lobby-header-daily-btn-width: min(36cqh, 34vw);
    --lobby-header-tutorial-size: min(12cqh, 12vw);
  }

  /* กันปุ่มคู่กลางล้นซ้าย/ขวา และกันไม่ให้ทับปุ่มเทพความรู้ / โปรไฟล์ที่มุมล่าง */
  .lobby-footer-center {
    max-width: calc(100vw - 2 * (16vw + 24px));
  }
}

.lobby-header .lobby-btn-daily {
  width: var(--lobby-header-daily-btn-width) !important;
  max-width: var(--lobby-header-daily-btn-width) !important;
}

.lobby-header .lobby-daily-img {
  width: 100% !important;
  max-width: 100% !important;
}

.lobby-header .lobby-header-row2-left .lobby-btn-tutorial {
  width: var(--lobby-header-tutorial-size) !important;
  max-width: var(--lobby-header-tutorial-size) !important;
}

.lobby-header .lobby-btn-tutorial-img {
  width: var(--lobby-header-tutorial-size) !important;
  max-width: var(--lobby-header-tutorial-size) !important;
  height: auto;
}

/* ---- Header columns width lock ---- */
.lobby-header {
  --lobby-header-left-col: 40%;
  --lobby-header-right-col: 40%;
  grid-template-columns: minmax(0, var(--lobby-header-left-col)) minmax(0, var(--lobby-header-right-col)) !important;
  justify-content: space-between;
}

.lobby-profile-panel,
.lobby-news-wrap,
.lobby-btn-daily {
  width: 100% !important;
  max-width: 100% !important;
}

/* ---- Header profile/news ratio lock + cqh sizing ---- */
.lobby-header {
  --lobby-profile-panel-height: 18cqh; /* ปรับความสูง profile panel */
  --lobby-news-wrap-height: 20cqh; /* ปรับความสูง news panel */
  --lobby-news-wrap-shift-y: 1.2cqh; /* ขยับ news panel ลง */
  --lobby-news-label-height: 3.18cqh; /* ปรับความสูง news.png */
  --lobby-news-label-shift-y: -1.8cqh; /* ขยับ news.png ลง */
}

.lobby-profile-panel {
  height: var(--lobby-profile-panel-height) !important;
  width: calc(var(--lobby-profile-panel-height) * (491 / 198)) !important;
  max-width: 100% !important;
  aspect-ratio: 491 / 198;
  transform: translateX(-0.5cqw);
}

.lobby-profile-bg {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  aspect-ratio: 491 / 198;
  object-fit: contain;
}

.lobby-news-wrap {
  /* [2026-08-10] เดิมตรึง height: 20cqh คู่กับ width ที่คำนวณจากความสูง แต่ `max-width:100%`
     บีบเฉพาะ "ความกว้าง" เมื่อคอลัมน์กริดแคบกว่าที่คำนวณ ⇒ กล่องเพี้ยนอัตราส่วน
     (วัดจริงที่ viewport 961px: ควรได้ 441.7×182 แต่โดนบีบเหลือ 362×182 = 1.99 แทน 2.427)
     ภาพกรอบ object-fit:contain จึงหดลอยกลางกล่อง (letterbox) แล้วช่องแบนเนอร์ที่วางด้วย %
     ของกล่องก็หลุดออกนอกกรอบขาว (สูงเกิน 23px เลื่อนขึ้น 12px)
     ให้ aspect-ratio คุมความสูงแทน — จอที่ไม่โดนบีบได้ค่าเท่าเดิมทุกประการ (no-op) */
  height: auto !important;
  width: calc(var(--lobby-news-wrap-height) * (517 / 213)) !important;
  max-width: 100% !important;
  aspect-ratio: 517 / 213;
  transform: translateY(var(--lobby-news-wrap-shift-y));
  margin-right: -1%;
}

.lobby-news-bg {
  width: 100% !important;
  height: 100% !important;
  aspect-ratio: 517 / 213;
  object-fit: contain;
}

.lobby-news-img {
  left: 50% !important;
  right: auto !important;
  top: calc(8% + var(--lobby-news-label-shift-y)) !important;
  height: var(--lobby-news-label-height) !important;
  width: calc(var(--lobby-news-label-height) * (459 / 34)) !important;
  max-width: 92% !important;
  aspect-ratio: 459 / 34;
  transform: translateX(-50%) !important;
}

/* ---- Profile panel children scale with parent ---- */
.lobby-profile-panel {
  /* [2026-08-23] เจ้าของงานสั่งให้การ์ดโปรไฟล์กลับไปเหมือน PROD — ถอดพื้นขั้นต่ำ px ออก
     ⚠️ นี่คือการ "ย้อน" การแก้เมื่อ 22 ส.ค. ที่ทำเพราะลูกค้าคอมเมนต์ว่าตัวหนังสือเล็กเกินไป
        (AGENT ID วัดได้ 5.7px บนมือถือ · ClickUp 86d43w4hv) ถ้าลูกค้าทักเรื่องนี้อีก ให้ย้อนกลับมา
     ผลที่วัดได้หลังถอดพื้น: 667x375 -> ชื่อ 13.125px / meta 5.4375px  (เท่า PROD ทุกหลัก)
     ไม่แตะ --lobby-leaderboard-font-size (บรรทัด ~507) เจ้าของงานสั่งเฉพาะบล็อกโปรไฟล์ */
  --lobby-profile-name-font-size: 3.5cqh;
  --lobby-profile-meta-font-size: 1.45cqh;  /* [2026-08-22] เดิม 1.45cqh ล้วน -> วัดจริงได้ 5.7px บนมือถือ
     ตัวแปรคู่นี้คือ "ตัวที่ชนะจริง" เพราะกฎที่ใช้มันอยู่ท้ายไฟล์ ทับกฎ .lobby-profile-meta ทุกอันข้างบน */
  --lobby-profile-text-gap: 0.2cqh; /* ระยะห่างระหว่างข้อความ 3 บรรทัด */
  --lobby-profile-coin-size: 2.2em; /* ขนาดไอคอนเหรียญ */
  --lobby-profile-avatar-size: 27%; /* ขนาดกรอบ avatar */
  --lobby-profile-avatar-shift-x: 17%; /* ขยับกรอบ avatar ซ้าย/ขวา */
  --lobby-profile-avatar-shift-y: -0.8cqh; /* ขยับกรอบ avatar ขึ้น/ลง */
  --lobby-profile-avatar-radius: 5%;
  --lobby-avatar-mask-scale: 1.1; /* ปรับขนาดรูป avatar ภายใน mask */
  --lobby-avatar-mask-shift-y: 0%; /* จูนตำแหน่งรูป avatar ขึ้น/ลง */
  --lobby-profile-info-shift-x: 5%; /* ขยับข้อมูลโปรไฟล์ไปทางขวา */
}

.lobby-profile-inner {
  gap: 2%;
  padding: 8% 6% 8% 5%;
}

.lobby-avatar-wrap {
  width: var(--lobby-profile-avatar-size) !important;
  flex: 0 0 var(--lobby-profile-avatar-size) !important;
  max-width: var(--lobby-profile-avatar-size) !important;
  min-width: 0;
  height: auto !important;
  aspect-ratio: 1 / 1;
  overflow: hidden !important;
  position: relative;
  isolation: isolate;
  clip-path: inset(0 round var(--lobby-profile-avatar-radius));
  padding-left: 0;
  border-radius: var(--lobby-profile-avatar-radius);
  transform: translate(var(--lobby-profile-avatar-shift-x), var(--lobby-profile-avatar-shift-y));
}

.lobby-avatar-mask {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  transform: translateY(var(--lobby-avatar-mask-shift-y)) scale(var(--lobby-avatar-mask-scale)) !important;
  transform-origin: center top;
  object-fit: cover;
  object-position: center top;
}

.lobby-profile-info {
  padding-left: 1.2%;
  transform: translateX(var(--lobby-profile-info-shift-x));
}

.lobby-profile-name {
  margin: 0 0 var(--lobby-profile-text-gap) !important;
  font-size: var(--lobby-profile-name-font-size);
}

.lobby-profile-meta,
.lobby-profile-coins {
  margin: 0 0 var(--lobby-profile-text-gap) !important;
  font-size: var(--lobby-profile-meta-font-size);
}

.lobby-profile-coins {
  margin-bottom: 0 !important;
}

.lobby-coin-icon {
  width: var(--lobby-profile-coin-size) !important;
  height: var(--lobby-profile-coin-size) !important;
}

/* ================================================== */
/*  Animations — entrance (ตอนขึ้น) / press (ตอนกด)   */
/*               accents (ตอนเปลี่ยน/แจ้งเตือน)        */
/* ================================================== */
@keyframes lb-rise { from { opacity: 0; transform: translateY(22px); } to { opacity: 1; transform: translateY(0); } }
@keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes lb-from-left { from { opacity: 0; transform: translateX(-26px); } to { opacity: 1; transform: translateX(0); } }
@keyframes lb-from-right { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: translateX(0); } }
@keyframes lb-char-in { from { opacity: 0; transform: translateY(18px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes lb-dot-pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.35); opacity: .55; } }

/* press feedback — เปิดเสมอ (ทุกปุ่ม) */
.lobby-btn-tutorial, .lobby-btn-daily, .lobby-btn-cloth, .lobby-btn-ai-chat,
.lobby-btn-start, .lobby-btn-quiz, .lobby-btn-profile, .lobby-guide-next, .lobby-icon-btn {
  transition: transform .13s ease, filter .2s;
  -webkit-tap-highlight-color: transparent;
}
.lobby-btn-tutorial:hover, .lobby-btn-daily:hover, .lobby-btn-cloth:hover, .lobby-btn-ai-chat:hover,
.lobby-btn-start:hover, .lobby-btn-quiz:hover, .lobby-btn-profile:hover,
.lobby-guide-next:hover, .lobby-icon-btn:hover { filter: brightness(1.13); }
.lobby-btn-tutorial:active, .lobby-btn-daily:active, .lobby-btn-cloth:active, .lobby-btn-ai-chat:active,
.lobby-btn-profile:active, .lobby-guide-next:active, .lobby-icon-btn:active { transform: scale(.91); }
.lobby-btn-start:active, .lobby-btn-quiz:active { transform: scale(.95); }
/* [2026-09-15] ชีต 15/9 ข้อ 2 — ปุ่มแต่งตัวมี transform: translateY(--lobby-btn-cloth-shift-y) อยู่แล้ว
   กฎ scale(.91) ด้านบนเขียนทับทั้งค่า ⇒ ตอนกดปุ่มกระโดดลง 50px แล้วเด้งกลับ ต้องคง translateY ไว้ด้วย */
.lobby-btn-cloth:active { transform: translateY(var(--lobby-btn-cloth-shift-y)) scale(.91); }

/* [2026-09-15] ชีต 15/9 ข้อ 2 — Chrome Android / iOS กดปุ่มแต่งตัว (#btn-cloth) ไม่ติด
   กล่อง <header> ใส (z-index:6) กับช่อง .lobby-header-row2-left (กว้าง 1fr) ลากลงมาทับครึ่งบนของปุ่ม
   ซึ่งอยู่ใน .lobby-character-area (z-index:3) บนจอแนวนอนเตี้ย 330–430px
   วัด elementFromPoint กลางปุ่มก่อนแก้: 800x330 กดติด 22% · 844x390 44% · 932x430 67% (แตะกลางปุ่มไม่เปิด)
   แก้โดยให้ตัวกล่อง header กับช่องแถว 2 ปล่อยการแตะทะลุ แล้วเปิดคืนให้ลูกทุกตัว
   (กรอบโปรไฟล์, ป้ายข่าว, #btn-daily, #btn-leaderboard-mb และ #btn-tutorial ในช่องแถว 2) ⇒ ของที่กดได้ยังกดได้เหมือนเดิม
   ไม่ผูกกับ media query เพราะกล่องใสไม่มีหน้าที่รับคลิกบนจอไหนเลย */
.lobby-header { pointer-events: none; }
.lobby-header > *,
.lobby-header-row2-left > * { pointer-events: auto; }
.lobby-header > .lobby-header-row2-left { pointer-events: none; }

.lobby-leaderboard-list li { transition: filter .18s ease, transform .18s ease; }
.lobby-leaderboard-list li:hover { filter: brightness(1.12); transform: translateX(2px); }

@media (prefers-reduced-motion: no-preference) {
  /* entrance: โผล่ไล่ทีละส่วน */
  .lobby-profile-panel { animation: lb-from-left .55s cubic-bezier(.2,.85,.25,1) .05s both; }
  .lobby-news-wrap { animation: lb-rise .55s cubic-bezier(.2,.85,.25,1) .12s both; }
  .lobby-header-row2-left { animation: lb-fade .5s ease .18s both; }
  .lobby-btn-daily { animation: lb-fade .5s ease .2s backwards; }
  .lobby-center-left { animation: lb-fade .5s ease .24s both; }
  .lobby-character-center { animation: lb-char-in .7s cubic-bezier(.2,.85,.25,1) .22s both; }
  .lobby-leaderboard { animation: lb-from-right .6s cubic-bezier(.2,.85,.25,1) .3s both; }
  .lobby-footer { animation: lb-rise .6s cubic-bezier(.2,.85,.25,1) .4s both; }
  /* accent: จุดแจ้งเตือน daily เต้น */
  .lobby-daily-dot { animation: lb-dot-pulse 1.6s ease-in-out infinite; }
}

/* ========== MOBILE LANDSCAPE — daily กว้างเท่า leaderboard เป๊ะ ==========
   ใช้ตัวแปรเดียวบน body (vh) แล้วบังคับทั้งคู่ — กัน cqh คนละ context
   และกันสูตร min(..., 24vw) ทำให้กล่องกับภาพ object-fit ไม่เท่ากัน */
@media (orientation: landscape) and (max-height: 500px) {
  body.lobby-page {
    --lobby-rail-h: min(44svh, 240px);
    --lobby-rail-w: calc(var(--lobby-rail-h) * 417 / 443);
  }

  .lobby-header {
    --lobby-header-daily-btn-width: var(--lobby-rail-w);
  }

  .lobby-header .lobby-btn-daily {
    width: var(--lobby-rail-w) !important;
    max-width: var(--lobby-rail-w) !important;
  }

  .lobby-leaderboard {
    --lobby-leaderboard-height: var(--lobby-rail-h);
    height: var(--lobby-rail-h) !important;
    width: var(--lobby-rail-w) !important;
    max-width: var(--lobby-rail-w) !important;
  }
}

@media (orientation: landscape) and (max-height: 380px) {
  body.lobby-page {
    --lobby-rail-h: min(40svh, 180px);
    --lobby-rail-w: calc(var(--lobby-rail-h) * 417 / 443);
  }

  .lobby-header {
    --lobby-header-daily-btn-width: var(--lobby-rail-w);
  }

  .lobby-header .lobby-btn-daily {
    width: var(--lobby-rail-w) !important;
    max-width: var(--lobby-rail-w) !important;
  }

  .lobby-leaderboard {
    --lobby-leaderboard-height: var(--lobby-rail-h);
    height: var(--lobby-rail-h) !important;
    width: var(--lobby-rail-w) !important;
    max-width: var(--lobby-rail-w) !important;
  }
}

/* ==========================================================================
   [2026-08-04] มือถือแนวนอน — ราง daily + leaderboard คิดจาก "งบความสูงจริง"
   --------------------------------------------------------------------------
   อาการที่แก้ (วัดจริงด้วย /testcase/responsive.html)
     1) .lobby-leaderboard ตั้ง top: 19em ซึ่งผูกกับ font-size ที่สืบทอดมา
        จอกว้างเกิน 932px ไม่มีกฎไหนลด font-size ⇒ 19em = 16px × 19 = 304px "ตายตัว"
        ทุกจอ วัดที่ 960×420 ถึง 1180×430 ได้ bottom = -35 ถึง -69px
        คือกระดานยื่นพ้นขอบล่างจอ และทับปุ่มโปรไฟล์มุมขวาล่างเต็ม ๆ (50×50)
     2) ความสูงรางเดิมใช้ vh ขณะที่ธาตุอื่นทั้งหน้าใช้ cqh
        บนเดสก์ท็อป vh == cqh จึงดู "ปกติ" ใน DevTools
        แต่บนมือถือจริง vh = large viewport (ไม่หักแถบ URL) ส่วน cqh = small viewport
        ⇒ รางใหญ่เกินส่วนอื่นราว 16% แล้วไปเบียดของข้างล่าง
        นี่คือสาเหตุที่ "Inspect บนเดสก์ท็อปไม่เหมือนมือถือจริง"
     3) มี tier ซ้อนกันสองชั้น (max-height:500px กับ 380px) ทำให้ความสูงกระดาน
        กระโดด 40% ⇄ 44% ของจอ ตรงรอยต่อ

   วิธีคิดใหม่ — ไม่ใช้ breakpoint คุมขนาด ใช้ "งบ" ที่เหลือจริง
     งบของราง = จอ − ข่าว − footer − ช่องไฟ
     รางวางซ้อนกันสองชิ้น: daily (กว้าง/สูง 416/213) กับ leaderboard (417/443)
     daily สูง = rail_w / 1.953 = rail_h × (417/443) / 1.953 = rail_h × 0.4818
     ⇒ งบ = rail_h × (1 + 0.4818) = rail_h × 1.4818
     ⇒ rail_h = งบ / 1.4818
     วัดจริงหลังแก้: กระดานคงที่ 35.4% ของความสูงจอทุกขนาดตั้งแต่ 262 ถึง 560px
     (เดิมกระโดด 40% ⇄ 44% ตรงรอยต่อ tier) — ไม่มีขั้น ไม่มีหน้าผา

   ยึด svh ไม่ใช่ vh/dvh เพราะ cqh ที่ทั้งหน้าใช้อยู่ = small viewport พอดี
   ใช้หน่วยเดียวกันทั้งหน้า ค่าถึงจะสอดคล้องกันบนมือถือจริง
   ========================================================================== */
@media (orientation: landscape) and (max-height: 620px) {
  body.lobby-page {
    --lobby-news-h: 20svh;                        /* = --lobby-news-wrap-height */
    --lobby-footer-h: 22svh;                      /* วัดจริงได้ 21.3–21.8% ทุกขนาด */
    --lobby-rail-gap: clamp(4px, 1.4svh, 12px);
    --lobby-rail-right: clamp(6px, 1.6svh, 16px); /* ระยะขอบขวาร่วมของ header + กระดาน */
    /* ช่องไฟ 4 ช่วงที่กินความสูงจริง: padding บน header, gap ระหว่างแถว header,
       ช่องว่าง daily→กระดาน, ช่องว่างกระดาน→footer */
    --lobby-rail-budget: calc(100svh - var(--lobby-news-h) - var(--lobby-footer-h) - (var(--lobby-rail-gap) * 4));
    --lobby-rail-h: clamp(64px, min(36svh, var(--lobby-rail-budget) / 1.4818), 230px);
    --lobby-rail-w: calc(var(--lobby-rail-h) * 417 / 443);
    /* ธงบอก lobby.js ว่า CSS ยึดกระดานไว้กับขอบล่างแล้ว อย่ามาตั้ง top ทับ */
    --lobby-board-auto: 1;
  }

  /* .lobby-leaderboard เป็น absolute → วัด right จาก "padding box" ของ .lobby-ui
     ส่วน header วัดจาก content box (คือเข้ามาอีกเท่ากับ padding ของ .lobby-ui)
     ต้องบวกกลับให้เท่ากัน ไม่งั้นสองแผงที่วางซ้อนกันจะเหลื่อมขอบขวา 8px */
  body.lobby-page .lobby-ui {
    --lobby-ui-pad-r: max(8px, env(safe-area-inset-right));
    padding-right: var(--lobby-ui-pad-r);
  }

  /* header ยังใช้ padding ขนาดเดสก์ท็อป (16px) ในย่านจอกว้างเกิน 932px
     บล็อก @media (min-width:933px) เดิมแก้แค่ footer ไม่เคยย่อ header
     ⇒ แถวข่าว+daily สูงเกินงบ แล้วดันชนกระดาน วัดได้ทับ 12px ที่ 960×420
     บังคับให้ header ย่อเท่ากันทุกความกว้าง โมเดลงบด้านบนถึงจะเป็นจริง */
  body.lobby-page .lobby-header {
    padding: var(--lobby-rail-gap) var(--lobby-rail-right) 0
             max(var(--lobby-rail-right), env(safe-area-inset-left));
    gap: var(--lobby-rail-gap) clamp(8px, 1.5vw, 24px);
  }

  /* [2026-09-01] ย่านนี้ทับ "ความกว้างที่เรนเดอร์" ของปุ่มรางวัลไว้ แต่ไม่ได้อัปเดต
     --lobby-header-daily-btn-width ตาม (ต่างจากบล็อก max-height 500/380 ที่ตั้งไว้ครบ)
     ⇒ ตัวแปรกับของจริงไม่ตรงกัน ใครมาอ้างตัวแปรนี้จะได้ค่าผิด (ปุ่ม LEADERBOARD อ้างอยู่)
     ตั้งให้ตรงกันเสียเลย — ค่าเท่าเดิมทุกประการ ปุ่มรางวัลจึงไม่ขยับ */
  body.lobby-page .lobby-header {
    --lobby-header-daily-btn-width: var(--lobby-rail-w);
  }

  body.lobby-page .lobby-header .lobby-btn-daily {
    width: var(--lobby-rail-w) !important;
    max-width: var(--lobby-rail-w) !important;
  }

  /* ยึดจากขอบล่างเหนือ footer — ไม่ต้องพึ่ง JS และทับ footer ไม่ได้เลยตามโครงสร้าง */
  body.lobby-page .lobby-leaderboard {
    top: auto !important;
    bottom: calc(var(--lobby-footer-h) + var(--lobby-rail-gap)) !important;
    right: calc(var(--lobby-rail-right) + var(--lobby-ui-pad-r, 0px)) !important;
    height: var(--lobby-rail-h) !important;
    width: var(--lobby-rail-w) !important;
    max-width: var(--lobby-rail-w) !important;
    --lobby-leaderboard-height: var(--lobby-rail-h);
  }
}

/* แท็บเล็ต/มือถือจอสัมผัสแนวนอน: หน้า Lobby เป็นจอเดียว ไม่ให้ปัดเลื่อนหรือซูม */
@media (orientation: landscape) and (hover: none) and (pointer: coarse) {
  html,
  body.lobby-page {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body.lobby-page {
    position: fixed;
    inset: 0;
    touch-action: manipulation;
  }

  body.lobby-page .lobby-ui {
    height: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  /* แถวปุ่มรองของ header ต้องจัดกึ่งกลางร่วมกันบนแท็บเล็ตแนวนอน */
  .lobby-header .lobby-header-row2-left,
  .lobby-header .lobby-btn-daily {
    grid-row: 2;
    align-self: center;
    margin-top: 0;
    margin-bottom: 0;
  }

  .lobby-center-left {
    transform: translate(calc(-50% - 12vw), -4em);
  }

  /* visual viewport จะย่อเมื่อคีย์บอร์ดเปิด: ย้ายแผงแชทมายังกึ่งกลางเสมอ */
  #lobby-ai-chat-panel.lobby-ai-chat-keyboard-open:not(.lobby-ai-chat-hidden) {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    max-height: calc(100dvh - 1rem);
  }
}

/* ============================================================================
   [2026-08-06] Task 11 — Popup พรีโหลดทรัพยากรครั้งแรก (ดู logic ใน lobby.js)
   ทำเป็นแถบบนสุดของจอ (ไม่ใช่ modal เต็มจอ) — ไม่บังฉากล็อบบี้ที่โต้ตอบได้อยู่แล้ว
   สูงคงที่ไม่ผูกกับความสูงจอ จึงพอดีกับแนวนอนมือถือ 926×428 โดยไม่ต้องมี media query เพิ่ม
   ============================================================================ */
.mlpre-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10150;
  display: flex;
  justify-content: center;
  padding: max(8px, env(safe-area-inset-top)) 10px 0;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-14px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.mlpre-overlay.is-hidden {
  display: none !important;
}

.mlpre-overlay.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.mlpre-card {
  pointer-events: auto;
  width: min(560px, 100%);
  max-width: calc(100vw - 20px);
  background: linear-gradient(180deg, rgba(10, 18, 34, 0.96), rgba(6, 12, 24, 0.96));
  border: 1px solid rgba(34, 211, 238, 0.4);
  border-top: none;
  border-radius: 0 0 16px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 22px rgba(34, 211, 238, 0.18);
  padding: 10px 16px 12px;
  color: #eaf6ff;
  font-family: 'NotoSansThai', 'Kanit', sans-serif !important;
}

.mlpre-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mlpre-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600 !important;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mlpre-title::before {
  content: '';
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22d3ee;
  box-shadow: 0 0 8px 2px rgba(34, 211, 238, 0.8);
  animation: mlpre-pulse 1.4s ease-in-out infinite;
}

@keyframes mlpre-pulse {
  0%, 100% { opacity: 0.5; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.15); }
}

.mlpre-skip {
  display: none;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.06);
  color: #eaf6ff;
  font-family: 'NotoSansThai', 'Kanit', sans-serif !important;
  font-size: 13px;
  font-weight: 500 !important;
  cursor: pointer;
  opacity: 0;
  transition: background 0.15s ease, opacity 0.25s ease;
}

.mlpre-skip.is-visible {
  display: inline-flex;
  opacity: 1;
}

.mlpre-skip:active {
  background: rgba(255, 255, 255, 0.16);
}

.mlpre-bar-wrap {
  position: relative;
  margin-top: 8px;
  width: 100%;
  height: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.22);
  overflow: hidden;
}

.mlpre-bar-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0891b2, #22d3ee, #7df9ff);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.6);
  transition: width 0.25s ease;
}

.mlpre-row-bottom {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.mlpre-subtitle {
  font-size: 11px;
  color: #9db8cc;
  line-height: 1.35;
}

.mlpre-meta {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 500 !important;
  color: #bdeeff;
  white-space: nowrap;
}

.mlpre-pct {
  color: #7df9ff;
  font-weight: 600 !important;
}

@media (prefers-reduced-motion: reduce) {
  .mlpre-overlay,
  .mlpre-skip {
    transition-duration: 0.01ms !important;
  }
  .mlpre-title::before {
    animation: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   [2026-08-22] กระดานอันดับบนมือถือแนวนอน — คืนพื้นที่ให้ชื่อผู้เล่น

   ที่มา: คอมเมนต์ลูกค้า 19 ส.ค. "ตัวหนังสือเล็กเกินไป" (พบ ~22 จุด)
   พอตั้งพื้นขนาดตัวอักษรให้อ่านออก ชื่อในกระดานอันดับกลับถูกตัดเหลือ "ผู้..." เพราะที่ไม่พอ

   วัดของจริงบนมือถือแนวนอน 844x390:
     กระดานทั้งแผงกว้าง  79px
       ไอคอน   28px  (35% ของทั้งแผง)
       ชื่อ+คดี 19px
       คะแนน   21px
     บรรทัด "(คดี : คดีที่ 10)" ต้องการ 59px แต่ได้ 19px -> แสดงเป็นขยะอยู่แล้ว

   ⇒ ที่แคบขนาดนี้ ชื่อไม่มีทางพอไม่ว่าจะย่อตัวอักษรแค่ไหน เป็นปัญหา "ผัง" ไม่ใช่ "ขนาดฟอนต์"
     ทำได้เท่าที่ไม่แตะดีไซน์: ย่อไอคอน + ซ่อนบรรทัดคดีที่แสดงไม่ได้อยู่แล้ว
     การขยายแผงให้กว้างขึ้นต้องให้ดีไซน์ตัดสิน เพราะแผงวางอยู่บนกรอบภาพ LEADERBOARD
   ═══════════════════════════════════════════════════════════════════════════ */
@media (orientation: landscape) and (max-height: 460px) {
  /* บรรทัด "(คดี : ...)" ต้องการพื้นที่ 3 เท่าของที่มี — ซ่อนไปเลยดีกว่าแสดงครึ่ง ๆ กลาง ๆ */
  .lobby-rank-case {
    display: none;
  }

  /* ย่อไอคอนคืนพื้นที่ให้ชื่อ (28px -> 18px = ชื่อได้เพิ่มราว 10px) */
  .lobby-rank-icon {
    width: 18px;
    min-width: 18px;
    height: 18px;
  }

  /* ชื่อได้พื้นที่ที่เหลือทั้งหมด และไม่ให้คะแนนไปเบียด */
  .lobby-rank-info {
    flex: 1 1 auto;
    min-width: 0;
  }
  .lobby-rank-score {
    flex: 0 0 auto;
  }
}


/* ══════════════════════════════════════════════════════════════════════
   [2026-08-29] จอมือถือ: ปุ่ม "รางวัลประจำวัน" + "LEADERBOARD" ชิดขวา
   ตาม mock ของทีม design (02-1-Main-Lobby-1-mobile.png · 2437x1126)
   วัดด้วยการจับคู่รูปปุ่มกับ mock — ทั้งสองปุ่ม 475x285 ชิดขวา x=1956
   รางวัลประจำวัน y=320 · LEADERBOARD y=596 ⇒ กว้าง 19.5vw · สัดส่วน 501/301

   หมายเหตุการทำ: ในไฟล์นี้มีระบบ --lobby-rail-h / --lobby-rail-w อยู่แล้ว
   (บล็อก "MOBILE LANDSCAPE — daily กว้างเท่า leaderboard เป๊ะ" ~บรรทัด 2412)
   ซึ่งบังคับด้วย !important ⇒ **ไม่สู้กับมัน แต่ต่อยอด**: แค่นิยาม --lobby-rail-w
   ใหม่ตามสัดส่วนปุ่มมือถือ (501/301) แทนสัดส่วนพาเนลเดิม (417/443)
   ปุ่มทั้งสองก็กว้างเท่ากันเป๊ะเหมือนเดิมโดยไม่ต้องแตะกฎเก่าเลย
   เดสก์ท็อปไม่ได้รับผลกระทบ — ทุกกฎอยู่ใน @media (hover:none) and (pointer:coarse)
   ══════════════════════════════════════════════════════════════════════ */
.lobby-daily-img-mb,
.lobby-btn-leaderboard-mb,
.lobby-lb-backdrop,
.lobby-lb-close { display: none; }

@media (hover: none) and (pointer: coarse) {
  body.lobby-page {
    /* ปุ่มมือถือเป็นแนวนอน 501/301 · ถ้ายังไม่มี --lobby-rail-h (นอกช่วงจอเตี้ย) ใช้ 25.3vh ตาม mock */
    --lobby-rail-h: var(--lobby-rail-h, 25.3vh);
    --lobby-rail-w: min(19.5vw, calc(25.3vh * 501 / 301));
  }

  /* ── ปุ่มรางวัลประจำวัน: สลับเป็นรูปแนวตั้งของมือถือ ── */
  body.lobby-page .lobby-header .lobby-btn-daily .lobby-daily-img { display: none; }
  body.lobby-page .lobby-header .lobby-btn-daily .lobby-daily-img-mb {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  body.lobby-page .lobby-header .lobby-btn-daily { aspect-ratio: 501 / 301; }

  /* ── ปุ่ม LEADERBOARD — กว้างเท่าปุ่มรางวัลประจำวันเป๊ะ (ตัวแปรเดียวกัน) ──
     [2026-09-01] เดิม top: 52.9vh + right: clamp(0.5rem,2vw,1.5rem) เป็นค่าคงที่ที่ถอดมาจาก mock
     ซึ่งไม่ผูกกับปุ่มรางวัลประจำวันจริง ⇒ วัดด้วย headless Chrome แล้วเพี้ยนทั้งสองแกน:
       ช่องไฟใต้ปุ่มรางวัล  14.0 / 14.8 / 16.6 / 17.7 / 30.8 / 60.7 px
                            (812x375 · 844x390 · 926x428 · 740x360 · 667x375 · 1024x600)
       ขอบขวาเหลื่อมกัน     -0.7 ถึง +3.7 px  (right ของปุ่มนี้วัดจาก padding box ของ .lobby-ui
                            ส่วนปุ่มรางวัลอยู่ใน content box ของ header ซึ่งเข้ามาอีกชั้น)
     แก้โดยย้ายปุ่มไปเป็นลูกของ <header> (ดู index.html) แล้ว "วางตัวเองในช่องกริดเดียวกับ
     ปุ่มรางวัลประจำวัน" — สำหรับลูกที่เป็น absolute ของ grid container ถ้าระบุ grid-column/row
     กล่องอ้างอิงจะเป็น "ช่องกริด" นั้น ไม่ใช่ padding box ของ header
       top: calc(100% + 20px) → 100% = ขอบล่างช่อง = ขอบล่างปุ่มรางวัลประจำวันเป๊ะ (แถว 2 เป็นแถวสุดท้าย)
                                จึงได้ช่องไฟ 20px ตรงตามที่ขอ ทุกขนาดจอ ไม่ต้องเดาเป็น vh
       right: 0             → ขอบขวาช่อง = ขอบขวาปุ่มรางวัลประจำวัน (ปุ่มนั้น margin-left:auto ชิดขวาช่องอยู่แล้ว)
     ปุ่มยังเป็น absolute เหมือนเดิม = อยู่นอกโฟลว์ ไม่ได้ดันความสูง header หรือเลย์เอาต์ใด ๆ ── */
  .lobby-btn-leaderboard-mb {
    display: block;
    position: absolute;
    /* ต้องระบุ "เส้นปิด" ด้วย (2 / 3) ห้ามเขียนแค่ `2`
       สำหรับลูก absolute ของกริด เส้นที่เป็น auto = ขอบ padding box ของกริด ไม่ใช่ขอบช่อง
       ⇒ เขียนแค่ `grid-column: 2` จะได้ช่องที่ลากยาวไปจบที่ขอบ header (วัดแล้วเหลื่อมขวา 6.2px
          และบนแท็บเล็ตที่ header มี padding-bottom 16px ช่องไฟก็กลายเป็น 36px แทน 20px) */
    grid-column: 2 / 3;
    grid-row: 2 / 3;
    top: calc(100% + 20px);
    right: 0;
    /* [2026-09-01] เดิมเป็น var(--lobby-rail-w) ซึ่งนิยามไว้เองที่ min(19.5vw, 25.3vh*501/301)
       ตรงกับปุ่มรางวัลเฉพาะ "มือถือแนวนอน" (จอเตี้ย ≤620px) ที่ปุ่มรางวัลถูกทับด้วย rail เหมือนกัน
       แต่บนแท็บเล็ต จอสูงเกิน 620px ⇒ rail ไม่ทำงาน ปุ่มรางวัลกลับไปใช้ 36cqh (36% ของความสูง
       container) ส่วนปุ่มนี้ยังคิดจาก 19.5vw ⇒ วัดจริงด้วย CDP (จำลอง pointer:coarse) ได้:
         iPad 1194×834  รางวัล 300.2 · LEADERBOARD 232.8   (เล็กกว่า 22%)
         1024×768       รางวัล 276.5 · LEADERBOARD 199.7   (เล็กกว่า 28%)
         1112×834       รางวัล 300.2 · LEADERBOARD 216.8   (เล็กกว่า 28%)
         1366×1024      รางวัล 368.6 · LEADERBOARD 266.4   (เล็กกว่า 28%)
       แก้โดยอ้าง "ตัวแปรความกว้างของปุ่มรางวัล" ตัวเดียวกันไปเลย ไม่คำนวณเองซ้ำ
       ⇒ ปุ่มรางวัลเปลี่ยนสูตรที่ย่านไหน ปุ่มนี้ตามไปเองทุกย่าน ไม่หลุดอีก
       (สัดส่วนภาพเท่ากัน 501/301 อยู่แล้ว ⇒ กว้างเท่ากันคือสูงเท่ากันด้วย) */
    width: var(--lobby-header-daily-btn-width, var(--lobby-rail-w));
    aspect-ratio: 501 / 301;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    z-index: 6;
  }
  .lobby-btn-leaderboard-mb-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  /* ── พาเนลอันดับ: ซ่อนแบบฝังในหน้า เปิดเป็นหน้าต่างซ้อนเมื่อกดปุ่ม ──
     บนจอเล็กพาเนลแบบฝังแคบจนชื่อถูกตัดเหลือ "Mix..." "Gol..." */
  .lobby-leaderboard { display: none; }

  body.is-lb-open .lobby-lb-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(4, 8, 20, 0.72);
    z-index: 10040;
  }
  /* กฎเก่าบังคับ height/width ด้วย !important ⇒ ตอนเป็นหน้าต่างซ้อนต้อง !important ทับ */
  body.is-lb-open .lobby-leaderboard {
    display: block;
    /* [แก้ 2026-08-29] ต้อง !important ทั้งชุด — พาเนลนี้มี animation เข้าฉากที่ขยับ
       transform/top อยู่ และ "ค่าจากอนิเมชัน ชนะค่าปกติเสมอ" ⇒ ตอนแรกหน้าต่างซ้อน
       ไปโผล่ที่ y=-49 หลุดขอบบน · ปิดอนิเมชันตอนเป็นหน้าต่างซ้อนไปเลย */
    animation: none !important;
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) !important;
    height: min(88vh, 88vw * (443 / 417)) !important;
    width: calc(min(88vh, 88vw * (443 / 417)) * (417 / 443)) !important;
    max-width: none !important;
    z-index: 10041;
  }
  body.is-lb-open .lobby-lb-close {
    display: block;
    position: absolute;
    top: 3%;
    right: 5%;
    width: 2.2em;
    height: 2.2em;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(10, 18, 38, 0.85);
    color: #7feeff;
    font-size: max(14px, 2.4vh);
    line-height: 1;
    cursor: pointer;
    z-index: 3;
  }
}
