:root {
  --bg: #0e1117;
  --panel: rgba(18, 22, 32, 0.92);
  --line: #2c3446;
  --text: #e8ecf3;
  --muted: #8d97ab;
  --gold: #f5c542;
  --hp: #e0474c;
  --mp: #3d8bf2;
  --ex: #9b6bf2;
  --accent: #f2a33d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: 'Prompt', system-ui, sans-serif; font-size: 14px; user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#c { position: fixed; inset: 0; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- ล็อกอิน ---------- */
#login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at top, #24324f 0%, #0e1117 70%); z-index: 20; }
#login .box { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
#login h1 { margin: 0 0 16px; text-align: center; font-size: 28px; color: var(--gold); text-shadow: 0 2px 12px rgba(245,197,66,.35); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--muted); }
.tabs button.on { background: #2a3550; color: var(--text); border-color: #45557a; }
#authForm input:not([type=radio]) { width: 100%; padding: 11px 12px; margin-bottom: 10px; border-radius: 8px; border: 1px solid var(--line);
  background: #0b0e15; color: var(--text); font-family: inherit; font-size: 15px; user-select: text; }
.classes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.classes input { display: none; }
.classes span { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; font-size: 24px; text-align: center; }
.classes b { font-size: 14px; }
.classes small { font-size: 11px; color: var(--muted); }
.classes input:checked + span { border-color: var(--accent); background: rgba(242,163,61,.12); }
#authBtn { width: 100%; padding: 12px; border: 0; border-radius: 8px; background: var(--accent); color: #1a1206; font-weight: 600; font-size: 16px; }
#authBtn:disabled { opacity: .6; }
#authErr { color: #ff7b7b; min-height: 20px; margin-top: 8px; text-align: center; }
.help { margin-top: 12px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.6; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
#stats { position: absolute; left: 10px; top: 10px; width: 230px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.who { font-weight: 600; margin-bottom: 4px; }
#sLv { color: var(--gold); }
.bar { position: relative; height: 16px; background: #0b0e15; border-radius: 4px; margin-bottom: 4px; overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; transition: width .2s; }
.bar.hp i { background: var(--hp); } .bar.mp i { background: var(--mp); } .bar.ex i { background: var(--ex); }
.bar.ex { height: 10px; }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 16px; text-shadow: 0 1px 2px #000; }
.bar.ex span { line-height: 10px; font-size: 9px; }
.gold { font-size: 12px; color: var(--muted); } .gold #sGold { color: var(--gold); }
#mapName { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 5px 16px; font-weight: 600; white-space: nowrap; pointer-events: none; }
#mapName .pvp { color: #ff6060; margin-left: 6px; }
#mapName .safe { color: #6fdc8c; margin-left: 6px; }
#mini { position: absolute; right: 10px; top: 10px; border: 1px solid var(--line); border-radius: 8px; background: #000; pointer-events: none; }
#ping { position: absolute; right: 12px; top: 134px; font-size: 11px; color: var(--muted); pointer-events: none; }

#chat { position: absolute; left: 10px; bottom: 10px; width: min(380px, calc(100vw - 20px)); }
#log { max-height: 160px; overflow-y: auto; font-size: 13px; line-height: 1.45; padding: 6px 8px; background: rgba(10,12,18,.55);
  border-radius: 8px 8px 0 0; text-shadow: 0 1px 2px #000; user-select: text; }
#log .sys { color: #ffd76a; } #log .n { color: #7fc4ff; font-weight: 600; } #log .loot { color: #9ff29f; }
#chatIn { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 0 0 8px 8px; background: rgba(10,12,18,.85);
  color: var(--text); font-family: inherit; user-select: text; }

#bottomRight { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#actions, #skillbar { display: flex; gap: 8px; align-items: center; }
#actions button { position: relative; width: 50px; height: 50px; border-radius: 50%; border: 2px solid var(--line); background: var(--panel);
  font-size: 22px; color: var(--text); }
#actions button:active, .sk:active { transform: scale(.94); }
#btnAtk { width: 64px !important; height: 64px !important; border-color: var(--accent) !important; font-size: 26px !important; }
.dot { position: absolute; top: 2px; right: 2px; width: 12px; height: 12px; border-radius: 50%; background: #ff4d4d; border: 2px solid var(--panel); }
.sk { position: relative; width: 54px; height: 54px; border-radius: 12px; border: 2px solid #45557a; background: var(--panel); font-size: 24px;
  color: var(--text); overflow: hidden; padding: 0; }
.sk.locked { opacity: .35; }
.sk.pending { border-color: var(--accent); }
.sk kbd { position: absolute; left: 3px; top: 1px; font-size: 10px; font-family: inherit; color: #cfd6e4; }
.sk small { position: absolute; right: 3px; bottom: 1px; font-size: 10px; color: #ffd76a; }
.sk .cdv { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.65); height: 0; }
.sk .cdt { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 600; text-shadow: 0 1px 3px #000; }

#buffs { position: absolute; left: 10px; top: 146px; display: flex; gap: 4px; flex-wrap: wrap; max-width: 240px; pointer-events: none; }
#buffs div { pointer-events: auto; cursor: pointer; } /* แตะไอคอนบัฟ/ดีบัฟ = ดูคำอธิบาย (ช่องว่างรอบๆ ยังทะลุไปเกม) */
#buffTip { position: fixed; z-index: 9200; max-width: min(300px, 86vw); white-space: pre-line; background: rgba(16,20,32,.96); border: 2px solid #4fbf6a;
  border-radius: 10px; padding: 7px 11px; font-size: 13px; color: #eef2fa; box-shadow: 0 6px 20px rgba(0,0,0,.5); cursor: pointer; }
#buffs div { position: relative; width: 30px; height: 30px; border-radius: 7px; background: var(--panel); border: 1px solid #3d7a4a;
  display: flex; align-items: center; justify-content: center; font-size: 16px; }
#buffs div.bad { border-color: #a33; }
#buffs small { position: absolute; bottom: -2px; right: 1px; font-size: 9px; text-shadow: 0 1px 2px #000; }

.panel.left { right: auto; left: 10px; top: 186px; width: min(420px, calc(100vw - 20px)); max-height: calc(100vh - 260px); }
.free { font-size: 13px; color: var(--muted); margin-bottom: 8px; } .free b { color: var(--gold); }
button.small { margin-top: 8px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); font-size: 12px; }
.charWrap { display: flex; gap: 12px; flex-wrap: wrap; }
.dollRow { display: flex; gap: 8px; align-items: flex-start; justify-content: center; width: 100%; }
.paper.one { grid-template-columns: 58px; }
#charPreview { width: 150px; height: 190px; border-radius: 12px; border: 1px solid var(--line);
  background: radial-gradient(ellipse at 50% 80%, #3a4a6e 0%, #141a28 70%); }
.paper { display: grid; grid-template-columns: 58px 58px; gap: 6px; align-content: start; }
.paper .ps { display: flex; flex-direction: column; align-items: center; font-size: 10px; color: var(--muted); gap: 2px; }
.paper .slot { width: 54px; min-width: 54px; }
.slot b { position: absolute; left: 3px; top: 1px; font-size: 10px; color: #ffd76a; text-shadow: 0 1px 2px #000; }
.statBox { flex: 1; min-width: 190px; }
.statRow { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 13px; }
.statRow .k { width: 34px; font-weight: 600; color: #ffd76a; }
.statRow .v { width: 58px; } .statRow .v i { color: #7fe08a; font-style: normal; font-size: 11px; }
.statRow .d { flex: 1; font-size: 10px; color: var(--muted); }
.statRow button { width: 24px; height: 24px; border: 0; border-radius: 6px; background: var(--accent); color: #1a1206; font-weight: 700; padding: 0; }
.statRow button:disabled { background: #2a3040; color: #555; }
.derived { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; margin-top: 8px; padding: 8px; background: #0b0e15; border-radius: 8px; font-size: 12px; }
.derived span { color: var(--muted); } .derived b { float: right; color: var(--text); font-weight: 600; }
.skillRow { display: flex; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--line); align-items: center; }
.skillRow .ic { font-size: 26px; width: 36px; text-align: center; }
.skillRow .tx { flex: 1; font-size: 12px; line-height: 1.45; }
.skillRow .tx b { font-size: 14px; } .skillRow .tx .lv { color: #ffd76a; margin-left: 4px; }
.skillRow .tx .nx { color: var(--muted); }
.skillRow button { width: 30px; height: 30px; border: 0; border-radius: 8px; background: var(--accent); font-weight: 700; font-size: 16px; }
.skillRow button:disabled { background: #2a3040; color: #555; }
.tag { display: inline-block; font-size: 10px; padding: 0 5px; border-radius: 4px; background: #2a3550; color: #9fb3dd; margin-left: 4px; }
.rf { color: #ffd76a; }
.okMsg { color: #7fe08a; font-weight: 600; } .failMsg { color: #ff7b7b; font-weight: 600; }

.panel { position: absolute; right: 10px; top: 160px; width: min(330px, calc(100vw - 20px)); max-height: calc(100vh - 250px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
@media (min-width: 720px) { #shop { right: 350px; } }
.ph { font-weight: 600; font-size: 16px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.x { background: none; border: 0; color: var(--muted); font-size: 18px; }
.equip { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.slot { position: relative; aspect-ratio: 1; min-width: 42px; background: #0b0e15; border: 1px solid var(--line); border-radius: 7px;
  display: flex; align-items: center; justify-content: center; font-size: 22px; cursor: pointer; }
.slot.sel { border-color: var(--accent); }
.slot small { position: absolute; right: 3px; bottom: 1px; font-size: 10px; color: #fff; text-shadow: 0 1px 2px #000; }
.slot.eq { width: 46px; }
.info { margin-top: 10px; padding: 8px; background: #0b0e15; border-radius: 8px; font-size: 13px; min-height: 60px; line-height: 1.5; }
.info .btns { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.info button, .shopItem button { padding: 5px 10px; border: 0; border-radius: 6px; background: #2a3550; color: var(--text); }
.info button.primary, .shopItem button { background: var(--accent); color: #1a1206; font-weight: 600; }
.bad { color: #ff7b7b; }
.shopNote { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.shopItem { display: flex; align-items: center; gap: 8px; padding: 6px; border-bottom: 1px solid var(--line); }
.shopItem .ic { font-size: 22px; width: 30px; text-align: center; }
.shopItem .nm { flex: 1; font-size: 13px; line-height: 1.3; }
.shopItem .nm small { color: var(--muted); display: block; }
.shopItem .pr { color: var(--gold); font-size: 12px; white-space: nowrap; }

#dead { position: absolute; inset: 0; background: rgba(40,0,0,.55); display: flex; align-items: center; justify-content: center; }
#dead .box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px 32px; text-align: center; }
#dead h2 { margin: 0 0 8px; }
#dead button { margin-top: 10px; padding: 10px 24px; border: 0; border-radius: 8px; background: var(--accent); font-weight: 600; font-size: 15px; }
#toast { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); pointer-events: none; text-align: center; }
#toast div { background: rgba(0,0,0,.7); padding: 6px 14px; border-radius: 8px; margin-top: 4px; color: #ffd76a; animation: fade 3s forwards; }
#btnBot.on { border-color: #5ad8ff !important; box-shadow: 0 0 12px rgba(90,216,255,.6); }
#botBadge { background: var(--panel); border: 1px solid #5ad8ff; color: #bfefff; border-radius: 16px; padding: 4px 12px; font-size: 12px; cursor: pointer; max-width: 260px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.botToggle { width: 100%; padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: #1a1206; font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.botToggle.on { background: #e0474c; color: #fff; }
.botSec { margin: 12px 0 4px; font-weight: 600; color: #ffd76a; border-bottom: 1px solid var(--line); padding-bottom: 3px; }
.botRow { display: flex; flex-direction: column; gap: 2px; margin: 6px 0; font-size: 13px; }
.botRow label b { color: #bfefff; font-weight: 600; }
.botRow input[type=range] { width: 100%; accent-color: var(--accent); }
.botRow:has(button) { flex-direction: row; gap: 6px; }
.botCheck { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 0; cursor: pointer; }
.botCheck.dim { color: var(--muted); }
.botSkills, .botMobs { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.botHint { font-size: 12px; color: var(--muted); margin-top: 6px; }
button.small.sel { border-color: var(--accent); color: var(--text); background: rgba(242,163,61,.15); }
#reconnect { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: rgba(5,7,11,.55); }
#reconnect div { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 22px; font-weight: 600; }
#reconnect i { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- ระบบใหม่: แท็บ / กระเป๋า / ตลาด / ปาร์ตี้ / เทรด / แถบด่วน ---------- */
.tabs2 { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.tabs2 .tab { padding: 4px 9px; border-radius: 14px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 12px; }
.tabs2 .tab.on { background: var(--accent); border-color: var(--accent); color: #1a1206; font-weight: 600; }
.invActions { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.invActions button { padding: 5px 9px; border-radius: 7px; border: 1px solid var(--line); background: #2a3550; color: var(--text); font-size: 12px; }
.invActions button.primary { background: var(--accent); color: #1a1206; border: 0; font-weight: 600; }
.invActions button.on { border-color: var(--accent); }
.invActions button:disabled { opacity: .45; }
.hint { font-size: 11px; color: var(--muted); width: 100%; }
.slot.pick { border-color: #ff6a6a; box-shadow: inset 0 0 0 2px rgba(255,90,90,.6); }
.slot.offer { border-color: #5ad8ff; box-shadow: inset 0 0 0 2px rgba(90,216,255,.6); }
.slot .optdot { position: absolute; left: 3px; bottom: 0; font-size: 8px; color: #7fe0ff; font-style: normal; letter-spacing: -1px; }
.slot.mini { width: 36px; min-width: 36px; font-size: 18px; }
.empty { grid-column: 1 / -1; color: var(--muted); font-size: 12px; padding: 10px; text-align: center; }
.muted { color: var(--muted); font-size: 12px; }
.opt { color: #7fe0ff; font-size: 12px; }
.cardfx { color: #ffb3e6; font-size: 12px; }
.cardTargets, .sellForm { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.cardTargets button { padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: #2a3550; color: var(--text); font-size: 12px; }
.sellForm input, .mbar input, .mbar select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: #0b0e15; color: var(--text); font-family: inherit; width: 120px; user-select: text; }
.sellForm button, .jobCard button { padding: 6px 12px; border: 0; border-radius: 6px; background: var(--accent); color: #1a1206; font-weight: 600; }
.sellForm button:disabled, .jobCard button:disabled, .shopItem button:disabled { opacity: .45; }
.jobLine { font-weight: 600; color: #ffd76a; margin-bottom: 4px; }
.jobNow { font-size: 18px; font-weight: 700; color: #ffd76a; margin: 6px 0; }
.jobCard { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 8px 0; background: rgba(40,50,80,.35); display: flex; flex-direction: column; gap: 5px; }
.jobCard b { font-size: 16px; }
.jobSk { font-size: 12px; color: #bfe3ff; }
.panel.wide { width: min(560px, calc(100vw - 20px)); }
.mbar { display: flex; gap: 6px; margin-bottom: 6px; }
.mbar input { flex: 1; }
.mpage { text-align: center; font-size: 12px; color: var(--muted); margin: 6px 0; }
.mmine { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 6px; }
.tradeWrap { display: flex; gap: 10px; }
.tside { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.tside .grid { grid-template-columns: repeat(4, 1fr); }
.tside input { padding: 5px; border-radius: 6px; border: 1px solid var(--line); background: #0b0e15; color: var(--text); width: 100%; user-select: text; }
.tgold { color: var(--gold); font-weight: 600; }
#partyFrame { position: absolute; left: 10px; top: 184px; width: 170px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
#partyFrame .pm { background: var(--panel); border: 1px solid #3d7a4a; border-radius: 8px; padding: 4px 6px; font-size: 11px; }
#partyFrame .pm.dead { opacity: .55; border-color: #a33; }
.pmTop { font-weight: 600; color: #7dff9a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pmMap { color: var(--muted); font-size: 10px; }
.pbar { height: 5px; background: #0b0e15; border-radius: 3px; margin-top: 2px; overflow: hidden; }
.pbar i { display: block; height: 100%; background: var(--hp); }
.pbar.mp i { background: var(--mp); }
#popups { position: absolute; top: 90px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 12; }
.popup { background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 12px 16px; min-width: 260px; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.popup .ptext { font-weight: 600; margin-bottom: 8px; }
.popup .btns { display: flex; gap: 6px; }
.popup button { flex: 1; padding: 7px; border: 0; border-radius: 7px; background: #2a3550; color: var(--text); }
.popup button.primary { background: var(--accent); color: #1a1206; font-weight: 600; }
#pmenu { position: fixed; z-index: 15; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
#pmenu b { color: #8fd0ff; margin-bottom: 2px; }
#pmenu button { padding: 6px 8px; border: 0; border-radius: 6px; background: #2a3550; color: var(--text); text-align: left; }
#pmenu button:hover { background: #34426a; }
#quickbar { display: flex; gap: 6px; }
.qk { position: relative; width: 44px; height: 44px; border-radius: 10px; border: 2px solid #4a6a8a; background: var(--panel); font-size: 20px; color: var(--text); padding: 0; }
.qk.empty { opacity: .45; }
.qk kbd { position: absolute; left: 3px; top: 0; font-size: 10px; font-family: inherit; color: #cfd6e4; }
.qk small { position: absolute; right: 3px; bottom: 0; font-size: 10px; color: #ffd76a; text-shadow: 0 1px 2px #000; }
#btnCam { position: absolute; right: 12px; top: 134px; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-size: 15px; padding: 0; }
#ping { top: 168px !important; }
.tag.job { background: #4a3a10; color: #ffd76a; }
#trade { left: 50% !important; right: auto !important; transform: translateX(-50%); top: 120px; width: min(460px, calc(100vw - 20px)); z-index: 11; border-color: #5ad8ff; }
#toast { top: 92px !important; }
#log .party { color: #9dffb0; } #log .tagp { color: #5dff8a; font-weight: 600; }
#skillbar { flex-wrap: wrap; justify-content: flex-end; max-width: 480px; }

@media (max-width: 640px) {
  #stats { width: 170px; padding: 6px 8px; }
  #btnCam { top: 96px; }
  .qk { width: 38px; height: 38px; font-size: 17px; }
  #partyFrame { top: 150px; width: 140px; }
  .tradeWrap { flex-direction: column; }
  #mini { width: 110px; height: 82px; }
  #ping { top: 96px; }
  #mapName { top: auto; bottom: 150px; font-size: 12px; }
  #log { max-height: 90px; font-size: 12px; }
  #chat { bottom: 150px; }
  #actions button { width: 42px; height: 42px; font-size: 18px; }
  #btnAtk { width: 54px !important; height: 54px !important; }
  .sk { width: 46px; height: 46px; font-size: 20px; }
  #buffs { top: 118px; }
  .panel, .panel.left { top: 110px; left: 10px; right: 10px; width: auto; max-height: calc(100vh - 270px); }
}

/* =================== มือถือ (จอสัมผัส) =================== */
.touchOnly, #joyZone, #joyBase, #touchMenu:empty, #atkWrap:empty { display: none; }
#btnInstall { width: 100%; margin-top: 10px; padding: 11px; border-radius: 8px; border: 1px solid var(--accent); background: rgba(242,163,61,.12); color: var(--accent); font-weight: 600; font-size: 15px; }
#installGuide { position: fixed; inset: 0; z-index: 40; background: rgba(5,7,11,.8); display: flex; align-items: center; justify-content: center; padding: 16px; }
#installGuide .box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 22px; max-width: 420px; max-height: 100%; overflow-y: auto; }
#installGuide h2 { margin: 0 0 8px; color: var(--gold); }
#installGuide ol { padding-left: 20px; line-height: 1.8; margin: 6px 0; }
#installGuide .ic { font-size: 18px; }
#installGuide .warn { color: #ffb86a; font-size: 13px; }
#installGuide button { width: 100%; padding: 10px; border: 0; border-radius: 8px; background: var(--accent); font-weight: 600; margin-top: 6px; }
#rotate { display: none; position: fixed; inset: 0; z-index: 90; background: #0e1117; color: var(--text); align-items: center; justify-content: center; text-align: center; font-size: 20px; line-height: 1.6; }
#rotate div { font-size: 22px; } #rotate small { color: var(--muted); font-size: 14px; }
@media (orientation: portrait) { body.touch #rotate { display: flex; } }

body.touch .pcOnly { display: none; }
body.touch .touchOnly { display: block; }
body.touch #login { align-items: flex-start; overflow-y: auto; padding: max(8px, env(safe-area-inset-top)) 16px; }
body.touch #login .box { padding: 14px 18px; }
body.touch #login h1 { font-size: 22px; margin-bottom: 8px; }
@media (max-height: 480px) {
  body.touch #login .box { max-width: 640px; }
  body.touch .classes span { flex-direction: row; justify-content: center; gap: 6px; padding: 6px 4px; font-size: 18px; }
  body.touch .classes small { display: none; }
}

/* HUD ย่อ + เผื่อขอบจอ (รอยบาก) */
body.touch #stats { width: 158px; padding: 5px 7px; left: max(8px, env(safe-area-inset-left)); top: 6px; font-size: 12px; }
body.touch .bar { height: 13px; } body.touch .bar span { line-height: 13px; font-size: 10px; }
body.touch #buffs { top: 104px; left: max(8px, env(safe-area-inset-left)); }
body.touch #partyFrame { top: 136px; left: max(8px, env(safe-area-inset-left)); width: 140px; }
body.touch #mapName { top: 6px; font-size: 12px; padding: 3px 12px; bottom: auto; }
body.touch #mini { width: 104px; height: 78px; top: 6px; right: max(8px, env(safe-area-inset-right)); }
body.touch #btnCam { top: 88px; right: max(8px, env(safe-area-inset-right)); width: 34px; height: 34px; }
body.touch #ping { display: none; }
body.touch #toast { top: 40px !important; font-size: 11px; max-width: 78vw; }
body.touch #toast div { padding: 3px 9px; margin-top: 2px; border-radius: 6px; line-height: 1.3; }
body.touch #touchMenu { position: absolute; top: 88px; right: calc(max(8px, env(safe-area-inset-right)) + 42px); display: flex; gap: 6px; }
body.touch #touchMenu button { position: relative; width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--line); background: var(--panel); font-size: 17px; color: var(--text); padding: 0; }
body.touch.chatOpen #btnChat { border-color: var(--accent); }

/* แชท: ซ่อนไว้ กด 💬 เพื่อเปิด */
body.touch #chat { display: none; }
body.touch.chatOpen #chat { display: block; top: 40px; bottom: auto; left: 50%; transform: translateX(-50%); width: min(420px, 60vw); z-index: 14; }
body.touch.chatOpen #log { max-height: 110px; }

/* จอยสติ๊ก */
body.touch #joyZone { display: block; position: absolute; left: 0; bottom: 0; width: 42vw; height: 62vh; touch-action: none; }
body.touch #joyBase { display: block; position: fixed; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; left: 90px; top: calc(100vh - 100px);
  background: radial-gradient(circle, rgba(255,255,255,.06), rgba(255,255,255,.14)); border: 2px solid rgba(255,255,255,.25); pointer-events: none; opacity: .55; }
body.touch #joyBase.on { opacity: 1; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; border-radius: 50%; transform: translate(-50%,-50%);
  background: radial-gradient(circle at 40% 35%, #ffffff, #b8c4dc); box-shadow: 0 2px 10px rgba(0,0,0,.5); }

/* ปุ่มโจมตีใหญ่ + สกิลอยู่ใกล้นิ้วโป้งขวา */
body.touch #atkWrap { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); }
body.touch #btnAtk { width: 84px !important; height: 84px !important; font-size: 34px !important; border-radius: 50%; border: 3px solid var(--accent) !important; background: var(--panel); color: var(--text); }
body.touch #btnAtk:active { transform: scale(.93); }
body.touch #bottomRight { right: calc(max(12px, env(safe-area-inset-right)) + 96px); bottom: max(8px, env(safe-area-inset-bottom)); gap: 6px; }
body.touch #skillbar { max-width: 232px; gap: 6px; }
body.touch .sk { width: 52px; height: 52px; font-size: 24px; border-radius: 14px; }
body.touch .sk kbd, body.touch .qk kbd { display: none; }
body.touch #quickbar { gap: 5px; }
body.touch .qk { width: 38px; height: 38px; font-size: 18px; }
body.touch #actions { gap: 6px; }
body.touch #actions button { width: 40px; height: 40px; font-size: 18px; }
body.touch #botBadge { max-width: 200px; font-size: 11px; }

/* หน้าต่างเต็มจอ ปุ่มใหญ่ขึ้น */
body.touch .panel, body.touch .panel.left, body.touch .panel.wide, body.touch #trade {
  top: max(6px, env(safe-area-inset-top)) !important; left: max(6px, env(safe-area-inset-left)) !important; right: max(6px, env(safe-area-inset-right)) !important;
  bottom: auto; width: auto !important; max-height: calc(100vh - 12px); transform: none !important; z-index: 20; }
body.touch #inv { left: 50% !important; }            /* กระเป๋าครึ่งขวา */
body.touch #shop, body.touch #market { right: 50% !important; } /* ร้าน/ตลาดครึ่งซ้าย (ขายของคู่กับกระเป๋าได้) */
body.touch .panel .x { font-size: 24px; padding: 0 6px; }
body.touch .grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
body.touch .shopItem button, body.touch .info button, body.touch .invActions button { padding: 8px 12px; }
body.touch .statRow button { width: 32px; height: 32px; }
body.touch .skillRow button { width: 38px; height: 38px; }
body.touch #pmenu button { padding: 10px 12px; }
body.touch .popup button { padding: 10px; }

/* ===== 6 อาชีพ / สายผลิต / กาชาคอสตูม ===== */
.classes.six small { font-size: 10px; text-align: center; line-height: 1.25; }
.classes.six span { padding: 8px 3px; }
.jobCard.t3 { border-color: #ffb3f0; background: linear-gradient(135deg, rgba(120,60,140,.35), rgba(40,50,80,.35)); }
.jobSk { font-size: 12px; color: #c9d4ea; }
.craftList { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.craftRow { display: flex; gap: 8px; align-items: center; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: rgba(20,26,40,.6); }
.craftRow.locked { opacity: .55; }
.craftRow .ic { font-size: 24px; width: 32px; text-align: center; }
.craftRow .nm { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.craftRow .nm small { font-size: 11px; color: var(--muted); }
.craftRow .mats { display: flex; flex-wrap: wrap; gap: 3px 8px; font-size: 11px; }
.craftRow .mats .ok { color: #7dff9a; } .craftRow .mats .no { color: #ff8a8a; }
.craftRow .act { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.craftRow .act select { max-width: 120px; font-size: 12px; background: #0b0e15; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 2px; }
.craftRow button, #gachaBody .btns button { padding: 5px 10px; border: 0; border-radius: 6px; background: var(--accent); color: #1a1206; font-weight: 600; cursor: pointer; }
.craftRow button:not(.primary) { background: #3a4660; color: var(--text); }
.craftRow button:disabled, #gachaBody button:disabled { opacity: .45; cursor: default; }
.grates { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; font-weight: 600; margin: 6px 0; }
.gres { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.gcard { display: flex; gap: 6px; border: 2px solid; border-radius: 9px; padding: 6px; background: rgba(12,14,22,.8); margin: 4px 0; }
.gcard .gic { font-size: 26px; }
.gcard .gtx { display: flex; flex-direction: column; font-size: 12px; min-width: 0; }
.gcard .gtx small { font-size: 10px; color: var(--muted); }
/* คอสตูมกาชา เกรด v2: g1 ขาว · g2 เขียว · g3 ฟ้า · g4 แดง · g5 ม่วง · g6 ทอง · g7 รุ้ง (grade4.js: ขอบวิ่งสี) */
.gcard.g4 { box-shadow: 0 0 10px rgba(255,90,90,.45); } .gcard.g5 { box-shadow: 0 0 12px rgba(179,107,255,.6); }
.gcard.g6 { box-shadow: 0 0 16px rgba(255,197,61,.7); animation: gpulse 1.2s infinite alternate; } .gcard.g7 { box-shadow: 0 0 18px rgba(255,122,217,.8); animation: gpulse 0.9s infinite alternate; }
@keyframes gpulse { from { box-shadow: 0 0 8px rgba(255,197,61,.5); } to { box-shadow: 0 0 20px rgba(255,120,200,.9); } }
.slot.g3 { box-shadow: inset 0 0 8px rgba(90,184,255,.6); } .slot.g4 { box-shadow: inset 0 0 9px rgba(255,90,90,.7); } .slot.g5 { box-shadow: inset 0 0 10px rgba(179,107,255,.8); } .slot.g6 { box-shadow: inset 0 0 12px rgba(255,197,61,.9); } .slot.g7 { box-shadow: inset 0 0 12px rgba(255,122,217,.9); }
#craftp, #gachap { width: min(520px, calc(100vw - 20px)); }
