* { box-sizing: border-box; }
body { margin: 0; background: #15171c; color: #e8e8e8; font-family: "Segoe UI", Tahoma, sans-serif; }
.hidden { display: none !important; }
.dim { color: #9aa0ab; font-size: 12px; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 6px; background: #2f6fe0; color: #fff; padding: 8px 14px; }
button:disabled { background: #3a3f4a; color: #777; cursor: default; }

.screen { padding: 24px; }

/* หน้าแรก */
#title { text-align: center; padding-top: 36px; }
#title .logo { display: block; width: 104px; height: 104px; margin: 0 auto 10px; }
#title h1 { font-size: 48px; margin: 0; letter-spacing: 3px; }
#title .beta { display: inline-block; margin-top: 6px; padding: 2px 12px; border: 1px solid #ffd84a; border-radius: 12px; color: #ffd84a; font-size: 13px; letter-spacing: 1px; }
#diffBox { margin-top: 26px; }
#diffBox span { margin-right: 10px; color: #c9ced6; }
#diffBox button { background: #20242c; border: 2px solid #333842; border-radius: 0; padding: 8px 22px; color: #c9ced6; }
#diffBox button:first-of-type { border-radius: 6px 0 0 6px; }
#diffBox button:last-of-type { border-radius: 0 6px 6px 0; }
#diffBox button.on { background: #2b3040; border-color: #ffd84a; color: #fff; font-weight: bold; }
#diffNote { margin-top: 8px; }
#title p { color: #9aa0ab; }
#pick .cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 20px auto 0; max-width: 860px; }
#pick .card { background: #20242c; border: 2px solid #333842; padding: 14px 22px; font-size: 18px; font-weight: bold; min-width: 150px; color: #e8e8e8; }
#pick .card span { display: block; font-size: 12px; font-weight: normal; color: #9aa0ab; margin-top: 4px; }
#pick .card.on { border-color: #ffd84a; background: #2b3040; }
#pick .card.flag { position: relative; padding: 0; min-width: 0; width: 132px; height: 88px; overflow: hidden; border-width: 3px; }
#pick .card.flag img { display: block; width: 100%; height: 100%; object-fit: cover; }
#pick .card.flag span { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 2px; background: rgba(0,0,0,.72); font-size: 14px; opacity: 0; transition: opacity .12s; }
#pick .card.flag:hover span, #pick .card.flag.on span { opacity: 1; }
#pick .card.flag.custom { font-size: 34px; color: #9aa0ab; }
#pick .card.flag.locked img { filter: grayscale(1) brightness(.45); }
#pick .card.flag.locked { cursor: not-allowed; }
#toast { position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%); background: #1b1e25; border: 1px solid #ffd84a; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 15px; z-index: 30; pointer-events: none; }
#pickTitle { font-size: 20px; font-weight: bold; }
#continueBox { margin: 22px 0 6px; display: flex; gap: 8px; justify-content: center; }
#btnContinue { font-size: 18px; padding: 14px 28px; background: #1f9d55; }
#btnContinue span { display: block; font-size: 12px; font-weight: normal; opacity: .9; margin-top: 3px; }
#banner small { font-size: 15px; font-weight: normal; }
#btnDelSave { font-size: 13px; }
#pickInfo { margin-top: 14px; min-height: 22px; color: #c9ced6; }
#customBox { margin-top: 16px; }
#customBox input, #customBox select { font: inherit; padding: 6px 8px; border-radius: 6px; border: 1px solid #444a56; background: #20242c; color: #e8e8e8; margin: 0 10px 0 4px; }
#countryUnits { max-width: 900px; margin: 10px auto 0; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.ucard { background: #20242c; padding: 0; width: 132px; overflow: hidden; border: 2px solid #333842; }
.ucard:hover { border-color: #ffd84a; }
.ucard img { display: block; width: 100%; height: 86px; object-fit: cover; }
.ucard span { display: block; padding: 5px 4px; font-size: 12px; line-height: 1.3; }
button.ghost { background: #3a3f4a; }
#panel .keys i { display: inline-block; width: 12px; height: 12px; vertical-align: -1px; margin: 0 3px 0 6px; }
#panel .keys i:first-child { margin-left: 0; }
#pick { text-align: center; padding-top: 28px; }
#pick .modes { margin-top: 22px; display: flex; gap: 16px; justify-content: center; }
#pick .modes button { font-size: 18px; padding: 14px 30px; }
#title .modes button span { display: block; font-size: 12px; font-weight: normal; opacity: .85; margin-top: 4px; }
#pickSteps { display: flex; gap: 10px; justify-content: center; margin-bottom: 6px; }
#pickSteps div { padding: 7px 16px; border-radius: 20px; background: #20242c; color: #7d838e; font-size: 14px; border: 2px solid transparent; }
#pickSteps div.now { color: #fff; border-color: #ffd84a; }
#pickSteps div.done { color: #7be29b; }
#title .modes { margin-top: 28px; display: flex; gap: 16px; justify-content: center; }
#title .modes button { font-size: 22px; padding: 22px 44px; min-width: 220px; }

/* ซื้อหน่วย */
#shop { max-width: 980px; margin: 0 auto; }
#shop h2 { margin: 0 0 4px; }
#shopBack { margin-bottom: 12px; padding: 6px 12px; font-size: 13px; }
#shopKept { margin: 0 0 12px; padding: 10px 14px; background: #1d2a22; border-radius: 6px; font-size: 14px; }
#shopKept .chip { display: inline-flex; align-items: center; gap: 6px; margin: 6px 14px 0 0; }
#shopKept .chip.gone { opacity: .55; }
#shopKept .chip button { padding: 4px 8px; font-size: 12px; background: #8a5a12; }
#shopKept .chip button.ghost { background: #3a3f4a; }
#shopKept .chip button:disabled { background: #3a3f4a; }
#shop #shopKept .thumb { width: 44px; height: 32px; border-width: 2px; }
#shop .thumb { cursor: pointer; }
#shop tr.group td { padding: 12px 10px; color: #ffd84a; font-weight: bold; border-bottom: 1px solid #555; cursor: pointer; background: #1d2028; }
#shop tr.group:hover td { background: #262a33; }
#shop tr.group .dim { font-weight: normal; margin-left: 8px; }
/* แถบงบ + ปุ่มเริ่มรบ ติดขอบบนเสมอ ไม่ต้องเลื่อนลงไปหา */
#shopBar { position: sticky; top: 0; z-index: 4; display: flex; align-items: center; gap: 14px; margin: 12px 0; padding: 10px 14px; background: #20242c; border-radius: 6px; box-shadow: 0 6px 12px rgba(0,0,0,.45); }
#shopBudget { flex: 1; }
#shopBudget b { color: #ffd84a; font-size: 18px; }
#shop table { width: 100%; border-collapse: collapse; }
#shop th { text-align: left; font-size: 12px; color: #9aa0ab; padding: 6px 8px; border-bottom: 1px solid #333842; }
#shop td { padding: 4px 8px; border-bottom: 1px solid #262a33; vertical-align: middle; }
#shop .thumb { display: block; width: 84px; height: 58px; object-fit: cover; border-radius: 6px; border: 3px solid; }
#shop .price { color: #ffd84a; font-weight: bold; }
#shop .qty { white-space: nowrap; }
#shop .qty span { display: inline-block; width: 30px; text-align: center; font-weight: bold; }
#shop .qty button { width: 30px; padding: 4px 0; }
#shopGo { flex: none; font-size: 16px; padding: 12px 28px; background: #1f9d55; }

/* รบ */
#battle .wrap { display: flex; gap: 16px; align-items: flex-start; }
#cvWrap { flex: none; max-width: 100%; }
#cv { display: block; border: 2px solid #333842; cursor: pointer; touch-action: manipulation; }
button { touch-action: manipulation; }
#panel { width: 280px; flex: none; }
#btnSound { position: fixed; right: 12px; bottom: 12px; padding: 6px 12px; font-size: 13px; z-index: 5; }
#stageName { margin-bottom: 6px; }
#turn { padding: 10px 12px; border-radius: 6px; font-weight: bold; }
#info { margin-top: 12px; padding: 12px; background: #20242c; border-radius: 6px; min-height: 300px; }
#info .photo { cursor: pointer; display: block; width: 100%; height: 160px; object-fit: cover; border-radius: 6px; margin-bottom: 10px; background: #111; }
#info .uname { font-weight: bold; font-size: 16px; border-left: 5px solid; padding-left: 8px; }
#info .stats { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0; font-size: 14px; }
#info .heal { margin-top: 8px; padding: 6px 8px; background: #16351f; border-radius: 6px; font-size: 13px; color: #7be29b; }
#info .heal.off { background: #2a2d35; color: #9aa0ab; }
#info .terr { margin-top: 10px; padding-top: 8px; border-top: 1px solid #333842; font-size: 13px; }
#info .pred { margin-top: 10px; padding: 8px; background: #3a1f1c; border-radius: 6px; font-size: 14px; }
#hint { margin: 12px 0 4px; font-size: 13px; color: #c9ced6; min-height: 36px; }
#left { font-size: 13px; color: #9aa0ab; min-height: 18px; }
#panel .btns { display: flex; gap: 8px; margin-top: 10px; }
#panel .btns button { flex: 1; padding: 8px 4px; }
#btnPhotos { width: 100%; margin-top: 10px; padding: 6px 4px; font-size: 12px; }
#btnEnd { background: #b5761a; }
/* ป้ายปุ่มลัดบนปุ่ม (ซ่อนบนจอสัมผัสที่ไม่มีคีย์บอร์ด) */
#panel .btns kbd { display: block; margin-top: 2px; font: 10px "Segoe UI", sans-serif; opacity: .75; }
@media (hover: none) { #panel .btns kbd { display: none; } }
#panel .keys { margin-top: 14px; font-size: 12px; color: #7d838e; line-height: 1.7; }

#banner { position: fixed; top: 40%; left: 0; right: 0; text-align: center; padding: 18px; font-size: 26px; font-weight: bold; color: #fff; pointer-events: none; opacity: .93; }
#result { position: fixed; inset: 0; background: rgba(0,0,0,.72); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
#resultText { font-size: 38px; font-weight: bold; }
#resultSub { text-align: center; line-height: 1.7; font-size: 14px; }

/* รายละเอียดหน่วยรบ */
#detail { position: fixed; inset: 0; background: rgba(0,0,0,.78); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
#detail .box { position: relative; background: #1b1e25; border: 1px solid #3a3f4a; border-radius: 10px; padding: 18px; width: 560px; max-width: 100%; max-height: 100%; overflow: auto; }
#detailClose { position: absolute; top: 12px; right: 12px; padding: 5px 10px; font-size: 13px; }
#detailImg { display: block; width: 100%; max-height: 330px; object-fit: contain; background: #0d0f13; border-radius: 6px; }
#detail h2 { margin: 12px 0 2px; }
#detailRows { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
#detailRows th { text-align: left; color: #9aa0ab; font-weight: normal; width: 150px; padding: 5px 8px 5px 0; vertical-align: top; border-bottom: 1px solid #2a2e37; }
#detailRows td { padding: 5px 0; border-bottom: 1px solid #2a2e37; }
#detailGame { margin-top: 12px; padding: 8px 10px; background: #20242c; border-radius: 6px; font-size: 13px; }
#detailWiki { display: inline-block; margin-top: 12px; color: #7fb0ff; font-size: 13px; }

/* หน้าแรก: เมนูแนวตั้ง ปุ่มกว้างเท่ากัน ปุ่มบนสุดคือสิ่งที่ควรกด ตัวเลือกรองตัวเล็กอยู่ด้านล่าง */
#title .menu { width: 340px; max-width: 100%; margin: 34px auto 0; display: flex; flex-direction: column; gap: 10px; }
#titleModes { display: flex; flex-direction: column; gap: 10px; }
#title .menu button { width: 100%; min-height: 58px; padding: 10px 16px; font-size: 17px; }
#title .menu button span { display: block; font-size: 12px; font-weight: normal; opacity: .85; margin-top: 2px; }
#btnContinue { background: #1f9d55; }
#diffBox { margin-top: 22px; font-size: 13px; }
#diffBox button { padding: 5px 16px; font-size: 13px; }
#diffNote { font-size: 12px; }
#btnDelSave { margin-top: 18px; background: none; color: #7d838e; font-size: 12px; text-decoration: underline; padding: 4px 8px; }
#btnDelSave:hover { color: #e8e8e8; }

/* ---------- จอแคบ (มือถือ / แท็บเล็ตแนวตั้ง) ---------- */
@media (max-width: 899px) {
  .screen { padding: 12px; }
  #btnSound { top: 6px; bottom: auto; right: 6px; padding: 4px 8px; font-size: 11px; opacity: .85; }
  #banner { font-size: 19px; padding: 12px; }
  #resultText { font-size: 24px; text-align: center; padding: 0 12px; }
  #result { padding: 12px; }
  #toast { width: max-content; max-width: 92vw; font-size: 13px; }

  /* หน้าแรก + เลือกประเทศ */
  #title { padding-top: 34px; }
  #title h1 { font-size: 34px; letter-spacing: 2px; }
  #title .logo { width: 84px; height: 84px; }
  #pick { padding-top: 34px; }
  #pick .cards { gap: 8px; }
  #pick .card.flag { width: calc(33.33% - 6px); height: auto; aspect-ratio: 3 / 2; }
  #pick .card.flag span { font-size: 12px; padding: 2px; }
  #pick .modes { flex-direction: column-reverse; gap: 8px; }
  #pick .modes button { width: 100%; font-size: 16px; }
  #pickSteps div { padding: 5px 10px; font-size: 12px; }
  #customBox input, #customBox select { display: block; width: 100%; margin: 6px 0 10px; }

  /* จัดทัพ: แต่ละหน่วยเป็นการ์ด 2 บรรทัด (รูป ชื่อ ปุ่มจำนวน / ค่าพลัง) */
  #shopBar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; font-size: 13px; }
  #shopBudget b { font-size: 16px; }
  #shopGo { width: 100%; padding: 10px; }
  #shop thead { display: none; }
  #shop table, #shop tbody { display: block; }
  #shopList tr[data-k] { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid #262a33; }
  #shopList tr.group { display: block; }
  #shopList tr.group td { display: block; }
  #shopList td { border: 0; padding: 0; font-size: 13px; }
  #shopList td:nth-child(1) { flex: none; }
  /* บรรทัดแรก: รูป + ชื่อ + ราคา + ปุ่มจำนวน (ชื่อกินที่ที่เหลือพอดี ค่าพลังจึงตกไปบรรทัดสอง) */
  #shopList td:nth-child(2) { flex: 1 1 calc(100% - 270px); min-width: 0; }
  #shopList td:nth-child(2) .dim { display: none; }
  #shopList td:nth-child(2) br { display: none; }
  #shopList td.price { order: 1; flex: none; width: 50px; text-align: right; }
  #shopList td.qty { order: 1; flex: none; }
  #shopList td[data-l] { order: 2; color: #c9ced6; }
  #shopList td[data-l]::before { content: attr(data-l) " "; color: #7d838e; font-size: 11px; }
  #shopList td[data-l="HP"] { margin-left: 74px; }
  #shop .thumb { width: 64px; height: 44px; }
  #shop .qty button { width: 36px; padding: 7px 0; }
  #shopKept { font-size: 13px; }

  /* รบ: กระดานเลื่อนได้อยู่บน แผงควบคุมอยู่ล่าง */
  #battle.screen { padding: 6px; }
  #battle .wrap { flex-direction: column; gap: 8px; }
  #cvWrap { width: 100%; max-height: 58vh; overflow: auto; -webkit-overflow-scrolling: touch; border-radius: 4px; }
  #panel { width: 100%; }
  #stageName { margin: 0 70px 4px 0; font-size: 11px; }
  #turn { padding: 7px 10px; font-size: 14px; }
  #panel .btns { position: sticky; bottom: 0; margin-top: 8px; padding: 6px 0; background: #15171c; z-index: 3; }
  #panel .btns button { padding: 12px 4px; font-size: 15px; }
  #info { margin-top: 8px; padding: 10px; min-height: 0; display: flow-root; }
  #info .photo { float: left; width: 96px; height: 68px; margin: 0 10px 4px 0; }
  #hint { margin: 8px 0 2px; min-height: 0; font-size: 12px; }
  #left { font-size: 12px; }
  #panel .keys { display: none; }
  #btnPhotos { margin-top: 6px; }
  #detail .box { padding: 12px; }
  #detailImg { max-height: 220px; }
  #detailRows th { width: 105px; }
}
/* มือถือแนวนอน: กระดานซ้าย แผงควบคุมขวา */
@media (max-width: 899px) and (orientation: landscape) and (max-height: 520px) {
  #battle .wrap { flex-direction: row; }
  #cvWrap { width: auto; flex: 1; min-width: 0; max-height: calc(100vh - 12px); }
  #panel { width: 230px; flex: none; max-height: calc(100vh - 12px); overflow: auto; }
  #info .photo { display: none; }
}

#shopGo:disabled { background: #3a3f4a; }

/* แถบเทียบกำลังรบในแผงขวา + หน้าต่างรายละเอียด */
#force { display: block; width: 100%; margin-top: 6px; padding: 6px 8px; background: #20242c; color: #c9ced6; font-size: 12px; text-align: left; border-radius: 6px; }
#force:hover { background: #262a33; }
#force .bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin-bottom: 5px; background: #111; }
#force .row { display: flex; justify-content: space-between; }
#forces { position: fixed; inset: 0; background: rgba(0,0,0,.78); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
#forces .box { position: relative; background: #1b1e25; border: 1px solid #3a3f4a; border-radius: 10px; padding: 18px; width: 640px; max-width: 100%; max-height: 100%; overflow: auto; }
#forces h2 { margin: 0 0 12px; font-size: 18px; }
#forcesClose { position: absolute; top: 12px; right: 12px; padding: 5px 10px; font-size: 13px; }
#forces table { width: 100%; border-collapse: collapse; font-size: 14px; }
#forces th, #forces td { padding: 5px 8px; border-bottom: 1px solid #2a2e37; text-align: center; }
#forces th:first-child, #forces td:first-child { text-align: left; color: #9aa0ab; font-weight: normal; }
#forces .lostT { margin: 16px 0 6px; font-weight: bold; }
#forces .lost { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; min-height: 20px; }
#forces .lost span { display: inline-flex; align-items: center; gap: 5px; }
#forces .lost img { width: 40px; height: 28px; object-fit: cover; border-radius: 4px; border: 2px solid; }
