body { overscroll-behavior: none; touch-action: manipulation; }
.scr { min-height: 100dvh; padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.center-col { align-items: center; justify-content: center; text-align: center; }
.logo { font-size: 34px; text-align: center; margin: 4vh 0 4px; }
.tag { text-align: center; color: var(--muted); margin: 0 0 8px; }
.form { display: flex; flex-direction: column; }
.pin-in { font-size: 26px; text-align: center; letter-spacing: 6px; }
.btn.big { font-size: 22px; padding: 14px; margin-top: 16px; width: 100%; }
.hd { text-align: center; color: var(--gold); text-shadow: 3px 3px 0 #000; }

.classes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cc { background: var(--panel); border: 4px solid #000; border-radius: 8px; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; cursor: pointer; box-shadow: 0 4px 0 #000; position: relative; }
.cc img { height: 74px; image-rendering: pixelated; }
.cc b { font-size: 15px; }
.cc small { font-family: 'Press Start 2P', monospace; font-size: 7px; color: var(--muted); }
.cc.sel { outline: 4px solid var(--gold); transform: translateY(-3px); }
.pick-info { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; min-height: 120px; }
.pick-info img { width: 110px; image-rendering: pixelated; }
.pick-info .tagimg { width: 100%; max-width: 220px; }
.st { display: grid; grid-template-columns: 56px 1fr; align-items: center; gap: 6px; font-size: 13px; margin-top: 2px; }
.st .pips { display: flex; gap: 3px; }
.st .pips i { width: 14px; height: 10px; background: #000; border: 2px solid #000; }
.st .pips i.on { background: var(--gold); }

.hero-big { height: 160px; image-rendering: pixelated; }
.hero-mid { height: 110px; image-rendering: pixelated; margin-top: 20px; }
.w-name { font-size: 26px; font-weight: 800; }
.w-cls { color: var(--gold); margin-top: -8px; }
.w-msg { font-size: 20px; }
.msg-box { width: 100%; }
.m-title { font-size: 26px; font-weight: 800; color: var(--gold); text-shadow: 3px 3px 0 #000; }
.m-sub { font-size: 17px; margin-top: 8px; white-space: pre-line; line-height: 1.5; }
.m-count { font-size: 40px; margin-top: 10px; }

/* RUN */
.top { display: flex; flex-direction: column; gap: 6px; }
.top-row { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.top-row .pixel { font-size: 14px; color: var(--gold); }
.bar { height: 22px; }
.bar-t { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000; }
.track { display: flex; align-items: center; gap: 4px; }
.t-line { flex: 1; height: 30px; position: relative; background: repeating-linear-gradient(90deg, #2a2450 0 12px, #231e44 12px 24px); border: 3px solid #000; border-radius: 4px; }
.t-line::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 16%; background: linear-gradient(90deg, #ff000088, transparent); }
.t-me { position: absolute; bottom: -2px; height: 30px; transform: translateX(-50%); transition: left .3s steps(4); image-rendering: pixelated; }
.t-boss, .t-flag { font-size: 22px; }
.qcard { min-height: 96px; display: flex; flex-direction: column; justify-content: center; }
.q-text { font-size: 19px; font-weight: 600; line-height: 1.45; }
.q-explain { margin-top: 8px; font-size: 14px; color: #d6ffe6; background: #0006; padding: 6px 8px; border-radius: 4px; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ans { border: 4px solid #000; border-radius: 8px; color: #fff; font-family: 'Kanit', sans-serif; font-size: 17px; font-weight: 700; padding: 12px 8px; min-height: 76px; text-align: left; display: flex; align-items: center; gap: 8px; box-shadow: inset -4px -4px 0 rgba(0,0,0,.25), 0 4px 0 #000; cursor: pointer; line-height: 1.25; }
.ans:active { transform: translateY(3px); box-shadow: inset -4px -4px 0 rgba(0,0,0,.25), 0 1px 0 #000; }
.ans .sh { font-size: 22px; flex: none; text-shadow: 2px 2px 0 #0006; }
.ans.c4 { background: #864cbf; grid-column: span 2; min-height: 60px; }
.ans.c0 { background: #e21b3c; } .ans.c1 { background: #1368ce; } .ans.c2 { background: #d89e00; } .ans.c3 { background: #26890c; }
.ans.dim { filter: grayscale(.8) brightness(.5); }
.ans.right { outline: 5px solid #7dffb0; filter: none; animation: pulse .4s 2; }
.ans.wrong { outline: 5px solid #ff4d4d; }
.ans:disabled { cursor: default; }
.boost-area { display: flex; align-items: center; gap: 12px; margin-top: auto; }
.charge { display: flex; gap: 6px; flex-direction: column; align-items: center; font-size: 12px; color: var(--muted); }
.charge .pp { display: flex; gap: 5px; }
.charge i { width: 22px; height: 22px; border: 3px solid #000; background: #2a2450; border-radius: 3px; }
.charge i.on { background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.boost { flex: 1; height: 84px; border: 5px solid #000; border-radius: 12px; font-family: 'Press Start 2P', monospace; font-size: 22px; color: #1b1200; background: linear-gradient(180deg, #fff38a, #ff9f1c); box-shadow: inset -5px -5px 0 rgba(0,0,0,.25), inset 5px 5px 0 rgba(255,255,255,.5), 0 6px 0 #000; position: relative; cursor: pointer; }
.boost:not(:disabled) { animation: pulse .7s infinite; }
.boost:active:not(:disabled) { transform: translateY(4px) scale(.98); }
.boost:disabled { filter: grayscale(1) brightness(.5); animation: none; }
.boost b { position: absolute; top: -12px; right: -10px; background: var(--red); color: #fff; border: 3px solid #000; border-radius: 50%; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.caught { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); background: #000d; border: 4px solid var(--red); border-radius: 10px; padding: 14px 22px; text-align: center; font-size: 26px; font-weight: 800; pointer-events: none; animation: blink 1s infinite; z-index: 10; }
.caught small { display: block; font-size: 16px; font-weight: 400; }
#run.is-caught .qcard { outline: 4px solid var(--red); }
#run.is-caught .caught { top: auto; bottom: 120px; transform: translateX(-50%); }

/* BATTLE (เต็มจอ แนวนอน: ภาพสนามเต็มจอ ปุ่มลอยอยู่บนภาพ) */
#battle { position: fixed; inset: 0; overflow: hidden; background: #000; user-select: none; -webkit-user-select: none; touch-action: none; }
.b-view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.b-hud { position: absolute; top: max(6px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); display: flex; align-items: center; gap: 10px; pointer-events: none; z-index: 3; }
.b-hud img { height: 34px; image-rendering: pixelated; }
.b-hp { width: min(26vw, 200px); }
.b-hp .bar { height: 14px; }
.b-hp span { font-size: 11px; color: #fff; text-shadow: 1px 1px 0 #000; }
#bLives { font-size: 17px; letter-spacing: 1px; text-shadow: 1px 1px 0 #000; }
#bUltInfo { color: var(--gold); font-size: 12px; text-shadow: 1px 1px 0 #000; flex: 1; text-align: center; }
#bTime { font-size: 13px; color: var(--gold); text-shadow: 2px 2px 0 #000; }
.mus-btn { background: #0008; color: #fff; border: 2px solid #fff6; border-radius: 6px; font-size: 14px; min-width: 32px; height: 28px; padding: 0 4px; cursor: pointer; pointer-events: auto; }
.gclock { font-size: 12px; color: #ffe27a; background: #0008; border-radius: 6px; padding: 2px 6px; white-space: nowrap; }
.gclock.low { color: #ff6b6b; }
.mus-btn.off { opacity: .45; text-decoration: line-through; }
.fs-btn { pointer-events: auto; background: #0008; color: #fff; border: 2px solid #fff6; border-radius: 6px; font-size: 16px; width: 34px; height: 30px; padding: 0; cursor: pointer; }
.joy { position: absolute; z-index: 2; left: max(18px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom)); width: min(40vh, 220px, 36vw); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, #2a245066 0 55%, #1c183888 56%); border: 4px solid #000a; box-shadow: inset 0 0 0 4px #4b3f8f88; touch-action: none; }
.knob { width: 42%; height: 42%; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff38a, #ff9f1c); border: 4px solid #000; position: absolute; left: 29%; top: 29%; box-shadow: 0 4px 0 #000; }
.btns { position: absolute; z-index: 2; right: max(18px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 12px; }
.atk { width: min(30vh, 150px, 24vw); aspect-ratio: 1; border-radius: 50%; border: 4px solid #000; background: radial-gradient(circle at 35% 35%, #ff8a8acc, #c1121fcc); color: #fff; font-size: 40px; box-shadow: inset -6px -6px 0 rgba(0,0,0,.3), 0 5px 0 #000; display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; font-family: 'Kanit', sans-serif; cursor: pointer; }
.atk small { font-size: 13px; font-weight: 700; }
.atk.on { transform: translateY(4px) scale(.96); box-shadow: inset -6px -6px 0 rgba(0,0,0,.3), 0 1px 0 #000; }
.ults { display: grid; grid-template-columns: repeat(3, auto); gap: 8px; align-items: end; justify-items: center; margin-bottom: 6px; }
.ults .ult-pips { grid-column: 1 / -1; }
.ult { position: relative; overflow: hidden; width: min(17vh, 84px, 14vw); border-radius: 50%; border: 4px solid #000; color: #1b1200; font-family: 'Kanit', sans-serif; font-size: 26px; line-height: 1; background: radial-gradient(circle at 35% 35%, #fff38a, #ff9f1c); box-shadow: inset -5px -5px 0 rgba(0,0,0,.25), 0 5px 0 #000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; touch-action: none; }
.ult .ic { font-size: min(6vh, 26px); }
.ult small { font-size: 9px; font-weight: 800; max-width: 92%; line-height: 1.1; }
.ult .cdv { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(rgba(0,0,0,.72) calc(var(--cd, 0) * 360deg), transparent 0); pointer-events: none; }
.ult .cdv[data-t]::after { content: attr(data-t); position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-family: "Press Start 2P", monospace; font-size: 14px; text-shadow: 2px 2px 0 #000; }
.team-badge { font-weight: 800; font-size: 13px; padding: 2px 8px; border-radius: 6px; border: 2px solid #000; color: #fff; text-shadow: 1px 1px 0 #000; }
.ult:not(:disabled) { animation: pulse .6s infinite; box-shadow: 0 0 22px #ffd23f, inset -5px -5px 0 rgba(0,0,0,.25), 0 5px 0 #000; }
.ult:disabled { filter: grayscale(1) brightness(.55); opacity: .8; cursor: default; }
.ult.on { background: radial-gradient(circle at 35% 35%, #fff, #ffd23f); animation: none; }
.ult-pips { display: flex; gap: 4px; }
.ult-pips i { width: 26px; height: 9px; border: 2px solid #000; background: #2a2450; border-radius: 3px; position: relative; overflow: hidden; }
.ult-pips i b { position: absolute; left: 0; top: 0; bottom: 0; background: #ffd23f; }
.ult-pips i.full { box-shadow: 0 0 8px #ffd23f; }
#battle.is-down .joy, #battle.is-down .btns { filter: grayscale(1) brightness(.5); }
#battle.is-out .joy, #battle.is-out .btns { filter: grayscale(1) brightness(.35); pointer-events: none; }
#battle .caught { top: auto; bottom: max(10px, env(safe-area-inset-bottom)); z-index: 4; font-size: 16px; padding: 6px 12px; max-width: 46vw; animation: none; opacity: .92; }
#battle .caught small { font-size: 12px; }
.rotate { display: none; position: absolute; inset: 0; z-index: 9; background: #0d0b1ef2; color: #fff; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 24px; }
.rotate b { font-size: 24px; color: var(--gold); }
.rotate small { color: var(--muted); font-size: 14px; }
.rot-ic { font-size: 64px; animation: rot 1.6s ease-in-out infinite; }
@keyframes rot { 0%, 20% { transform: rotate(0); } 50%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
@media (orientation: portrait) { .rotate { display: flex; } }

/* อัปเกรดหลังผ่านด่าน */
.upg-list { display: grid; grid-template-columns: 1fr; gap: 8px; width: 100%; }
.upg { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; text-align: left; background: var(--panel); color: #fff; border: 4px solid #000; border-radius: 8px; padding: 10px 12px; box-shadow: 0 4px 0 #000; font-family: 'Kanit', sans-serif; cursor: pointer; }
.upg .ic { font-size: 28px; text-align: center; }
.upg b { font-size: 17px; display: block; }
.upg small { color: var(--muted); font-size: 13px; }
.upg .lv { font-family: 'Press Start 2P', monospace; font-size: 10px; color: var(--gold); }
.upg:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }
.upg.sel { outline: 4px solid var(--gold); background: linear-gradient(180deg, #ffd23f44, var(--panel)); }
.upg:disabled:not(.sel) { opacity: .45; }
@media (orientation: landscape) and (max-height: 500px) { .upg-list { grid-template-columns: 1fr 1fr; } #upg { gap: 6px; } }

.stats { width: 100%; text-align: left; font-size: 17px; line-height: 1.8; }
.stats b { color: var(--gold); }
