* { box-sizing: border-box; }

@font-face {
  font-family: 'NotoSansThai';
  src: url('../FONTS/NotoSansThai-ExtraBold.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'NotoSansThaiMedium';
  src: url('../FONTS/NotoSansThai-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: 'Kanit', 'Sarabun', 'Segoe UI', system-ui, sans-serif;
  color: #fff;
  background: #030712;
}

.qb-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
}

.qb-bg-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.qb-vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 25%, transparent 15%, rgba(0, 0, 0, 0.4) 100%);
}

.qb-ui {
  --qb-ui-scale: 1;
  position: relative;
  z-index: 2;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(calc(10px * var(--qb-ui-scale)), env(safe-area-inset-top))
    max(calc(12px * var(--qb-ui-scale)), env(safe-area-inset-right))
    max(calc(14px * var(--qb-ui-scale)), env(safe-area-inset-bottom))
    max(calc(12px * var(--qb-ui-scale)), env(safe-area-inset-left));
  overflow: hidden;
}

.qb-top {
  position: absolute;
  top: max(calc(10px * var(--qb-ui-scale)), env(safe-area-inset-top));
  left: max(calc(12px * var(--qb-ui-scale)), env(safe-area-inset-left));
  right: max(calc(12px * var(--qb-ui-scale)), env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: calc(8px * var(--qb-ui-scale));
  min-height: calc(157px * var(--qb-ui-scale));
  z-index: 6;
  pointer-events: none;
}

.qb-top-fill {
  flex: 1;
  min-width: calc(8px * var(--qb-ui-scale));
  pointer-events: none;
}

/* กรอบแดง 1: ใช้ layout แบบ Join Room back button */
.qb-join-back {
  position: fixed;
  top: max(2px, env(safe-area-inset-top));
  left: max(2px, env(safe-area-inset-left));
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 20;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.qb-join-back-img {
  --qb-exit-btn-height: 142px;
  display: block;
  height: var(--qb-exit-btn-height);
  width: calc(var(--qb-exit-btn-height) * (122 / 142));
  object-fit: contain;
}

/* กรอบแดง 2: ใช้ layout แบบ room-lobby-profile-avatar-viewport */
.qb-room-profile-wrap {
  flex-shrink: 0;
  pointer-events: none;
}

.qb-room-profile-frame {
  position: relative;
  width: 159px;
  height: 157px;
  min-width: 159px;
  min-height: 157px;
  max-width: 159px;
  max-height: 157px;
  aspect-ratio: 159 / 157;
  border-radius: 0;
  border: none;
  overflow: hidden;
  background: url(../Game/img/btn-profile-bg.png) center/100% 100% no-repeat;
  box-shadow: none;
}

.qb-room-profile-avatar-viewport {
  position: absolute;
  left: 18px;
  top: 10px;
  width: 124px;
  height: 118px;
  overflow: hidden;
  border-radius: 12px;
}

.qb-room-profile-avatar {
  position: absolute;
  left: 50%;
  top: 5px;
  display: block;
  width: 120%;
  height: auto;
  max-width: none;
  object-fit: contain;
  object-position: center top;
  transform: translateX(-50%);
  transform-origin: center center;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
}

.qb-main {
  --qb-main-scale: 1;
  --qb-banner-width: calc(419px * var(--qb-main-scale));
  --qb-banner-height: calc(151px * var(--qb-main-scale));
  --qb-card-width: calc(271px * var(--qb-main-scale));
  --qb-card-height: calc(351px * var(--qb-main-scale));
  --qb-card-start-height: calc(83px * var(--qb-main-scale));
  --qb-card-start-width: calc(168px * var(--qb-main-scale));
  --qb-grid-gap-x: calc(18px * var(--qb-main-scale));
  --qb-grid-gap-y: calc(14px * var(--qb-main-scale));
  --qb-main-gap-banner-grid: calc(12px * var(--qb-main-scale));
  --qb-main-gap-grid-toast: calc(8px * var(--qb-main-scale));
  position: relative;
  z-index: 3;
  width: 100%;
  height: calc(100dvh - max(calc(10px * var(--qb-ui-scale)), env(safe-area-inset-top)) - max(calc(14px * var(--qb-ui-scale)), env(safe-area-inset-bottom)));
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 0;
  overflow: hidden;
  padding-top: calc(2px * var(--qb-main-scale));
}

.qb-main::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.qb-main::-webkit-scrollbar-track {
  background: transparent;
}

.qb-main::-webkit-scrollbar-thumb {
  background: transparent;
}

.qb-room-banner {
  flex: 0 0 auto;
  width: var(--qb-banner-width);
  height: var(--qb-banner-height);
  max-width: 100%;
  flex-shrink: 0;
  margin: 0 auto var(--qb-main-gap-banner-grid);
  margin-top: calc(60px * var(--qb-main-scale));
}





.qb-room-banner img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35));
}

.qb-grid {
  width: auto;
  max-width: 100%;
  display: grid;
  grid-template-columns: repeat(5, var(--qb-card-width));
  grid-auto-rows: var(--qb-card-height);
  justify-content: center;
  align-content: start;
  column-gap: var(--qb-grid-gap-x);
  row-gap: var(--qb-grid-gap-y);
  padding: 0;
}





.qb-card {
  position: relative;
  width: var(--qb-card-width);
  height: var(--qb-card-height);
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: default;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.qb-card-room {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.qb-card-start {
  position: absolute;
  left: 50%;
  bottom: calc(25px * var(--qb-main-scale));
  transform: translateX(-50%);
  width: var(--qb-card-start-width);
  height: var(--qb-card-start-height);
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  z-index: 2;
  transition: transform 0.14s ease, filter 0.14s ease;
}

.qb-card-start:hover,
.qb-card-start:focus-visible {
  transform: translateX(-50%) translateY(-1px);
  filter: brightness(1.06);
}

.qb-card-start:focus-visible {
  outline: 2px solid #22d3ee;
  outline-offset: 3px;
  border-radius: 8px;
}

.qb-card-start:active {
  transform: translateX(-50%) translateY(0);
}

.qb-card-start img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.qb-card-count {
  position: absolute;
  top: calc(44px * var(--qb-main-scale));
  right: calc(54px * var(--qb-main-scale));
  font-family: 'NotoSansThaiMedium', 'NotoSansThai', 'Kanit', 'Sarabun', system-ui, sans-serif;
  font-size: calc(22px * var(--qb-main-scale));
  font-weight: 500;
  line-height: 1;
  color: #ffffff;
  letter-spacing: 0;
  text-shadow:
    0 0 calc(10px * var(--qb-main-scale)) rgba(87, 239, 255, 0.55),
    0 0 calc(2px * var(--qb-main-scale)) rgba(0, 0, 0, 0.65);
  pointer-events: none;
  user-select: none;
  z-index: 3;
}

.qb-toast {
  text-align: center;
  font-size: calc(20px * var(--qb-main-scale));
  color: rgba(248, 250, 252, 0.88);
  line-height: 1.2;
  min-height: calc(24px * var(--qb-main-scale));
  margin-top: var(--qb-main-gap-grid-toast);
  flex-shrink: 0;
  padding: 0 calc(8px * var(--qb-main-scale)) calc(4px * var(--qb-main-scale));
}

/* มุมขวาล่าง — btn-voice (ซ่อนไว้ก่อน: ทับการ์ด Room 09–10 ในหน้าเลือกห้อง) */
.qb-room-lobby-br-fixed {
  --lobby-br-btn: calc(121px * var(--qb-ui-scale, 1));
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  position: fixed;
  bottom: max(calc(0.95rem * var(--qb-ui-scale, 1)), env(safe-area-inset-bottom));
  right: max(calc(1.25rem * var(--qb-ui-scale, 1)), env(safe-area-inset-right));
  z-index: 400;
  flex-direction: row;
  align-items: flex-end;
  gap: calc(10px * var(--qb-ui-scale, 1));
  pointer-events: none;
}

.qb-room-lobby-br-fixed .btn-voice-icon {
  pointer-events: auto;
  box-sizing: border-box;
  width: var(--lobby-br-btn);
  height: var(--lobby-br-btn);
  min-width: var(--lobby-br-btn);
  min-height: var(--lobby-br-btn);
  max-width: var(--lobby-br-btn);
  max-height: var(--lobby-br-btn);
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  cursor: pointer;
  background: transparent;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qb-room-lobby-br-fixed .btn-voice-icon img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* ============================================================
   Quiz Battle play overlay (Kahoot/ZEP-style) — จอเล่นจริง 50 คน
   ============================================================ */
.qb-play {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(37, 99, 235, 0.28) 0%, transparent 60%),
    linear-gradient(180deg, #0b1024 0%, #060912 100%);
  color: #fff;
  font-family: 'Kanit', 'Sarabun', system-ui, sans-serif;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.qb-play.is-open { display: flex; }

/* แถบหัว: ห้อง / จำนวนผู้เล่น / คะแนนเรา */
.qb-play-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}
.qb-play-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: clamp(14px, 2.2vw, 20px);
  font-weight: 600;
  white-space: nowrap;
}
.qb-play-pill b { color: #57efff; }
.qb-play-leave {
  border: none;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.qb-play-leave:hover { background: rgba(239, 68, 68, 0.3); }

/* body กลางจอ */
.qb-play-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 2.5vh, 28px);
  text-align: center;
}
.qb-play-screen { width: 100%; max-width: 1100px; display: none; flex-direction: column; align-items: center; gap: clamp(12px, 2.4vh, 26px); }
.qb-play-screen.is-active { display: flex; }

/* timer bar */
.qb-timebar {
  width: min(100%, 760px);
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.qb-timebar-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #34d399, #fbbf24, #ef4444);
  transform-origin: left center;
  transition: transform 0.2s linear;
}

/* คำถาม */
.qb-qmeta { font-size: clamp(13px, 2vw, 18px); color: rgba(255,255,255,0.7); font-weight: 600; }
.qb-question-text {
  font-size: clamp(22px, 4.2vw, 44px);
  font-weight: 700;
  line-height: 1.25;
  padding: 18px 22px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  max-width: 900px;
}
.qb-answers {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(10px, 1.8vw, 18px);
}
.qb-answers[data-count="3"] .qb-answer:last-child { grid-column: 1 / -1; }
.qb-answer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: clamp(64px, 12vh, 110px);
  padding: 14px 20px;
  border: none;
  border-radius: 16px;
  color: #fff;
  font: inherit;
  font-size: clamp(16px, 2.6vw, 26px);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.1s ease, opacity 0.2s ease;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25), 0 10px 24px rgba(0, 0, 0, 0.35);
}
.qb-answer:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.08); }
.qb-answer:active:not(:disabled) { transform: translateY(0); }
.qb-answer:disabled { cursor: default; }
.qb-answer .qb-answer-icon {
  flex: 0 0 auto;
  width: clamp(28px, 5vw, 44px);
  height: clamp(28px, 5vw, 44px);
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  font-weight: 800;
}
.qb-answer.c0 { background: #e21b3c; }
.qb-answer.c1 { background: #1368ce; }
.qb-answer.c2 { background: #d89e00; }
.qb-answer.c3 { background: #26890c; }
.qb-answer.is-picked { outline: 4px solid #fff; outline-offset: 2px; }
.qb-answer.is-correct { box-shadow: 0 0 0 4px #fff, 0 0 28px rgba(38,137,12,0.8); }
.qb-answer.is-wrong { opacity: 0.45; }
.qb-answer.is-dimmed { opacity: 0.4; }

.qb-answered-info { font-size: clamp(14px, 2.2vw, 20px); color: rgba(255,255,255,0.78); font-weight: 600; }

/* countdown */
.qb-countdown-num { font-size: clamp(80px, 22vw, 220px); font-weight: 800; line-height: 1; color: #57efff; text-shadow: 0 0 40px rgba(87,239,255,0.6); }
.qb-countdown-label { font-size: clamp(18px, 3vw, 30px); font-weight: 600; }

/* reveal / result feedback */
.qb-feedback { font-size: clamp(28px, 6vw, 64px); font-weight: 800; }
.qb-feedback.ok { color: #34d399; }
.qb-feedback.no { color: #f87171; }
.qb-delta { font-size: clamp(20px, 3.4vw, 34px); font-weight: 700; color: #fbbf24; }

/* leaderboard */
.qb-board { width: min(100%, 560px); display: flex; flex-direction: column; gap: 8px; }
.qb-board-title { font-size: clamp(18px, 3vw, 28px); font-weight: 700; margin-bottom: 4px; }
.qb-board-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: clamp(15px, 2.4vw, 20px);
}
.qb-board-row.me { background: rgba(87, 239, 255, 0.16); border-color: rgba(87,239,255,0.4); }
.qb-board-row.top1 { background: linear-gradient(90deg, rgba(251,191,36,0.25), rgba(255,255,255,0.05)); border-color: rgba(251,191,36,0.5); }
.qb-board-rank { flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,0.14); font-weight: 800; }
.qb-board-row.top1 .qb-board-rank { background: #fbbf24; color: #1a1500; }
.qb-board-name { flex: 1; text-align: left; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qb-board-score { flex: 0 0 auto; font-weight: 700; color: #57efff; }

/* lobby (waiting room) */
.qb-lobby-title { font-size: clamp(26px, 5vw, 52px); font-weight: 800; }
.qb-lobby-sub { font-size: clamp(15px, 2.6vw, 22px); color: rgba(255,255,255,0.78); }
.qb-players {
  width: min(100%, 720px);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-height: 34vh;
  overflow-y: auto;
}
.qb-player-chip {
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  font-size: clamp(13px, 2.2vw, 18px);
  font-weight: 600;
}
.qb-player-chip.me { background: rgba(87,239,255,0.18); border-color: rgba(87,239,255,0.45); }

/* primary action button */
.qb-btn {
  border: none;
  border-radius: 14px;
  padding: 14px 40px;
  font: inherit;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 700;
  color: #04121f;
  background: linear-gradient(180deg, #67e8f9, #22d3ee);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(34,211,238,0.35);
  transition: transform 0.1s ease, filter 0.1s ease;
}
.qb-btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.05); }
.qb-btn:active:not(:disabled) { transform: translateY(0); }
.qb-btn:disabled { opacity: 0.5; cursor: default; }
.qb-btn.ghost { background: rgba(255,255,255,0.1); color: #fff; border: 1px solid rgba(255,255,255,0.2); box-shadow: none; }

/* ================================================== */
/*  Animations — entrance (ตอนขึ้น) / press (ตอนกด)   */
/* ================================================== */
@keyframes qb-rise { from { opacity: 0; transform: translateY(22px); } to { opacity: 1; transform: translateY(0); } }
@keyframes qb-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes qb-card-in { from { opacity: 0; transform: translateY(26px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* press feedback — เปิดเสมอ */
.qb-join-back { transition: transform .13s ease, filter .2s; -webkit-tap-highlight-color: transparent; }
.qb-join-back:hover { filter: brightness(1.13); }
.qb-join-back:active { transform: scale(.9); }
.btn-voice-icon { transition: transform .13s ease, filter .2s; }
.btn-voice-icon:hover { filter: brightness(1.13); }
.btn-voice-icon:active { transform: scale(.9); }
/* การ์ดห้อง: hover ยกขึ้น (มี transition แล้ว) + override :active ของปุ่มเริ่ม คง translateX(-50%) */
.qb-card { transition: transform .18s ease, filter .2s; }
.qb-card:hover { transform: translateY(-4px); filter: brightness(1.06); }
.qb-card-start:active { transform: translateX(-50%) scale(.93); }

@media (prefers-reduced-motion: no-preference) {
  /* entrance: โผล่ไล่ทีละชิ้น */
  .qb-join-back { animation: qb-fade .55s ease .06s backwards; }
  .qb-room-profile-wrap { animation: qb-fade .6s ease .12s both; }
  .qb-room-banner { animation: qb-rise .55s cubic-bezier(.2,.85,.25,1) .12s both; }
  /* การ์ดใช้ backwards → หลัง entrance กลับสู่สภาพปกติ (hover transform ยังทำงาน) */
  .qb-card { animation: qb-card-in .5s cubic-bezier(.2,.85,.25,1) backwards; }
  .qb-card:nth-child(1) { animation-delay: .2s; }
  .qb-card:nth-child(2) { animation-delay: .28s; }
  .qb-card:nth-child(3) { animation-delay: .36s; }
  .qb-card:nth-child(4) { animation-delay: .44s; }
  .qb-card:nth-child(5) { animation-delay: .52s; }
  .qb-card:nth-child(n+6) { animation-delay: .58s; }
}







