/* Nền tảng cho trang chạy độc lập */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }

/* Layout: canvas toàn màn hình vẽ ở độ phân giải thấp rồi phóng to (kiểu pixel), HUD và nút cảm ứng nổi bên trên. Một giao diện cố định: trời xanh ban ngày. */
:root {
  --sky: #59b7f5;
  --ink: #14301c;        /* viền chữ, nền thẻ */
  --paper: #ffffff;
  --gold: #ffc21a;       /* ngôi sao */
  --red: #e3262b;        /* bóng */
  --grass: #4fcf2e;
  --f-display: "Baloo 2", "Segoe UI", system-ui, sans-serif;
}
html, body { height: 100%; }
body { background: var(--sky); color: var(--paper); font-family: var(--f-display); overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hud { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); left: 16px; right: 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: rgb(20 48 28 / .55); border-radius: 10px; padding: 4px 12px; font-weight: 800; font-size: 20px; line-height: 1.3; font-variant-numeric: tabular-nums; text-shadow: 0 2px 0 var(--ink); display: inline-flex; align-items: center; gap: 6px; }
.chip .ic { width: 18px; height: 18px; flex: none; }
.btns { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.restart { pointer-events: auto; border: 0; border-radius: 10px; background: rgb(20 48 28 / .55); color: var(--paper); font: 800 16px var(--f-display); padding: 6px 14px; cursor: pointer; }
.restart:focus-visible, .card button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.board { position: fixed; top: calc(60px + env(safe-area-inset-top, 0px)); left: 16px; width: 236px; max-width: calc(100% - 32px); background: rgb(20 48 28 / .72); border-radius: 12px; padding: 6px 10px 8px; font-variant-numeric: tabular-nums; z-index: 2; }
.board-head { all: unset; cursor: pointer; display: flex; justify-content: space-between; align-items: center; width: 100%; font-weight: 800; font-size: 16px; color: var(--gold); }
.board-head:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
.board[data-closed] #boardBody { display: none; }
.board[data-closed] .board-caret { transform: rotate(-90deg); }
.board-cols, .board-list li { display: grid; grid-template-columns: 22px 1fr 44px 52px; gap: 6px; align-items: center; }
.board-cols { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: rgb(255 255 255 / .6); margin-top: 4px; }
.board-list { list-style: none; margin: 2px 0 0; padding: 0; font-size: 14px; font-weight: 600; }
.board-list li { padding: 2px 0; border-top: 1px solid rgb(255 255 255 / .08); }
.board-list li.me { color: var(--gold); }
.board-list .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .bk { display: inline-flex; gap: 3px; }
.board-list .bk i { width: 9px; height: 9px; border-radius: 2px; background: rgb(255 255 255 / .18); }
.board-list .bk i.on { background: #ff4d55; }
.board-list .empty { display: block; font-weight: 600; color: rgb(255 255 255 / .7); border: 0; }
.board-status { margin: 4px 0 0; font-size: 11px; color: rgb(255 255 255 / .6); }
.boltfab { position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); display: none; border: 3px solid #fff27a; border-radius: 14px; background: rgb(20 48 28 / .6); color: #fff27a; font: 800 18px var(--f-display); padding: 6px 14px; cursor: pointer; }
.boltfab kbd { font-size: 12px; }
.boltfab.on { background: rgb(20 48 28 / .85); }
.boltfab:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
@media (pointer: fine) { .boltfab { display: block; } }
@media (max-width: 640px) { .board { top: auto; bottom: calc(100px + env(safe-area-inset-bottom, 0px)); width: 200px; } }
.submit { display: grid; gap: 6px; margin-top: 8px; text-align: left; }
.submit label { font-weight: 800; font-size: 15px; }
.submit-row { display: flex; gap: 8px; }
.submit input { flex: 1; min-width: 0; font: 600 16px var(--f-display); padding: 6px 10px; border: 3px solid var(--ink); border-radius: 10px; color: var(--ink); background: #fff; }
.submit button { margin: 0 !important; padding: 6px 16px !important; font-size: 17px !important; }
.submit button:disabled { opacity: .5; }
.sent { margin: 0; font-size: 15px !important; }
.hint { position: fixed; left: 50%; top: 22%; transform: translateX(-50%); background: rgb(20 48 28 / .6); padding: 8px 18px; border-radius: 12px; font-weight: 600; font-size: 18px; text-align: center; transition: opacity .6s; max-width: calc(100% - 32px); }
.hint.gone { opacity: 0; }
kbd { font: 800 14px var(--f-display); background: var(--paper); color: var(--ink); border-radius: 5px; padding: 0 7px; box-shadow: 0 2px 0 #9aa; }
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgb(20 48 28 / .35); padding: 16px; }
.card { background: var(--paper); color: var(--ink); border-radius: 18px; border: 4px solid var(--ink); padding: 22px 28px; text-align: center; display: grid; gap: 6px; box-shadow: 0 8px 0 var(--ink); max-width: 100%; }
.card h2 { margin: 0; font-size: 34px; line-height: 1.1; color: var(--red); text-wrap: balance; }
.card p { margin: 0; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card button { margin-top: 10px; border: 0; border-radius: 12px; background: var(--grass); color: var(--ink); font: 800 20px var(--f-display); padding: 8px 22px; cursor: pointer; box-shadow: 0 4px 0 #2a8a18; }
.touch { position: fixed; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); left: 16px; right: 16px; display: none; justify-content: space-between; pointer-events: none; }
.touch .grp { display: flex; gap: 12px; }
.tbtn { pointer-events: auto; width: 68px; height: 68px; border-radius: 50%; border: 3px solid rgb(255 255 255 / .7); background: rgb(20 48 28 / .35); color: var(--paper); font: 800 26px var(--f-display); touch-action: none; }
.tbtn.on { background: rgb(20 48 28 / .6); }
.chip.lives { color: #ffffff; font-size: 14px; }
#lives { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
#lives b { color: #ff6b6b; }
#lives .hpb { display: inline-block; width: 110px; height: 10px; border-radius: 5px; background: rgb(0 0 0 / .45); overflow: hidden; }
#lives .hpb i { display: block; height: 100%; border-radius: 5px; transition: width .2s; }
#lives small { opacity: .8; font-size: 11px; }
@media (max-width: 640px) { #lives .hpb { width: 60px; } #lives small { display: none; } }
.prog { position: fixed; top: calc(60px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); width: min(420px, calc(100% - 32px)); pointer-events: none; }
.track { position: relative; height: 12px; border-radius: 6px; background: rgb(20 48 28 / .55); border: 2px solid rgb(255 255 255 / .7); }
.track .fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 4px; background: var(--grass); }
.track .cp { position: absolute; top: -5px; width: 4px; height: 18px; margin-left: -2px; background: var(--paper); border-radius: 2px; }
.track .end { position: absolute; right: -14px; top: -10px; width: 26px; height: 26px; }
.track .end svg { width: 100%; height: 100%; }
.track .me { position: absolute; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; background: var(--red); border: 2px solid #14141a; left: 0; }
.bossbar { position: fixed; top: calc(92px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); width: min(520px, calc(100% - 32px)); background: rgb(20 10 14 / .7); border-radius: 12px; padding: 6px 14px 8px; text-align: center; pointer-events: none; }
.bhead { font-size: 18px; font-weight: 800; display: flex; justify-content: center; align-items: center; gap: 8px; }
.bhead b { color: #ff4d55; letter-spacing: .08em; }
.pips { display: inline-flex; gap: 4px; margin-left: 6px; }
.pips i { width: 22px; height: 10px; border-radius: 3px; background: rgb(255 255 255 / .2); }
.pips i.on { background: #ff4d55; }
.hpbar { height: 12px; margin: 6px auto 2px; width: 100%; border-radius: 6px; background: rgb(255 255 255 / .18); overflow: hidden; }
.hpbar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #7ff0ff, #c9b6ff 50%, #ff2f5c); transition: width .2s; }
.bnote { font-size: 14px; font-weight: 600; color: #ffe9a8; line-height: 1.3; }
.tip { position: fixed; left: 50%; top: 22%; transform: translateX(-50%); background: rgb(20 48 28 / .78); border: 2px solid var(--gold); padding: 8px 18px; border-radius: 12px; font-weight: 600; font-size: 18px; text-align: center; transition: opacity .6s; max-width: min(640px, calc(100% - 32px)); pointer-events: none; text-wrap: balance; }
.tip.gone { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .tip { transition: none; } }
.tsbanner { position: fixed; left: 50%; top: 38%; transform: translateX(-50%); background: rgb(60 30 90 / .85); border: 3px solid #c9b6ff; color: var(--paper); font-weight: 800; font-size: 22px; padding: 8px 20px; border-radius: 14px; text-align: center; max-width: calc(100% - 32px); pointer-events: none; }
.tsbanner[data-esc="1"] { background: rgb(150 20 50 / .85); border-color: #ff9ab0; }
#time.low { color: #ff6b6b; }
.tbtn.bolt { color: #fff27a; border-color: #fff27a; font-size: 18px; }
.tbtn.power { color: var(--gold); border-color: var(--gold); }
.tbtn:disabled { opacity: .4; }
.chip.energy { gap: 8px; }
.ebar { width: 90px; height: 12px; border-radius: 6px; background: rgb(255 255 255 / .2); overflow: hidden; border: 2px solid rgb(255 255 255 / .5); }
.ebar i { display: block; height: 100%; width: 50%; background: linear-gradient(90deg, #ffc21a, #fff27a); transition: width .15s; }
.chip.energy[data-full="1"] { color: #fff27a; box-shadow: 0 0 0 3px #fff27a; }
.chip.energy[data-full="1"] .ebar i { background: #ffffff; }
.touch .grp.acts { display: grid; grid-template-columns: repeat(3, 58px); gap: 8px; }
.touch .grp.acts .tbtn { width: 58px; height: 58px; font-size: 18px; }
.tbtn.web { color: #c9f3ff; border-color: #c9f3ff; }
.tbtn.volt { color: #fff27a; border-color: #fff27a; font-size: 16px !important; }
@media (pointer: coarse) { .touch { display: flex; } .hint .keys { display: none; } }
@media (pointer: fine) { .hint .tap { display: none; } }
@media (prefers-reduced-motion: reduce) { .hint { transition: none; } }
.charcard { width: min(1180px, 100%); max-height: calc(100dvh - 32px); overflow: auto; }
.charlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; margin-top: 6px; }
.card .charopt canvas.charprev { width: 100%; height: auto; aspect-ratio: 4 / 3; display: block; border-radius: 8px; background: radial-gradient(circle at 50% 70%, #ffffff 0 30%, #dfe9e3 70%); }
.card .charopt.locked canvas.charprev { filter: grayscale(.85) brightness(.85); }
.card .charopt { margin: 0; display: grid; gap: 2px; text-align: center; align-content: start; background: #f2f6f3; color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; padding: 8px 10px; font: 800 18px var(--f-display); box-shadow: none; }
.card .charopt small { font: 600 13px/1.3 var(--f-display); color: #3d5244; }
.card .charopt[aria-pressed="true"] { background: #fff1b8; border-color: #c48a00; }
.card p.charinfo { font-size: 14px; font-weight: 600; text-align: left; line-height: 1.5; margin-top: 4px; }
.charinfo kbd { font-size: 12px; }
.tbtn.sx { color: #9fd8ff; border-color: #9fd8ff; font-size: 16px !important; }
.tbtn.nm { color: #8fe08a; border-color: #8fe08a; font-size: 16px !important; }
.tbtn.lf { color: #ff8a7a; border-color: #ff8a7a; font-size: 16px !important; }
.tbtn.ku { color: #ffd36a; border-color: #ffd36a; font-size: 16px !important; }
.tbtn.pk { color: #ff5a6e; border-color: #ff5a6e; font-size: 16px !important; }
@media (max-width: 420px) { .charlist { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); } .card .charopt small { display: none; } }
.outfit { display: flex; gap: 12px; align-items: center; text-align: left; margin-top: 4px; }
.outfit canvas { flex: none; background: #d6ecff; border: 3px solid var(--ink); border-radius: 12px; }
.outfit-sel { display: grid; gap: 6px; flex: 1; min-width: 0; font-size: 15px; }
.outfit-sel label { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 6px; font-weight: 800; font-size: 14px; }
.outfit-sel select { min-width: 0; font: 600 15px var(--f-display); color: var(--ink); background: #fff; border: 2px solid var(--ink); border-radius: 8px; padding: 3px 6px; }
.outfit-sel select:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; }
/* Đấu trường cá cược */
.betrow { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.card .betside { background: #f2f6f3; border: 3px solid #d83a3a; box-shadow: none; font-size: 16px; }
.card #betB { border-color: #2a7ad8; }
.card .betside[aria-pressed="true"] { background: #fff1b8; }
.card .betchip { background: #e8eef0; box-shadow: none; font-size: 15px; padding: 4px 12px; }
.betrow label { font-weight: 800; font-size: 15px; }
.betrow input { width: 120px; font: 600 16px var(--f-display); padding: 6px 10px; border: 3px solid var(--ink); border-radius: 10px; color: var(--ink); background: #fff; }
.card p.betvs { font-size: 18px; font-weight: 800; }
.betcoin b { color: #c48a00; }
.card p.betwin { color: #2a8a18; min-height: 1.3em; font-size: 16px; }
.card #betGo:disabled { opacity: .5; cursor: default; }
.bethud { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
body.betting .hud, body.betting .board, body.betting .prog, body.betting .bossbar, body.betting .touch, body.betting .hint, body.betting .boltfab, body.betting .tip, body.betting .tsbanner { display: none !important; }
