/* ============================================================================
   LOBBY (BOF v0.8) — ล็อบบี้เกมหน้าจอเดียว: ลีดเดอร์กลางจอ + กำแพงการ์ดของเด็ค
   สเปก: docs/specs/2026-10-24-lobby-game-design.md
   กฎ: ขยับด้วย transform/opacity · ไม่ใช้ backdrop-filter / mix-blend-mode บนหรือใต้สิ่งที่ขยับ
   ============================================================================ */

#lobby-screen {
  --lb-bg: #0b0d1a;
  --lb-panel: rgba(22, 26, 58, .88);
  --lb-line: rgba(160, 175, 255, .25);
  --lb-ink: #e8eaf7;
  --lb-ink-soft: #b9bee0;
  --lb-ink-dark: #12142a;
  --lb-gold: #f3c969;
  --lb-gold-hi: #ffe39a;
  --lb-gold-lo: #e0a83c;
  --deck: #3ee08f;
  --leader-h: min(62vh, 44vw); /* จอแคบแต่สูง (แท็บเล็ต) ลีดเดอร์เล็กลง ให้ข้อมูลเด็คมีที่ */

  position: relative;
  width: calc(100% + 20px);
  height: 100vh; height: 100svh;
  margin: -10px; /* body มี padding 10px สำหรับกระดานเกม — ล็อบบี้ต้องเต็มจอ */
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 35%, #182048 0%, var(--lb-bg) 62%);
  color: var(--lb-ink);
  font-family: var(--font-body);
}
#lobby-screen *, #lobby-screen *::before, #lobby-screen *::after { box-sizing: border-box; }
#lobby-screen h1, #lobby-screen h2, #lobby-screen p { margin: 0; }
#lobby-screen :focus-visible { outline: 3px solid var(--lb-gold); outline-offset: 3px; }
#lobby-screen .lb-dialog :focus-visible { outline-color: var(--lb-ink-dark); }

/* ---------- กำแพงการ์ด ---------- */
#lb-wall { position: absolute; left: 50%; top: 50%; width: 170vw; transform: translate(-50%, -50%) rotate(-12deg); opacity: .34; pointer-events: none; }
.lb-wall-inner { display: grid; grid-template-columns: repeat(12, 1fr); gap: 1.1vw; }
.lb-tile { aspect-ratio: 750 / 1050; }
.lb-tile img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.lb-tint { position: absolute; inset: 0; pointer-events: none; background: var(--deck); opacity: .12; } /* ไม่ทำ transition สีเต็มจอ (วาดใหม่ทั้งจอทุกเฟรม) */
.lb-vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(48% 58% at 50% 46%, rgba(11, 13, 26, .35) 0%, rgba(11, 13, 26, .9) 100%); }

/* ---------- โลโก้ + เมนู ---------- */
.lb-logo { position: absolute; left: 24px; top: 18px; font: 700 22px/1.2 var(--font-display); color: var(--lb-gold); letter-spacing: .02em; text-shadow: 0 0 18px rgba(243, 201, 105, .5); }
.lb-menu { position: absolute; left: 24px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 14px; }
.lb-menu-item {
  width: 72px; height: 72px; border-radius: 14px; border: 1px solid rgba(243, 201, 105, .45); background: var(--lb-panel);
  color: var(--lb-ink); font: 600 13px/1.1 var(--font-display); text-decoration: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 0;
  transition: background-color .2s, border-color .2s;
}
.lb-menu-item:hover { background: rgba(38, 44, 92, .95); border-color: var(--lb-gold); }
.lb-menu-item svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lb-mobile-only { display: none; }

/* ---------- คอลัมน์ซ้าย: โลโก้ → การ์ดผู้เล่น → เมนู (ไหลต่อกันจึงไม่ทับกันไม่ว่าฉายายาวแค่ไหน) ---------- */
@media (min-width: 768px) {
  .lb-side { position: absolute; left: 24px; top: 16px; z-index: 15; width: 236px; display: flex; flex-direction: column; gap: 12px; }
  #lobby-screen .lb-side .lb-logo, #lobby-screen .lb-side .lb-menu { position: static; transform: none; }

  /* การ์ดผู้เล่น: แผ่นป้ายแบบการ์ดสะสม มีแถบฟอยล์ทองด้านบน + ต้นขั้วเหรียญแบบตั๋วฉีก */
  .lb-plate {
    position: relative; border-radius: 16px; overflow: hidden;
    background: linear-gradient(160deg, #1f2656 0%, #141834 70%);
    border: 1px solid rgba(243, 201, 105, .5);
    box-shadow: 0 10px 28px rgba(0, 0, 0, .5), inset 0 0 0 3px rgba(11, 13, 26, .55), inset 0 0 0 4px rgba(243, 201, 105, .14);
  }
  .lb-plate::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: linear-gradient(90deg, var(--lb-gold-lo), var(--lb-gold-hi) 45%, var(--deck) 100%); }
  #lobby-screen .lb-plate #lb-auth-bar {
    position: static; display: flex; align-items: center; width: 100%; gap: 12px; padding: 14px 12px 12px;
    border: 0; border-radius: 0; background: none; box-shadow: none; transform: none; text-align: left;
  }
  #lobby-screen .lb-plate #lb-auth-bar:hover { background: rgba(255, 255, 255, .04); }
  #lobby-screen .lb-plate .lb-auth-avatar { width: 54px; height: 54px; border-radius: 12px; }
  #lobby-screen .lb-plate .lb-auth-meta { gap: 3px; min-width: 0; }
  #lobby-screen .lb-plate .lb-auth-name { font-size: 15px; max-width: 146px; }
  #lobby-screen .lb-plate .bof-user-title-pill { max-width: 146px; overflow: hidden; text-overflow: ellipsis; padding: 2px 8px; font-size: 10.5px; }
  #lobby-screen .lb-plate #lb-coin-pill {
    position: relative; left: auto; top: auto; display: flex; width: 100%; height: 44px; padding: 0 12px 0 14px;
    border: 0; border-top: 1px dashed rgba(243, 201, 105, .35); border-radius: 0;
    background: rgba(6, 8, 20, .35); box-shadow: none; transform: none; font-size: 17px;
  }
  #lobby-screen .lb-plate #lb-coin-pill:hover { background: rgba(243, 201, 105, .1); }
  #lobby-screen .lb-plate #lb-coin-pill .lb-coin-plus { margin-left: auto; }
  /* รอยเจาะสองข้างของรอยฉีก */
  #lb-coin-pill::before, #lb-coin-pill::after { content: ''; position: absolute; top: -6px; width: 12px; height: 12px; border-radius: 50%; background: var(--lb-bg); border: 1px solid rgba(243, 201, 105, .35); }
  #lb-coin-pill::before { left: -7px; }
  #lb-coin-pill::after { right: -7px; }

  /* เมนู: กริด 2 คอลัมน์ใต้การ์ดผู้เล่น */
  #lobby-screen .lb-side .lb-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  #lobby-screen .lb-side .lb-menu-item { width: auto; height: 50px; flex-direction: row; justify-content: flex-start; gap: 8px; padding: 0 12px; border-radius: 12px; font-size: 14px; }
  #lobby-screen .lb-side .lb-menu-item svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--lb-gold); }
  #lobby-screen .lb-side #nav-settings { grid-column: span 2; }
}

/* ---------- เข้าห้องด้วยรหัส ---------- */
.lb-join-slot { position: absolute; right: 24px; top: 14px; }
.lb-join { display: grid; grid-template-columns: auto 96px auto; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; border-radius: 14px; background: var(--lb-panel); border: 1px solid var(--lb-line); }
.lb-join label { font: 500 14px var(--font-body); }
.lb-join input { width: 100%; height: 44px; border: 0; border-radius: 10px; background: var(--lb-bg); color: #fff; text-align: center; font: 600 18px var(--font-display); letter-spacing: .15em; }
.lb-join input::placeholder { color: #6b7199; letter-spacing: .15em; }
.lb-join-btn { height: 44px; min-width: 64px; padding: 0 16px; border: 0; border-radius: 10px; background: #2a3270; color: #fff; font: 600 14px var(--font-display); cursor: pointer; }
.lb-join-btn:hover { background: #38419a; }
.lb-join-error { grid-column: 1 / -1; font-size: 13px; color: #ffb3bd; }
.lb-join-error:empty { display: none; }

/* ---------- ลีดเดอร์ + ข้อมูลเด็ค ---------- */
.lb-leader-wrap { position: absolute; left: 50%; top: 45%; height: var(--leader-h); aspect-ratio: 750 / 1050; transform: translate(-50%, -50%); perspective: 1200px; }
.lb-leader { position: relative; width: 100%; height: 100%; cursor: pointer; }
.lb-leader img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 12px; box-shadow: 0 24px 60px rgba(0, 0, 0, .7), 0 0 0 3px rgba(243, 201, 105, .85); }
.lb-info { position: absolute; left: calc(50% + var(--leader-h) * .357 + 32px); top: 28%; width: min(380px, calc(50vw - var(--leader-h) * .357 - 56px)); }
.lb-deck-name { font: 700 clamp(30px, 3.4vw, 48px)/1.05 var(--font-display); color: var(--deck); text-shadow: 0 0 24px rgba(0, 0, 0, .6); transition: color .6s; }
.lb-leader-name { margin-top: 10px !important; font: 600 18px var(--font-display); }
.lb-deck-style { margin-top: 6px !important; color: var(--lb-ink-soft); font-size: 15px; line-height: 1.5; }
.lb-chips { margin-top: 14px !important; display: flex; flex-wrap: wrap; gap: 8px; }
.lb-chips span { padding: 4px 12px; border-radius: 999px; background: var(--lb-panel); border: 1px solid var(--lb-line); font-size: 13px; }

/* ---------- เลือกเด็ค ---------- */
.lb-decks { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; gap: 14px; align-items: flex-end; }
.lb-deck { position: relative; width: 60px; padding: 0; border: 0; background: none; cursor: pointer; opacity: .6; transition: opacity .2s; }
.lb-deck img { display: block; width: 100%; aspect-ratio: 750 / 1050; border-radius: 6px; }
.lb-deck:hover { opacity: .9; }
.lb-deck:focus-visible { opacity: 1; }
.lb-deck[aria-pressed="true"] { opacity: 1; transform: translateY(-6px); }
.lb-deck[aria-pressed="true"] img { outline: 3px solid var(--lb-gold); box-shadow: 0 0 18px rgba(243, 201, 105, .6); }
.lb-deck-mine-tag { position: absolute; left: 50%; bottom: -2px; transform: translate(-50%, 50%); white-space: nowrap; padding: 1px 8px; border-radius: 999px; background: var(--lb-gold); color: var(--lb-ink-dark); font: 600 11px var(--font-display); }

/* ---------- ปุ่มเริ่มดวล (แสงเต้นอยู่ในชั้นแยก ขยับด้วย opacity/scale) ---------- */
.lb-play {
  position: absolute; right: 28px; bottom: 28px; padding: 16px 44px; border: 0; border-radius: 14px; cursor: pointer;
  color: #1a1405; background: linear-gradient(135deg, var(--lb-gold-hi), var(--lb-gold-lo));
  box-shadow: 0 0 0 3px rgba(255, 240, 200, .35), 0 10px 30px rgba(224, 168, 60, .45); text-align: center;
}
.lb-play-label { position: relative; display: block; font: 700 26px/1.1 var(--font-display); }
.lb-play small { position: relative; display: block; margin-top: 2px; font: 500 12px var(--font-body); opacity: .8; }
.lb-play-glow { position: absolute; inset: -10px; border-radius: 20px; background: radial-gradient(closest-side, rgba(255, 227, 154, .55), rgba(255, 227, 154, 0)); opacity: .4; pointer-events: none; }

.lb-github { position: absolute; left: 24px; bottom: 16px; display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; color: var(--lb-ink-soft); font-size: 13px; }

/* ---------- หน้าต่าง ---------- */
.lb-dialog {
  margin: auto; /* style.css รีเซ็ต margin ทุกตัวเป็น 0 — dialog ต้องใช้ auto จึงจะอยู่กลางจอ */
  border: 0; border-radius: 16px; padding: 28px; width: min(460px, calc(100vw - 32px));
  background: #f5ecd7; color: var(--lb-ink-dark); box-shadow: 0 24px 64px rgba(0, 0, 0, .55);
}
.lb-dialog::backdrop { background: rgba(7, 8, 15, .78); }
.lb-dialog h2 { font: 700 28px/1.2 var(--font-display); }
.lb-btn { min-height: 56px; padding: 0 20px; border: 0; border-radius: 12px; cursor: pointer; font: 700 18px var(--font-display); }
.lb-btn-primary { color: #1a1405; background: linear-gradient(135deg, var(--lb-gold-hi), var(--lb-gold-lo)); }

/* ---------- หน้าต่างเลือกโหมด: พื้นเข้ม ขอบทอง การ์ดโหมด 2 ใบ ---------- */
/* พื้นและขอบอยู่ที่ .lb-dialog-panel ซึ่ง lobby-motion.js ใช้เด้งตอนเปิด
   (animate ตัว <dialog> เองแล้ว Chrome ทำ focus ของปุ่มในหน้าต่างหลุด) */
.lb-dialog-dark { width: min(620px, calc(100vw - 32px)); padding: 0; background: transparent; box-shadow: none; overflow: visible; color: var(--lb-ink); }
.lb-dialog-panel {
  padding: 26px; border-radius: 20px; background: var(--lb-ink-dark); border: 1px solid rgba(243, 201, 105, .55);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), 0 0 40px rgba(243, 201, 105, .18);
}
#lobby-screen .lb-dialog-dark :focus-visible { outline-color: var(--lb-gold); }
.lb-mode-deck { display: inline-flex; align-items: center; gap: 10px; padding: 5px 14px 5px 5px; border-radius: 999px; background: #1d2246; font-size: 14px; }
.lb-mode-deck img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; object-position: center 20%; border: 2px solid var(--deck); }
.lb-mode-deck b { color: var(--deck); font-family: var(--font-display); }
.lb-dialog-dark h2 { margin-top: 14px !important; font-size: 30px; }
.lb-modes { margin-top: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.lb-mode {
  position: relative; overflow: hidden; min-height: 190px; padding: 22px 18px 20px; border-radius: 16px;
  border: 1px solid rgba(160, 175, 255, .25); color: var(--lb-ink); font: inherit; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; transition: border-color .2s;
}
.lb-mode:hover { border-color: var(--lb-gold); }
.lb-mode-bot { background: linear-gradient(160deg, #1f3a6b, #141a3a 70%); }
.lb-mode-pvp { background: linear-gradient(160deg, #6b4a14, #2a1d0c 70%); }
.lb-mode-icon { position: absolute; top: 18px; left: 18px; width: 46px; height: 46px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lb-mode-bot .lb-mode-icon { color: #7fd3ff; }
.lb-mode-pvp .lb-mode-icon { color: var(--lb-gold); }
.lb-mode-title { font: 700 22px/1.2 var(--font-display); }
.lb-mode-desc { font-size: 13px; color: #c9cdea; }
/* แสงกวาดตอนชี้ และวงแสงตอนกด — ขยับด้วย transform/opacity (lobby-motion.js) */
.lb-mode-shine { position: absolute; top: 0; bottom: 0; left: 0; width: 40%; pointer-events: none; opacity: 0;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .22), transparent); transform: skewX(-18deg); }
.lb-mode-ring { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; opacity: 0; box-shadow: 0 0 0 3px rgba(243, 201, 105, .8); }
.lb-dialog-close { margin-top: 14px; min-height: 44px; padding: 0 8px; border: 0; background: none; color: inherit; font: 500 16px var(--font-body); text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }
/* สวิตช์ตั้งค่า: checkbox จริงซ่อนด้วยการขยายเต็มแถว (ยังโฟกัส/กดได้) + ราง/ปุ่มเลื่อนวาดเอง */
.lb-switch { position: relative; margin-top: 18px; min-height: 56px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-radius: 12px; background: #e2d5b6; font-size: 16px; cursor: pointer; }
.lb-switch-input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.lb-switch-track { position: relative; flex: none; width: 48px; height: 28px; border-radius: 999px; background: #8d8470; transition: background .2s; }
.lb-switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .4); transition: transform .2s; }
.lb-switch-input:checked + .lb-switch-track { background: #2f7d4f; }
.lb-switch-input:checked + .lb-switch-track::after { transform: translateX(20px); }
.lb-switch:has(.lb-switch-input:focus-visible) { outline: 3px solid var(--lb-ink-dark); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .lb-switch-track, .lb-switch-track::after { transition: none; } }
.lb-steps { margin: 16px 0 0; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; font-size: 16px; line-height: 1.5; }
.lb-steps b { font-family: var(--font-display); margin-right: 6px; }
.lb-counts { margin-top: 16px !important; padding: 10px 14px; border-radius: 10px; background: #e2d5b6; font-size: 14px; }
.lb-dialog-ok { margin-top: 18px; width: 100%; }
#lb-join-dialog .lb-join { background: var(--lb-ink-dark); color: var(--lb-ink); }

/* style.css เอา padding ของ body ออกที่ ≤ 768px → ไม่ต้องชดเชย */
@media (max-width: 768px) { #lobby-screen { width: 100%; margin: 0; } }

/* ================= มือถือ (แนวตั้ง): จัดเลย์เอาต์หัวและแถวอย่างเป็นสัดส่วน ================= */
@media (max-width: 767px) {
  html, body {
    overflow: hidden;
    overscroll-behavior: none;
    height: 100%;
  }
  #lobby-screen {
    position: fixed;
    inset: 0;
    width: 100%;
    margin: 0;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto auto auto;
    justify-items: center;
    align-items: center;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 0;
    gap: 6px;
    overflow: hidden !important;
    overflow: clip !important;
    overscroll-behavior: none;
    touch-action: manipulation;
  }
  .lb-side, .lb-plate { display: contents; }
  #lb-wall { position: fixed; width: 200vw; opacity: .22; }
  .lb-wall-inner { grid-template-columns: repeat(6, 1fr); gap: 2vw; }
  .lb-logo {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    position: relative;
    left: auto;
    top: auto;
    font-size: 18px;
    margin: 0;
    letter-spacing: 0.5px;
    white-space: nowrap;
  }
  #lb-coin-pill {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    position: relative;
    left: auto;
    top: auto;
    height: 34px;
    padding: 0 10px;
    font-size: 13.5px;
    gap: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  }
  #lb-coin-pill .lb-coin-icon { font-size: 15px; }
  #lb-coin-pill .lb-coin-plus { display: none; }
  #lb-auth-bar {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: stretch;
    position: relative;
    left: auto;
    top: auto;
    height: 38px;
    padding: 3px 12px 3px 4px;
    gap: 8px;
    background: rgba(18, 22, 50, 0.88);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  }
  .lb-auth-avatar { width: 30px; height: 30px; }
  /* ฉายาอยู่แถวเดียวกับชื่อ — ซ้อนเป็น 3 บรรทัดแล้วล้นแถบสูง 38px ขึ้นไปทับโลโก้ */
  #lb-auth-bar .lb-auth-meta { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 6px; align-items: center; min-width: 0; }
  #lb-auth-bar .lb-auth-sub { grid-column: 1 / -1; }
  #lb-auth-bar .bof-user-title-pill { padding: 1px 7px; font-size: 10px; }
  .lb-auth-name { font-size: 13px; max-width: 140px; }
  .lb-auth-sub { font-size: 10px; }
  .lb-join-slot, .lb-github, .lb-chips { display: none; }
  .lb-leader-wrap {
    grid-column: 1 / -1;
    grid-row: 3;
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    height: 100%;
    max-height: min(40dvh, 290px);
    min-height: 0;
  }
  .lb-info {
    grid-column: 1 / -1;
    grid-row: 4;
    position: relative;
    left: auto;
    top: auto;
    width: 100%;
    text-align: center;
  }
  .lb-deck-name { font-size: 22px; }
  .lb-leader-name { display: none; }
  .lb-deck-style { margin-top: 1px !important; font-size: 13px; }
  #lb-decks {
    grid-column: 1 / -1;
    grid-row: 5;
    position: relative;
    left: auto;
    bottom: auto;
    transform: none;
    gap: 8px;
    padding-top: 2px;
  }
  .lb-deck { width: 42px; }
  #lb-play {
    grid-column: 1 / -1;
    grid-row: 6;
    position: relative;
    right: auto;
    bottom: auto;
    width: 100%;
    max-width: 320px;
    padding: 10px 16px;
    touch-action: manipulation;
  }
  .lb-play-label { font-size: 21px; }
  .lb-play-glow { inset: 0; }
  /* หน้าต่างเลือกโหมด: การ์ดเรียงลงเป็นแถว ไอคอนอยู่ซ้าย */
  .lb-dialog-dark .lb-dialog-panel { padding: 18px 16px; border-radius: 16px; }
  .lb-dialog-dark h2 { font-size: 22px; }
  .lb-modes { grid-template-columns: 1fr; gap: 10px; }
  .lb-mode { min-height: 80px; padding: 12px 14px 12px 68px; justify-content: center; touch-action: manipulation; }
  .lb-mode-icon { top: 50%; left: 14px; width: 38px; height: 38px; margin-top: -19px; }
  .lb-mode-title { font-size: 18px; }
  .lb-mode-desc { font-size: 12px; }
  .lb-menu {
    grid-column: 1 / -1;
    order: 10;
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    flex-direction: row;
    gap: 0;
    justify-self: stretch;
    margin: 0 -14px;
    width: calc(100% + 28px);
    border-top: 1px solid var(--lb-line);
    background: var(--lb-panel);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .lb-menu-item { flex: 1; width: auto; height: 56px; border: 0; border-radius: 0; background: none; font-size: 11.5px; touch-action: manipulation; }
  .lb-mobile-only { display: flex; }
}

@media (max-width: 767px) and (max-height: 680px) {
  #lobby-screen { gap: 4px; padding-top: 4px; }
  .lb-leader-wrap { max-height: min(34dvh, 230px); }
  .lb-deck-name { font-size: 19px; }
  .lb-deck-style { display: none; }
  .lb-play small { display: none; }
  .lb-play { padding: 8px 14px; }
  .lb-deck { width: 36px; }
  .lb-menu-item { height: 50px; font-size: 11px; }
}


/* ================= ปุ่มกดเลือกเด็ค & หน้าต่างเลือกเด็ค (Deck Picker Modal) ================= */
#lb-decks .lb-deck {
  display: none !important;
}

.lb-deck-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  max-width: 340px;
  padding: 7px 12px 7px 8px;
  border-radius: 14px;
  border: 1.5px solid rgba(243, 201, 105, 0.6);
  background: linear-gradient(145deg, rgba(24, 30, 68, 0.96), rgba(14, 18, 42, 0.96));
  color: var(--lb-ink);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 18px rgba(243, 201, 105, 0.16);
  cursor: pointer;
  text-align: left;
  transition: transform 0.18s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  touch-action: manipulation;
}

.lb-deck-picker-btn:hover {
  border-color: var(--lb-gold-hi);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.6), 0 0 22px rgba(243, 201, 105, 0.32);
  transform: translateY(-2px);
}

.lb-deck-picker-btn:active {
  transform: scale(0.98);
}

.lb-deck-picker-thumb {
  width: 36px;
  height: 50px;
  border-radius: 6px;
  object-fit: cover;
  border: 1.5px solid var(--deck);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  flex-shrink: 0;
}

.lb-deck-picker-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.lb-deck-picker-sub {
  font-size: 11px;
  color: var(--lb-ink-soft);
  line-height: 1.2;
}

.lb-deck-picker-name {
  font: 700 16px/1.2 var(--font-display);
  color: var(--deck);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-deck-picker-cta {
  padding: 7px 12px;
  border-radius: 10px;
  background: rgba(243, 201, 105, 0.16);
  border: 1px solid rgba(243, 201, 105, 0.5);
  color: var(--lb-gold-hi);
  font: 700 13px/1 var(--font-display);
  white-space: nowrap;
  flex-shrink: 0;
}

/* หน้าต่างเลือกเด็ค: "ชั้นวางเด็ค" — แถวละเด็ค ภาพลีดเดอร์เอียง + ชื่อสีประจำเด็ค + สไตล์การเล่น · เด็คจัดเองเป็นปุ่มสล็อตกดครั้งเดียว */
#lb-deck-picker-dialog { width: min(1340px, calc(100vw - 32px)); }
.lb-deck-picker-panel {
  display: flex; flex-direction: column; max-height: min(88vh, 88dvh); padding: 22px 24px 16px;
  background: linear-gradient(180deg, #171c40 0%, #0f1229 60%);
  border-radius: 20px;
  border: 1px solid rgba(160, 175, 255, 0.22);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7), 0 0 40px rgba(15, 18, 41, 0.6);
}
.lb-deck-picker-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.lb-deck-picker-head h2 { margin: 0 !important; font-size: 26px !important; color: var(--lb-gold-hi); }
.lb-deck-picker-desc { margin-top: 4px !important; font-size: 13.5px; color: var(--lb-ink-soft); }
.lb-deck-picker-x {
  width: 44px; height: 44px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 1px solid rgba(160, 175, 255, .3); background: rgba(255, 255, 255, .06);
  color: var(--lb-ink); font-size: 16px; cursor: pointer;
  transition: border-color .18s ease, background-color .18s ease;
}
.lb-deck-picker-x:hover { border-color: var(--lb-gold); background: rgba(243, 201, 105, 0.12); }
.lb-deck-picker-body {
  min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 4px 8px 12px; -webkit-overflow-scrolling: touch;
}
#lobby-screen .lb-picker-section {
  display: flex; align-items: center; gap: 10px; margin: 6px 0 10px;
  font: 600 13.5px/1.2 var(--font-display); color: var(--lb-ink-soft);
}
.lb-picker-section::after { content: ''; flex: 1; height: 1px; background: rgba(160, 175, 255, .18); }

.lb-deck-picker-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; }
.lb-picker-item {
  position: relative; display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 14px;
  padding: 12px 14px; border-radius: 16px; border: 1.5px solid rgba(160, 175, 255, .16);
  background: linear-gradient(135deg, color-mix(in srgb, var(--item-accent) 14%, #121532) 0%, #0e1126 100%);
  color: var(--lb-ink); text-align: left; cursor: pointer; overflow: hidden; touch-action: manipulation;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
  transition: border-color .2s ease, transform .16s ease, box-shadow .2s ease;
}
.lb-picker-item::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--item-accent); opacity: .45; }
.lb-picker-item:hover { border-color: var(--item-accent); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0, 0, 0, .45); }
.lb-picker-item.is-selected { border-color: var(--item-accent); box-shadow: 0 0 0 1.5px var(--item-accent), 0 10px 28px rgba(0, 0, 0, .55); }
.lb-picker-item.is-selected::before { opacity: 1; }
.lb-picker-item:last-child:nth-child(odd) { grid-column: auto; }
.lb-picker-art {
  width: 64px; aspect-ratio: 750 / 1050; border-radius: 8px; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .55); transform: none; transition: transform .2s ease, box-shadow .2s ease;
}
.lb-picker-item:hover .lb-picker-art, .lb-picker-item.is-selected .lb-picker-art { transform: scale(1.04); box-shadow: 0 8px 20px rgba(0, 0, 0, .65); }
.lb-picker-art img { display: block; width: 100%; height: 100%; object-fit: cover; }
.lb-picker-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lb-picker-item.is-selected .lb-picker-meta { padding-right: 52px; }
.lb-picker-name { font: 700 16px/1.2 var(--font-display); color: var(--item-accent); letter-spacing: 0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-picker-leader { font-size: 11.5px; color: var(--lb-ink-soft); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-picker-style {
  margin-top: 4px; font-size: 11px; line-height: 1.4; color: #cbd5e1; opacity: .9;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lb-picker-tag {
  position: absolute; top: 10px; right: 10px; padding: 2px 8px; border-radius: 999px;
  background: var(--item-accent); color: var(--lb-ink-dark); font: 700 11px/1.4 var(--font-display);
}

/* เด็คที่จัดเอง: 5 สล็อต กดแล้วใช้ทันที */
.lb-deck-picker-slots { margin-top: 14px; }
.lb-slot-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.lb-slot-chip {
  position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 10px; min-width: 0;
  padding: 10px 10px; border-radius: 14px; border: 1.5px solid rgba(160, 175, 255, .18);
  background: linear-gradient(135deg, color-mix(in srgb, var(--item-accent) 10%, #121532) 0%, #0e1126 100%);
  color: var(--lb-ink); text-align: left; cursor: pointer; touch-action: manipulation; overflow: hidden;
  transition: border-color .2s ease, transform .16s ease, box-shadow .2s ease;
}
.lb-slot-art { width: 44px; aspect-ratio: 750 / 1050; border-radius: 6px; overflow: hidden; border: 1px solid rgba(255,255,255,.15); box-shadow: 0 4px 10px rgba(0,0,0,.5); }
.lb-slot-art img { display: block; width: 100%; height: 100%; object-fit: cover; }
.lb-slot-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lb-slot-num { font: 700 10.5px/1.2 var(--font-display); color: var(--item-accent); opacity: .9; }
.lb-slot-name { max-width: 100%; font: 700 13px/1.25 var(--font-display); color: #f1f5f9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-slot-sub { font-size: 11px; color: #94a3b8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-slot-sub.is-ready { color: #86efac; }
.lb-slot-chip:hover { border-color: var(--item-accent); transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,.4); }
.lb-slot-chip.is-selected { border-color: var(--item-accent); box-shadow: 0 0 0 1.5px var(--item-accent), 0 10px 24px rgba(0,0,0,.5); }
.lb-slot-chip .lb-picker-tag { top: 6px; right: 6px; font-size: 10px; padding: 1px 6px; }

.lb-deck-picker-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(160, 175, 255, .18);
}
.lb-deck-picker-builder-btn {
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid rgba(243, 201, 105, .55);
  background: rgba(243, 201, 105, .08); color: var(--lb-gold-hi); font: 600 14px/1.2 var(--font-display); cursor: pointer;
}
.lb-deck-picker-builder-btn:hover { background: rgba(243, 201, 105, .16); }
.lb-deck-picker-footer .lb-dialog-close { margin-top: 0; }
@media (prefers-reduced-motion: reduce) {
  .lb-picker-item, .lb-picker-art { transition: none; }
  .lb-picker-item:hover { transform: none; }
}

@media (min-width: 768px) and (max-width: 1120px) {
  #lb-deck-picker-dialog { width: min(880px, calc(100vw - 24px)); }
  .lb-deck-picker-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 767px) {
  #lb-decks {
    width: 100%;
    max-width: 320px;
    justify-content: center;
  }

  .lb-deck-picker-btn {
    width: 100%;
    max-width: 320px;
    min-width: 0;
    padding: 6px 10px 6px 8px;
  }


  #lb-deck-picker-dialog { width: calc(100vw - 16px); }
  .lb-deck-picker-panel { padding: 16px 14px 10px; }
  .lb-deck-picker-head h2 { font-size: 20px !important; }
  .lb-deck-picker-grid { grid-template-columns: 1fr; gap: 8px; }
  .lb-picker-item { display: grid; grid-template-columns: 50px minmax(0, 1fr); text-align: left; align-items: center; gap: 12px; padding: 9px 10px 9px 12px; }
  .lb-picker-item::before { top: 0; bottom: 0; left: 0; right: auto; width: 4px; height: auto; }
  .lb-picker-art { width: 50px; }
  .lb-picker-meta { align-items: flex-start; }
  .lb-picker-name { font-size: 16px; }
  .lb-picker-style { margin-top: 3px; font-size: 12px; background: transparent; padding: 0; }
  .lb-picker-tag { top: 10px; right: 10px; font-size: 11.5px; padding: 2px 10px; }
  .lb-slot-row { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; }
  .lb-slot-chip { flex: 0 0 96px; scroll-snap-align: start; }
}


/* ================= Safari & Samsung Browser Fallbacks ================= */
dialog.bof-dialog-polyfilled[open] {
  position: fixed;
  inset: 0;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  display: block;
  max-height: 90vh;
  overflow-y: auto;
}

@supports not (height: 100dvh) {
  @media (max-width: 767px) {
    #lobby-screen {
      height: 100vh;
      max-height: 100vh;
    }
    .lb-leader-wrap {
      max-height: min(40vh, 290px);
    }
    .lb-deck-picker-panel {
      max-height: 86vh;
    }
    .lb-deck-picker-panel .lb-deck-picker-body { max-height: none; }
  }
}

/* ================= หน้าต่างตั้งค่า (แบบ A "แผงมืดแบ่งกลุ่ม") — การเล่น / เสียง / สนาม ================= */
.lb-settings { width: min(480px, calc(100vw - 24px)); }
.lb-settings-panel { padding: 22px; max-height: min(90vh, 90dvh); overflow-y: auto; }
.st-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#lobby-screen .st-head h2 { margin: 0 !important; font: 700 26px/1.2 var(--font-display); color: var(--lb-gold-hi); }
.st-x { width: 44px; height: 44px; flex-shrink: 0; display: inline-grid; place-items: center; border-radius: 50%; border: 1px solid rgba(160, 175, 255, .32); background: rgba(255, 255, 255, .05); color: var(--lb-ink); cursor: pointer; }
.st-x:hover { border-color: var(--lb-gold); }
.st-x svg, .st-ico, .st-btn svg, .st-admin svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.st-x svg { width: 18px; height: 18px; }
.st-group { margin-top: 18px; }
#lobby-screen .st-group h3 { margin: 0 0 8px; font: 600 14px/1.2 var(--font-display); color: #8a90b8; }
.st-card { border-radius: 14px; background: #141834; border: 1px solid rgba(160, 175, 255, .18); }
.st-row { position: relative; display: flex; align-items: center; gap: 12px; min-height: 62px; padding: 10px 14px; cursor: pointer; }
.st-row:has(.lb-switch-input:focus-visible) { outline: 3px solid var(--lb-gold); outline-offset: 2px; border-radius: 14px; }
.st-ico { width: 20px; height: 20px; flex-shrink: 0; color: var(--lb-gold); }
.st-text { flex: 1; min-width: 0; }
.st-text b { display: block; font: 600 15px/1.3 var(--font-display); }
.st-text small, .st-arena-body small { display: block; font-size: 12.5px; line-height: 1.4; color: #8a90b8; }
.lb-settings .lb-switch-track { background: #2b3160; }
.lb-settings .lb-switch-input:checked + .lb-switch-track { background: #2fae6b; }
.st-vol { display: flex; align-items: center; gap: 12px; padding: 0 14px 14px 46px; transition: opacity .25s; }
.st-vol label { font-size: 13px; color: var(--lb-ink-soft); }
.st-vol input { flex: 1; min-height: 28px; accent-color: var(--lb-gold); cursor: pointer; }
.st-vol output { width: 40px; text-align: right; font: 600 13px var(--font-display); color: var(--lb-ink-soft); }
.st-vol.is-off { opacity: .4; }
.st-vol.is-off input { cursor: not-allowed; }
.st-arena { display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 14px; align-items: center; padding: 14px; }
.st-arena-prev {
  aspect-ratio: 16 / 10; border-radius: 10px; border: 1px solid rgba(160, 175, 255, .32); overflow: hidden;
  display: grid; place-items: center; background: linear-gradient(160deg, #23306b, #0d1130) center / cover no-repeat;
  color: #8a90b8; font-size: 12px; transition: background-image .3s;
}
.st-arena-prev.has-img span { display: none; }
.st-arena-body b { display: block; font: 600 15px/1.3 var(--font-display); }
.st-arena-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.st-btn { min-height: 42px; padding: 0 14px; border-radius: 11px; border: 0; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: 600 14px var(--font-display); cursor: pointer; touch-action: manipulation; }
.st-btn svg { width: 17px; height: 17px; }
.st-btn-gold { position: relative; overflow: hidden; color: #1a1405; background: linear-gradient(135deg, var(--lb-gold-hi), var(--lb-gold-lo)); }
.st-btn-ghost { color: var(--lb-ink); background: rgba(255, 255, 255, .04); border: 1px solid rgba(160, 175, 255, .32); }
.st-btn-ghost:hover { border-color: var(--lb-gold); }
.st-btn-gold:has(.st-file:focus-visible) { outline: 3px solid var(--lb-gold); outline-offset: 2px; }
.st-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.st-status { margin: 8px 0 0 !important; font-size: 12px; color: #4ade80; }
.st-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 20px; }
.st-admin { min-height: 44px; padding: 0 6px; border: 0; background: none; color: #8a90b8; font: 500 13px var(--font-body); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.st-admin:hover { color: var(--lb-ink); }
.st-admin svg { width: 15px; height: 15px; }
.st-done { min-height: 44px; padding: 0 22px; }
@media (max-width: 420px) {
  .lb-settings-panel { padding: 18px 14px; }
  .st-arena { grid-template-columns: 1fr; }
  .st-vol { padding-left: 14px; }
}
