/* nav.css — เมนูหลัก: มือถือ/แท็บเล็ตติดล่างจอ, PC > 860px ติดบนจอ (2026-11-02 ผู้ใช้กำหนด) — ไฟล์กลางไฟล์แรกของเกม: แก้เมนูที่นี่ที่เดียว
   ใช้กับ <nav class="bnav"> ในหน้า index/attack/hangar/shop/history/boss (ลิงก์ <link rel="stylesheet" href="/nav.css"> ต่อจาก <style> ของหน้า
   — โหลดทีหลังจึงทับ .nav-link ของแต่ละหน้า) · หน้าใหม่ที่มีเมนูหลักใส่ทั้ง class bnav และลิงก์ไฟล์นี้
   PC/แท็บเล็ต: แถบลอยกลางจอ ขอบมน ไอคอน + ชื่อเรียงแนวนอน · มือถือ ≤ 640px: แถบเต็มความกว้างติดขอบล่าง ไอคอนบน ชื่อล่าง
   --bnav-h = ความสูงที่แถบบังล่างจอ — body เว้นที่เท่านี้ (เนื้อหาท้ายหน้าไม่ถูกบัง), ของที่ติดล่างจอเอง (sticky/fixed) ใช้ค่านี้ยกขึ้นพ้นแถบ */
:root { --bnav-h: 72px; }
@media (max-width: 640px) { :root { --bnav-h: calc(60px + env(safe-area-inset-bottom)); } }

body { padding-bottom: calc(var(--bnav-h) + 16px); }

nav.bnav {
  position: fixed; z-index: 40; left: 50%; bottom: 12px; transform: translateX(-50%);
  display: flex; flex-wrap: nowrap; gap: 4px; margin: 0; padding: 5px; max-width: calc(100vw - 24px);
  background: color-mix(in srgb, var(--panel, #171b27) 90%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid var(--line, #2a3042); border-radius: 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
nav.bnav[hidden] { display: none; }
nav.bnav .nav-link {
  position: relative; display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; margin: 0;
  border: 0; border-radius: 11px; background: transparent; color: var(--muted, #9aa3b5);
  font-size: 14px; line-height: 1.2; white-space: nowrap; text-decoration: none;
}
nav.bnav .nav-link .ico { margin: 0; font-size: 17px; line-height: 1; }
@media (hover: hover) { nav.bnav a.nav-link:hover { background: var(--panel-2, #1f2433); color: var(--fg, #e8ecf4); } }
nav.bnav .nav-link.current { background: var(--torch, #f0a03c); color: #20160a; font-weight: 600; cursor: default; }
nav.bnav .nav-link:focus-visible { outline: 2px solid var(--torch, #f0a03c); outline-offset: 2px; }
nav.bnav .atk-badge { top: -5px; right: -4px; }   /* ตัวเลขถูกโจมตีใหม่ (session.mjs mountAttackBadge) */

/* PC > 860px (2026-11-02 ผู้ใช้กำหนด): แถบลอยกลางด้านบน — ลูกแรกของ .wrap (ก่อน <header>) แบบ sticky = อยู่ในหน้าตามปกติ เลื่อนแล้วติดขอบบน
   ไม่ใช้ fixed (ไม่ต้องเว้นที่บนทุกหน้า / ไม่ทับแถบติดตั้งแอปของหน้าแรก) · ป้าย EMERGENCY (session.mjs, sticky บนสุด 30px) แสดง → แถบติดใต้ป้าย
   --tnav-h = ที่ที่แถบบนบังตอนติดขอบ — ของที่ติดขอบบนเอง (คอลัมน์เวทีโรงเก็บ) ใช้ค่านี้เลื่อนลง */
:root:has(.emg:not([hidden])) { --emg-h: 30px; }
@media (min-width: 861px) {
  :root { --bnav-h: 0px; --tnav-h: calc(var(--emg-h, 0px) + 70px); }
  nav.bnav { position: sticky; top: calc(var(--emg-h, 0px) + 10px); left: auto; bottom: auto; transform: none;
    justify-self: center; width: fit-content; margin: 0 auto; }
}

@media (max-width: 640px) {
  nav.bnav {
    left: 0; right: 0; bottom: 0; transform: none; max-width: none; gap: 0;
    padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
    border-width: 1px 0 0; border-radius: 0; box-shadow: 0 -6px 20px rgba(0, 0, 0, .4);
  }
  nav.bnav .nav-link {
    flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 3px;
    padding: 6px 2px 5px; font-size: 11px; border-radius: 10px; overflow: hidden; text-overflow: ellipsis;
  }
  nav.bnav .nav-link .ico { font-size: 21px; }
  /* หน้าปัจจุบัน: ไอคอน + ชื่อสีส้มบนพื้นส้มจาง (พื้นส้มทึบทั้งช่องดูหนักเกินในแถบเต็มความกว้าง) */
  nav.bnav .nav-link.current { background: color-mix(in srgb, var(--torch, #f0a03c) 16%, transparent); color: var(--torch, #f0a03c); }
  nav.bnav .atk-badge { top: 1px; right: auto; left: calc(50% + 5px); }
}

/* ---------- ปุ่ม ⚙️ ตั้งค่า + การ์ดเมนูย่อย + dialog เปลี่ยนรหัสผ่าน (2026-11-02, การทำงานอยู่ใน session.mjs initSettings) ---------- */
nav.bnav button.nav-link { font: inherit; font-size: 14px; cursor: pointer; }
nav.bnav .setbtn[aria-expanded="true"] { background: var(--panel-2, #1f2433); color: var(--fg, #e8ecf4); }
/* หน้าแรกตอนยังไม่มีผู้เล่น/server ผิดพลาด: แถบมีแค่ปุ่มตั้งค่า (ออกจากระบบได้) */
nav.bnav.only-set > .nav-link:not(.setbtn) { display: none; }
@media (max-width: 640px) {
  nav.bnav button.nav-link { font-size: 11px; }
  nav.bnav.only-set { left: auto; right: 0; width: 25%; border-left-width: 1px; border-top-left-radius: 14px; }
}

.setcard {
  position: fixed; z-index: 45; min-width: 220px; max-width: calc(100vw - 16px); padding: 8px; display: grid; gap: 4px;
  background: var(--panel, #171b27); border: 1px solid var(--line, #2a3042); border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .55); color: var(--fg, #e8ecf4); font-size: 14px;
  animation: setcardIn .14s ease-out;
}
@keyframes setcardIn { from { opacity: 0; translate: 0 6px; } }
.setcard.down { animation-name: setcardDown; }
@keyframes setcardDown { from { opacity: 0; translate: 0 -6px; } }
@media (prefers-reduced-motion: reduce) { .setcard { animation: none; } }
.setcard .sc-acct { display: grid; gap: 2px; padding: 6px 10px 10px; border-bottom: 1px solid var(--line, #2a3042); margin-bottom: 4px; }
.setcard .sc-lbl { font-size: 12px; color: var(--muted, #9aa3b5); }
.setcard .sc-mail { font-weight: 600; overflow-wrap: anywhere; }
.setcard :is(button, a) { display: flex; text-decoration: none; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit; color: inherit;
  background: transparent; border: 0; border-radius: 9px; padding: 10px; cursor: pointer; }
.setcard :is(button, a):hover, .setcard :is(button, a):focus-visible { background: var(--panel-2, #1f2433); outline: none; }
.setcard :is(button, a) .ico { margin: 0; font-size: 17px; }

.pwdlg { border: 1px solid var(--line, #2a3042); border-radius: 14px; background: var(--panel, #171b27); color: var(--fg, #e8ecf4);
  padding: 0; width: min(420px, calc(100vw - 32px)); }
.pwdlg::backdrop { background: rgba(4, 6, 12, .7); }
.pwdlg .pwd-form { margin: 0; padding: 18px; display: grid; gap: 12px; }
.pwdlg h2 { margin: 0; font-size: 19px; font-weight: 500; font-family: var(--font-display, inherit); }
.pwdlg .pwd-field { display: grid; gap: 4px; font-size: 14px; color: var(--muted, #9aa3b5); }
.pwdlg input { background: var(--bg, #12151f); border: 1px solid var(--line, #2a3042); border-radius: 7px; padding: 9px 10px;
  font: inherit; color: var(--fg, #e8ecf4); width: 100%; box-sizing: border-box; }
.pwdlg .pwd-msg { margin: 0; font-size: 14px; color: var(--muted, #9aa3b5); }
.pwdlg .pwd-msg:empty { display: none; }
.pwdlg .pwd-msg.err { color: var(--team-a, #ff6b6b); } .pwdlg .pwd-msg.ok { color: var(--heal, #5fd38d); }
.pwdlg .pwd-row { display: flex; gap: 8px; justify-content: flex-end; }
.pwdlg .pwd-row button { font: inherit; color: inherit; cursor: pointer; background: var(--panel-2, #1f2433);
  border: 1px solid var(--line, #2a3042); border-radius: 8px; padding: 8px 14px; }
.pwdlg .pwd-row .pwd-save { background: var(--torch, #f0a03c); border-color: var(--torch, #f0a03c); color: #20160a; font-weight: 600; }
.pwdlg .pwd-row button:disabled { opacity: .45; cursor: default; }

/* ตั้งค่าการต่อสู้ (session.mjs openBattleSettings) — ใช้กรอบ .pwdlg ร่วมกัน */
.btldlg .btl-row { border: 0; margin: 0; padding: 10px 0 0; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 15px; color: var(--fg, #e8ecf4); }
.btldlg .btl-row + .btl-row { border-top: 1px solid var(--line, #2a3042); }
.btldlg legend { float: left; padding: 0; }
.btldlg .btl-row .ico { margin-right: 8px; }
.btldlg .btl-seg { display: flex; border: 1px solid var(--line, #2a3042); border-radius: 10px; overflow: hidden; margin-left: auto; }
.btldlg .btl-seg label { position: relative; }
.btldlg .btl-seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.btldlg .btl-seg span { display: block; padding: 7px 16px; font-weight: 600; color: var(--muted, #9aa3b5); }
.btldlg .btl-seg label + label span { border-left: 1px solid var(--line, #2a3042); }
.btldlg .btl-seg input:checked + span { background: var(--torch, #f0a03c); color: #20160a; }
.btldlg .btl-seg input:focus-visible + span { outline: 2px solid var(--torch, #f0a03c); outline-offset: -2px; }
.btldlg .btl-sw { cursor: pointer; }
/* สวิตช์เปิด/ปิด */
.btldlg .btl-sw input { appearance: none; -webkit-appearance: none; width: 46px; height: 26px; margin: 0; flex: none; padding: 0;
  border-radius: 999px; background: var(--panel-2, #1f2433); border: 1px solid var(--line, #2a3042); position: relative; cursor: pointer; transition: background .15s; }
.btldlg .btl-sw input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--muted, #9aa3b5); transition: translate .15s, background .15s; }
.btldlg .btl-sw input:checked { background: var(--torch, #f0a03c); border-color: var(--torch, #f0a03c); }
.btldlg .btl-sw input:checked::after { translate: 20px 0; background: #20160a; }
.btldlg .btl-sw input:focus-visible { outline: 2px solid var(--torch, #f0a03c); outline-offset: 2px; }
.btldlg .pwd-msg { font-size: 12.5px; }
