/* หน้าจอของเกมเทิร์นเบส (ใช้ร่วมกับ game.css) */
body.turn { background: #dcefe9; }
#turnMap { position: fixed; inset: 0; background: #e6f1ec; }
/* ชื่อมอนใต้หมุดบนแผนที่ */
/* มินิบอสมีวงแหวนทองรอบตัวและป้าย ◆ บนชื่อ */
body.turn .mon.mini { filter: drop-shadow(0 0 6px #ffd166); }
/* ชื่อมอนแสดงเฉพาะตัวที่อยู่ใกล้ บอส และมินิบอส */
body.turn .mon .nm { display: none; }
body.turn .mon.near .nm, body.turn .mon.boss .nm, body.turn .mon.mini .nm { display: block; }
body.turn .mon .nm { position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%); white-space: nowrap;
  background: var(--navy, #14262e); color: #fff8ea; font: 600 11px var(--display); padding: 1px 8px; border-radius: 99px;
  border: 2px solid var(--rc, #fff); box-shadow: 0 2px 6px rgba(0, 0, 0, .3); pointer-events: none; }
/* แผงมอนใกล้ตัว (มุมขวาบน) */
/* แผงมอนใกล้ตัว: วงกลมเล็กเรียงแนวตั้งทางขวา มีระยะห่างกำกับ */
.nearby { position: fixed; top: calc(var(--st) + 70px); right: 10px; z-index: 1100; display: grid; gap: 10px; justify-items: center; }
.nearby .nb { position: relative; width: 54px; height: 54px; padding: 0; border: 3px solid var(--rc); border-radius: 50%;
  background: var(--navy, #14262e); box-shadow: 0 5px 12px rgba(0, 0, 0, .3); display: grid; place-items: center; overflow: visible; }
.nearby .nb img { width: 48px; height: 48px; border-radius: 50%; }
.nearby .nb small { position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  font: 600 10px var(--display); color: var(--navy); background: #fff8ea; border-radius: 99px; padding: 0 6px; border: 1.5px solid var(--navy); }
.nearby .nb.in { box-shadow: 0 0 0 3px var(--sun), 0 5px 12px rgba(0, 0, 0, .3); }
.nearby .nb:active { transform: scale(.95); }
/* มอนและเสารอบตัวบนแผนที่เล็กลงเล็กน้อย */
body.turn .mon { transform: scale(.8); transform-origin: 50% 100%; }
body.turn .stop { transform: scale(.75); transform-origin: 50% 100%; }
body.turn .zone-label span { font-size: 11px; padding: 2px 8px; opacity: .92; }
@media (max-width: 640px) {
  body.turn .zone-label span { font-size: 10px; padding: 1px 6px; opacity: .8; }
  /* มือถือ: ตัดเอฟเฟกต์ที่ทำให้แผนที่กระตุก (เบลอทับแผนที่ที่กำลังเลื่อน และเงาบนไอคอนที่เคลื่อนไหวทุกตัว) */
  .turn-nav, .counts, .hud-top, #btMini.challenge { backdrop-filter: none; }
  body.turn .mon img, body.turn .mon.far img, body.turn .mon.mini { filter: none; }
}
.me-dot { width: 18px; height: 18px; margin: 11px; border-radius: 50%; background: var(--lagoon); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); }

/* ---------- แถบบน ---------- */
.counts { display: flex; gap: 10px; align-items: center; background: rgba(255, 255, 255, .92); border-radius: 99px; padding: 6px 12px;
  box-shadow: 0 4px 14px rgba(27, 42, 53, .16); font: 500 13px var(--display); white-space: nowrap; }
.counts b { font-variant-numeric: tabular-nums; }
#zoneName { font: 500 12px var(--display); color: var(--ink-2); }

/* ---------- แถบเมนูล่างของแผนที่ (สี่ช่องเท่ากัน) ---------- */
.turn-nav { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--sb) + 14px); z-index: 1100;
  width: min(92vw, 420px); display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 6px;
  background: rgba(255, 255, 255, .94); border-radius: 22px; box-shadow: 0 8px 24px rgba(27, 42, 53, .18); backdrop-filter: blur(6px); }
.turn-nav button { border: 0; background: transparent; border-radius: 16px; padding: 6px 0 5px; display: grid; justify-items: center; gap: 1px;
  font: 500 12px var(--display); color: var(--ink-2); }
.turn-nav button span { font-size: 20px; line-height: 1.1; }
.turn-nav button:active { background: #e6f5f2; }
.turn-nav .nav-center span { display: grid; place-items: center; width: 40px; height: 40px; margin-top: -22px; border-radius: 50%;
  background: var(--lagoon); color: #fff; font-size: 22px; border: 4px solid #fff; box-shadow: 0 4px 12px rgba(11, 127, 120, .35); }
.turn-nav .nav-center { color: var(--lagoon-d); font-weight: 600; }

/* ---------- มินิเกม (ชุดใหม่ของเกมเทิร์นเบส) ---------- */
#btMini.challenge { background: radial-gradient(circle at 50% 35%, rgba(10, 40, 50, .25), rgba(10, 25, 35, .85)); }
/* มินิเกม: หัวเรื่องด้านบน พื้นที่เล่นตรงกลางเต็มที่ คะแนนด้านล่าง เว้นขอบปลอดภัยของมือถือ */
.gm-wrap { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px;
  padding: calc(var(--st) + 14px) 16px calc(var(--sb) + 14px); color: #fff; }
.gm-top { display: grid; gap: 6px; }
.gm-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gm-title { font: 600 22px var(--display); text-shadow: 0 2px 6px rgba(0, 0, 0, .5); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gm-how { font: 500 14px/1.4 var(--display); opacity: .92; }
.gm-bar { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .22); overflow: hidden; }
.gm-bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ffd54f, #ff8a65); border-radius: 4px; transition: width .1s linear; }
.gm-bar i.low { background: linear-gradient(90deg, #ff8a65, #ff3d3d); animation: gmBlink .5s steps(2) infinite; }
@keyframes gmBlink { 50% { opacity: .55; } }
.gm-score.pop { animation: gmScorePop .3s ease-out; }
@keyframes gmScorePop { 0% { transform: scale(1.18); } 100% { transform: scale(1); } }
.gm-stage { flex: 1; min-height: 0; position: relative; }
.gm-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.gm-foot { display: flex; justify-content: center; }
.gm-score { background: rgba(255, 255, 255, .92); color: var(--ink); border-radius: 99px; padding: 6px 16px; font: 600 15px var(--display);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .2); font-variant-numeric: tabular-nums; }
.gm-count { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 4px; font: 600 60px var(--display);
  color: #fff; opacity: 0; pointer-events: none; text-shadow: 0 4px 0 rgba(0, 0, 0, .25); text-align: center; }
.gm-count small { font: 600 22px var(--display); }
.gm-count.show { opacity: 1; animation: gmPop .4s ease-out; }
.gm-count.win { color: #fff8e1; }
.gm-count.lose { color: #ffccbc; }
.gm-reward { font: 600 18px var(--display); color: #ffe082; text-shadow: 0 2px 0 #8a5a00; }
@keyframes gmPop { from { transform: scale(1.4); opacity: 0; } }
.gm-skip { border: 0; border-radius: 99px; padding: 6px 14px; background: rgba(255, 255, 255, .92); color: var(--ink); font: 500 14px var(--display); flex: none; }

/* ---------- หน้าต่อสู้ ---------- */
.battle { position: fixed; inset: 0; z-index: 3000; overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  --arena-a: #7fd4ff; --arena-b: #e8f8ff; }
.bt-arena { position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(180deg, var(--arena-a) 0%, var(--arena-b) 60%, #bfe3c6 60%, #9fd7a8 100%); }
.bt-arena::after { content: ""; position: absolute; left: 50%; top: 64%; width: 140%; height: 34%; transform: translate(-50%, -50%);
  border-radius: 50%; background: radial-gradient(ellipse at center, rgba(255, 255, 255, .6), rgba(255, 255, 255, 0) 70%); }
.battle.is-boss .bt-arena { filter: saturate(1.15) brightness(.95); }
#btStage { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
.battle.shake { animation: btShake .35s linear; }
@keyframes btShake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ตัวเลขดาเมจลอยขึ้นจากเป้าหมาย */
.bt-dmg { position: absolute; z-index: 4; transform: translate(-50%, -50%); font: 700 24px var(--display); color: #fff;
  -webkit-text-stroke: 2px #1b2a35; text-shadow: 0 3px 0 #1b2a35; pointer-events: none; white-space: nowrap; animation: btRise .9s ease-out forwards; }
.bt-dmg.crit { color: #ffe082; font-size: 30px; -webkit-text-stroke: 2px #6d4c00; text-shadow: 0 0 14px rgba(255, 213, 79, .9), 0 3px 0 #6d4c00; animation: btCrit 1s ease-out forwards; }
@keyframes btCrit { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.4); } 12% { opacity: 1; transform: translate(-50%, -60%) scale(1.35); }
  25% { transform: translate(-50%, -66%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -150%) scale(1); } }
.bt-note { position: absolute; z-index: 4; transform: translate(-50%, -50%); font: 600 16px var(--display); -webkit-text-stroke: 1.5px #1b2a35;
  pointer-events: none; white-space: nowrap; animation: btNote 1.1s ease-out forwards; }
@keyframes btNote { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -90%); } }
.battle.shake-hard { animation: btShakeHard .45s linear; }
@keyframes btShakeHard { 0%, 100% { transform: translate(0, 0); } 15% { transform: translate(-12px, 4px); } 35% { transform: translate(10px, -5px); }
  55% { transform: translate(-8px, 3px); } 75% { transform: translate(5px, -2px); } }
.bt-dmg.heal { color: #b9f6ca; }
@keyframes btRise { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.7); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -140%) scale(1); } }

/* การ์ดข้อมูล */
.bt-card { position: absolute; z-index: 3; background: #fff; border: 3px solid #1b2a35; border-radius: 14px; padding: 8px 12px 10px;
  box-shadow: 0 6px 16px rgba(27, 42, 53, .22); width: min(44vw, 300px); font-family: var(--body); color: var(--ink); }
.bt-foe { top: 14px; right: 14px; }
.bt-me { left: 12px; bottom: calc(150px + var(--sb)); }
.bt-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.bt-row b { font: 600 17px var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt-row > span { font: 600 13px var(--display); white-space: nowrap; }
.bt-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; align-items: center; }
.diff { border-radius: 99px; padding: 1px 8px; color: var(--ink); background: #e0f2f1; font: 600 12px var(--display); }
.bt-hp { height: 10px; border-radius: 6px; background: #e4ece9; overflow: hidden; margin-top: 6px; border: 1px solid rgba(0, 0, 0, .15); }
.bt-hp i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #4ade80, #22c55e); transition: width .7s ease; }
.bt-hp i[data-low="1"] { background: linear-gradient(90deg, #f87171, #ef4444); }
.bt-xp { height: 4px; border-radius: 3px; background: #e4ece9; margin-top: 6px; overflow: hidden; }
.bt-xp i { display: block; height: 100%; background: #60a5fa; transition: width .6s ease; }
.bt-pips { display: flex; gap: 5px; margin-top: 6px; }
.bt-pips i { width: 12px; height: 12px; border-radius: 50%; background: #d6dedb; border: 2px solid #1b2a35; }
.bt-pips i.on { background: #ffc93c; }

/* กล่องข้อความ */
.bt-log { position: absolute; z-index: 3; left: 12px; right: 196px; bottom: calc(12px + var(--sb)); min-height: 96px; background: #fffdf6;
  border: 3px solid #1b2a35; border-radius: 14px; padding: 12px 16px; font: 500 17px/1.45 var(--display); color: var(--ink);
  display: flex; align-items: center; box-shadow: 0 6px 16px rgba(27, 42, 53, .22); }
.bt-log.pop { animation: btPop .3s ease-out; }
@keyframes btPop { from { transform: translateY(6px); opacity: .5; } }

/* เมนูคำสั่ง (ทางขวา) */
.bt-menu { position: absolute; z-index: 3; right: 12px; bottom: calc(12px + var(--sb)); width: 172px; display: grid; gap: 8px;
  max-height: 60vh; overflow-y: auto; }
.bt-cmd { border: 3px solid #1b2a35; border-radius: 12px; padding: 11px 12px; font: 600 16px var(--display); color: #fff; text-align: left;
  background: #5b8def; box-shadow: 0 4px 0 #1b2a35; transition: transform .1s; }
.bt-cmd:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #1b2a35; }
.bt-cmd:disabled { opacity: .45; }
.bt-cmd.red { background: #e85d5d; }
.bt-cmd.yellow { background: #f2c14e; color: #1b2a35; }
.bt-cmd.green { background: #4caf7a; }
.bt-cmd.blue { background: #5b8def; }

/* มือถือแนวตั้ง: การ์ดเล็กลง ข้อความและเมนูเรียงด้านล่างเต็มความกว้าง */
@media (max-width: 640px) {
  .bt-card { width: min(56vw, 230px); padding: 6px 10px 8px; }
  .bt-row b { font-size: 15px; }
  .bt-foe { top: 10px; right: 10px; }
  .bt-me { left: 10px; bottom: calc(232px + var(--sb)); }
  .bt-log { left: 10px; right: 10px; bottom: calc(10px + var(--sb)); min-height: 62px; font-size: 15px; padding: 8px 12px; }
  .bt-menu { left: 10px; right: 10px; width: auto; bottom: calc(86px + var(--sb)); grid-template-columns: 1fr 1fr; gap: 6px; max-height: 148px; }
  .bt-cmd { padding: 9px 10px; font-size: 15px; }
}

/* ---------- เลือกมอนเริ่มต้น ---------- */
.starter-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 12px; }
.starter-card { border: 3px solid var(--rc); border-radius: 18px; background: #fff; padding: 12px 8px; display: grid; justify-items: center;
  gap: 4px; box-shadow: 0 6px 16px rgba(27, 42, 53, .15); }
.starter-card img { width: 110px; height: 110px; }
.starter-card b { font: 600 18px var(--display); }
.starter-card small { color: var(--ink-2); }

/* ---------- ทีม กระเป๋า และความสำเร็จ ---------- */
.tm-list, .bag-list, .ach-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; max-width: 760px; }
.tm-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; background: #fff; border-radius: 16px;
  padding: 10px; box-shadow: 0 2px 10px rgba(27, 42, 53, .08); }
.tm-row.in { outline: 3px solid var(--lagoon); }
.tm-row img { width: 64px; height: 64px; }
.tm-main { display: grid; gap: 2px; min-width: 0; }
.tm-main b { font: 600 17px var(--display); }
.tm-main .lv { color: var(--lagoon-d); }
.tm-main small { color: var(--ink-2); font-size: 12px; }
.tm-main .bar { height: 6px; border-radius: 3px; background: #e4ece9; overflow: hidden; }
.tm-main .bar i { display: block; height: 100%; background: #4ade80; }
.tm-main .bar.xp i { background: #60a5fa; }
.tm-btn { border: 0; border-radius: 12px; padding: 8px 12px; background: var(--lagoon); color: #fff; font: 600 14px var(--display); }
.bag-list li { display: grid; grid-template-columns: 1fr auto; background: #fff; border-radius: 14px; padding: 12px 14px; }
.bag-list small { grid-column: 1 / -1; color: var(--ink-2); }
.bag-list span { font: 600 18px var(--display); }
.ach-list li { background: #fff; border-radius: 14px; padding: 10px 14px; opacity: .55; display: grid; gap: 2px; }
.ach-list li.got { opacity: 1; box-shadow: 0 0 0 2px var(--sun); }
.ach-list small { color: var(--ink-2); }

/* ---------- ผลลัพธ์ ---------- */
.result { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(88vw, 340px); background: var(--sand);
  border-radius: 28px; padding: 22px 22px 20px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .4); z-index: 4500;
  animation: resultIn .4s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes resultIn { from { transform: translate(-50%, -40%) scale(.9); opacity: 0; } }
.result img { width: 150px; height: 150px; margin: -70px auto 0; display: block; }
.result h2 { font: 600 24px var(--display); margin: 6px 0 2px; }
.result p { margin: 0 0 12px; color: var(--ink-2); }
.result ul { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 6px; }
.result li { display: flex; justify-content: space-between; gap: 8px; background: #fff; border-radius: 12px; padding: 8px 12px; font-size: 14px; }

#teamSheet, #bagSheet, #dexSheet { z-index: 2500; }
