:root {
  --bg: #f6eedd; --card: #fffaf0; --card2: #fbf3e2; --ink: #3a2a1e; --muted: #8a7560; --line: rgba(58, 36, 22, .12);
  --green: #1f5c4f; --teal: #2f8a6c; --mint: #dcefe5; --gold: #f2c14e; --gold-d: #b98512; --sand: #ecd6ad; --red: #c8402a; --rose: #fbe3dc;
  --r: 18px; --sh: 0 6px 18px rgba(58, 36, 22, .12); --sh2: 0 2px 6px rgba(58, 36, 22, .1);
  --top: 60px; --rail: 88px; --panel: 420px;
  font-family: "Baloo Bhaijaan 2", system-ui, sans-serif; color: var(--ink); -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }
img { display: block; }
.num { font-variant-numeric: tabular-nums; unicode-bidi: isolate; direction: ltr; display: inline-block; }

.boot { position: fixed; inset: 0; display: grid; place-content: center; gap: 18px; justify-items: center; background: var(--bg); z-index: 50; }
.boot img { width: 84px; animation: bob 1.4s ease-in-out infinite; }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 4px solid var(--sand); border-top-color: var(--teal); animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
@keyframes bob { 50% { transform: translateY(-8px); } }

.screen { position: fixed; inset: 0; }

/* ---------- nút ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 6px 16px; border-radius: 14px; font-weight: 700; font-size: 15px;
  background: var(--card); box-shadow: inset 0 -3px 0 rgba(58, 36, 22, .12), var(--sh2); transition: transform .08s; white-space: nowrap; }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary { background: var(--teal); color: #fff; box-shadow: inset 0 -4px 0 #1f5c4f, var(--sh2); }
.btn.gold { background: var(--gold); color: #3a2a1e; box-shadow: inset 0 -4px 0 #c99a2a, var(--sh2); }
.btn.danger { background: var(--rose); color: var(--red); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.sm { min-height: 34px; padding: 4px 12px; font-size: 14px; border-radius: 11px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn img { width: 22px; height: 22px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 18px; background: var(--card2); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 6px; border-radius: 999px; background: var(--card); box-shadow: var(--sh2); font-weight: 800; white-space: nowrap; }
.pill img { width: 26px; height: 26px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--card2); white-space: nowrap; }
.chip.good { background: var(--mint); color: var(--green); }
.chip.bad { background: var(--rose); color: var(--red); }
.chip.gold { background: #fdf0c4; color: #7a5a0a; }
.chip img { width: 18px; height: 18px; }
.seg { display: flex; gap: 4px; padding: 4px; background: var(--card2); border-radius: 14px; }
.seg button { flex: 1; padding: 6px 10px; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--sh2); }
.err { color: var(--red); font-weight: 700; min-height: 22px; }
input.field { width: 100%; padding: 10px 14px; border-radius: 14px; border: 2px solid var(--line); background: #fff; font-size: 16px; }
input.field:focus { outline: none; border-color: var(--teal); }
label.lbl { display: block; font-weight: 700; font-size: 14px; margin: 10px 2px 4px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: rgba(58, 36, 22, .1); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--teal); }
.bar.gold > i { background: var(--gold); }
.bar.red > i { background: var(--red); }

/* ---------- đăng nhập ---------- */
.auth { display: grid; grid-template-columns: 1fr minmax(360px, 460px); background: var(--green); }
.auth-hero { position: relative; overflow: hidden; }
.auth-hero img { width: 100%; height: 100%; object-fit: cover; object-position: center 40%; }
.auth-card { background: var(--bg); padding: 28px 30px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.lang-row { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.lang-row #auth-lang { margin-inline-start: auto; }
.lang-row .about { font-size: 14px; font-weight: 700; text-decoration: none; color: inherit; opacity: .75; }
.lang-row .about:hover { opacity: 1; text-decoration: underline; }
.brand { display: flex; gap: 12px; align-items: center; margin-top: 10px; }
.brand img { width: 64px; }
.brand h1 { margin: 0; font-size: 34px; line-height: 1.05; color: var(--green); }
.brand .alt { font-weight: 700; color: var(--gold-d); }
.tagline { margin: 2px 0 8px; font-size: 18px; }
#auth-form { display: flex; flex-direction: column; }
#auth-form .btn { margin-top: 16px; }
@media (max-width: 760px) {
  .auth { grid-template-columns: 1fr; grid-template-rows: calc(34 * var(--vh)) 1fr; }
  .auth-card { border-radius: 26px 26px 0 0; margin-top: -26px; position: relative; }
}

/* ---------- chọn mặt bằng ---------- */
.lots { display: flex; flex-direction: column; background: var(--bg); }
.lots-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; }
.lots-top h2 { margin: 0; color: var(--green); font-size: 26px; }
.lots-top p { margin: 0; color: var(--muted); }
.lots-body { flex: 1; display: grid; grid-template-columns: 1fr 400px; gap: 14px; padding: 0 14px 14px; min-height: 0; }
.map-wrap { background: #f0dfbf; border-radius: 24px; overflow: hidden; box-shadow: var(--sh); min-height: 0; }
#map { width: 100%; height: 100%; display: block; touch-action: manipulation; }
#map .pin { cursor: pointer; }
#map .pin circle.ring { transition: r .15s; }
#map .pin.sel circle.ring { stroke: #c8402a; stroke-width: 6; }
#map text { font-family: "Baloo Bhaijaan 2", system-ui; pointer-events: none; }
.lot-card { background: var(--card); border-radius: 24px; box-shadow: var(--sh); padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.lot-card h3 { margin: 0; font-size: 22px; }
.lot-card .dist { font-weight: 700; color: var(--teal); }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kv > div { background: var(--card2); border-radius: 14px; padding: 8px 10px; }
.kv b { display: block; font-size: 18px; }
.kv span { font-size: 12px; color: var(--muted); font-weight: 700; }
.mix { display: flex; flex-wrap: wrap; gap: 6px; }
.mix .m { display: flex; align-items: center; gap: 4px; background: var(--card2); border-radius: 14px; padding: 2px 10px 2px 2px; font-weight: 700; font-size: 13px; }
.mix .m img { width: 36px; height: 36px; border-radius: 10px; background: #fff; }
.empty-pick { margin: auto; text-align: center; color: var(--muted); font-weight: 700; display: grid; gap: 10px; justify-items: center; }
.empty-pick img { width: 120px; opacity: .9; }
@media (max-width: 860px) {
  .lots-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; padding: 0 8px 8px; }
  .lot-card { max-height: calc(56 * var(--vh)); border-radius: 22px; }
  .lots-top h2 { font-size: 21px; }
}

/* ---------- bố cục game: sân khấu 3D không bao giờ bị che ---------- */
.game { display: grid; grid-template-columns: var(--rail) 1fr; grid-template-rows: var(--top) 1fr; grid-template-areas: "top top" "rail stage"; }
.game.panel-open { grid-template-columns: var(--rail) 1fr var(--panel); grid-template-areas: "top top top" "rail stage panel"; }
.top { grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--card); box-shadow: 0 2px 10px rgba(58, 36, 22, .08); z-index: 3; min-width: 0; }
.rail { grid-area: rail; display: flex; flex-direction: column; gap: 6px; padding: 10px 8px; background: var(--card2); border-inline-end: 1px solid var(--line); overflow: auto; z-index: 2; }
.stage { grid-area: stage; position: relative; overflow: hidden; min-width: 0; min-height: 0; }
.panel { grid-area: panel; display: flex; flex-direction: column; background: var(--card); border-inline-start: 1px solid var(--line); min-height: 0; z-index: 2; }
#cv, #ov { position: absolute; inset: 0; width: 100%; height: 100%; }
#ov { pointer-events: none; }

.tab { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 16px; font-size: 13px; font-weight: 700; color: var(--muted); }
.tab img { width: 40px; height: 40px; transition: transform .15s; }
.tab.on { background: var(--card); color: var(--ink); box-shadow: var(--sh2); }
.tab.on img { transform: scale(1.08); }
.tab .badge { position: absolute; top: 4px; inset-inline-end: 8px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--red); color: #fff; font-size: 12px; display: grid; place-items: center; }

.top .name { display: flex; flex-direction: column; min-width: 0; line-height: 1.1; }
.top .name b { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 26vw; }
.top .clock { display: flex; flex-direction: column; line-height: 1.1; padding: 2px 12px; border-radius: 14px; background: var(--card2); }
.top .clock b { font-size: 20px; }
.top .clock span { font-size: 12px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.top .grow { flex: 1; }
.stars { display: inline-flex; align-items: center; gap: 4px; }
.stars .s { position: relative; width: 18px; height: 18px; }
.stars .s::before, .stars .s i::before { content: "★"; position: absolute; inset: 0; font-size: 19px; line-height: 18px; }
.stars .s::before { color: #e3d6bd; }
.stars .s i { position: absolute; inset: 0; overflow: hidden; }
.stars .s i::before { color: #f2b632; }
[dir=rtl] .stars .s i { inset-inline-start: auto; }
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 800; padding: 1px 9px; border-radius: 99px; background: var(--card2); color: var(--muted); width: fit-content; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.open { background: var(--mint); color: var(--green); }
.status.rest { background: #dfe3f4; color: #3c4a8a; }
.status.bad { background: var(--rose); color: var(--red); }

.hud { position: absolute; display: flex; flex-direction: column; gap: 8px; pointer-events: none; z-index: 1; max-width: calc(100% - 24px); }
.hud > * { pointer-events: auto; }
.hud.tl { top: 12px; inset-inline-start: 12px; }
.hud.tc { top: 12px; left: 50%; transform: translateX(-50%); align-items: center; }
.hud.bl { bottom: 12px; inset-inline-start: 12px; }
.hud.br { bottom: 12px; inset-inline-end: 12px; align-items: flex-end; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--sh); padding: 12px; }
.setup { width: 270px; padding: 10px 12px; }
.setup h4 { margin: 0 0 6px; display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.setup .step { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 12px; font-weight: 700; font-size: 14px; width: 100%; text-align: start; }
.setup .step:hover { background: var(--card2); }
.setup .step .ck { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--card2); font-size: 13px; flex: none; }
.setup .step.done .ck { background: var(--teal); color: #fff; }
.setup .step.done { color: var(--muted); text-decoration: line-through; }
.setup .step.wait .ck { background: #fdf0c4; }
.setup.mini { width: auto; padding: 6px 12px; }
.banner { display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; border-radius: 999px; background: var(--card); box-shadow: var(--sh); font-weight: 800; }
.banner img { width: 40px; height: 40px; border-radius: 50%; background: var(--card2); }
.banner.gold { background: #fdf0c4; }
.tip { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 14px; background: rgba(255, 250, 240, .94); box-shadow: var(--sh2); font-size: 13px; font-weight: 700; max-width: 360px; }
.tip.bad { background: #fff1ec; color: #8a2a18; }
.fab { display: flex; gap: 8px; }
.fab .icon-btn { background: var(--card); box-shadow: var(--sh2); }
.rest-card { display: flex; gap: 12px; align-items: center; max-width: 380px; background: #26305a; color: #eef; }
.rest-card img { width: 48px; }
.rest-card .btn { color: var(--ink); }

.editbar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 20px; background: var(--card); box-shadow: var(--sh); z-index: 2; max-width: calc(100% - 20px); }
.editbar .lab { font-weight: 800; padding: 0 8px; display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editbar .lab img { width: 36px; height: 36px; }

.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 4px 16px; }
.panel-head h3 { margin: 0; flex: 1; font-size: 20px; }
.panel-head .grip { display: none; }
.panel-tabs { padding: 4px 12px 8px; }
.panel-tabs:empty { display: none; }
.panel-body { flex: 1; overflow: auto; padding: 4px 12px 24px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.sec { display: flex; flex-direction: column; gap: 8px; }
.sec > h4 { margin: 4px 2px 0; font-size: 15px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { position: relative; background: var(--card2); border-radius: 16px; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; font-weight: 700; font-size: 13px; border: 2px solid transparent; }
.tile:hover { border-color: rgba(47, 138, 108, .35); }
.tile img { width: 76px; height: 76px; object-fit: contain; }
.tile .nm { line-height: 1.15; min-height: 30px; display: flex; align-items: center; }
.tile .pr { display: inline-flex; align-items: center; gap: 3px; font-weight: 800; }
.tile .pr img, .coin { width: 18px; height: 18px; display: inline-block; vertical-align: -3px; }
.tile .meta { font-size: 12px; color: var(--muted); }
.tile.off { opacity: .5; }
.tile .own { position: absolute; top: 6px; inset-inline-end: 6px; }
.row { display: flex; align-items: center; gap: 10px; background: var(--card2); border-radius: 16px; padding: 8px 10px; }
.row .av { width: 56px; height: 56px; border-radius: 14px; background: #fff; flex: none; object-fit: cover; }
.row .mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row .mid b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .mid .sub { font-size: 12px; color: var(--muted); font-weight: 700; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
.row.wrap .acts { flex-basis: 100%; justify-content: flex-start; padding-inline-start: 66px; }
.lvl { display: inline-flex; gap: 2px; }
.lvl i { width: 7px; height: 12px; border-radius: 3px; background: #e3d6bd; }
.lvl i.on { background: var(--teal); }
.lvl i.on.p { background: #6f7fe0; }
.stat { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat > div { background: var(--card2); border-radius: 14px; padding: 8px 10px; display: flex; align-items: center; gap: 8px; }
.stat > div > img { width: 34px; height: 34px; }
.stat > div { font-size: 24px; }
.stat .pr img { width: 18px; height: 18px; }
.stat b { display: block; font-size: 18px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 700; }
.bigrate { display: flex; align-items: center; gap: 14px; }
.bigrate .v { font-size: 46px; font-weight: 800; line-height: 1; color: var(--gold-d); }
.cap { position: relative; height: 16px; border-radius: 99px; background: rgba(58, 36, 22, .08); }
.cap i { position: absolute; top: 0; bottom: 0; border-radius: 99px; }
.ladder { display: flex; flex-direction: column; gap: 4px; }
.ladder > div { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; padding: 4px 8px; border-radius: 10px; background: var(--card2); }
.ladder > div.on { background: var(--mint); color: var(--green); }
.ladder em { font-style: normal; margin-inline-start: auto; }
.spark { width: 100%; height: 46px; display: block; }
.chart { width: 100%; height: 130px; display: block; }
.sw { position: relative; width: 48px; height: 28px; border-radius: 99px; background: #d9ccb2; flex: none; transition: background .15s; }
.sw::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: var(--sh2); transition: inset-inline-start .15s; }
.sw.on { background: var(--teal); }
.sw.on::after { inset-inline-start: 23px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper b { min-width: 64px; text-align: center; font-size: 20px; }
.qty { display: flex; gap: 4px; }
.qty button { padding: 4px 10px; border-radius: 10px; background: var(--card2); font-weight: 800; }
.qty button.on { background: var(--gold); }
.empty { text-align: center; color: var(--muted); font-weight: 700; padding: 18px; }
.note { font-size: 13px; color: var(--muted); background: var(--card2); border-radius: 12px; padding: 8px 10px; }
.note.good { background: var(--mint); color: var(--green); }
.note.bad { background: var(--rose); color: var(--red); }
.evt { display: flex; gap: 10px; padding: 8px 10px; border-radius: 14px; background: var(--card2); font-size: 14px; font-weight: 600; align-items: flex-start; }
.evt time { font-size: 12px; color: var(--muted); white-space: nowrap; margin-top: 2px; }
.evt.good { background: var(--mint); }
.evt.bad { background: var(--rose); }
.medal { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--card); }

.modal { position: fixed; inset: 0; background: rgba(30, 20, 10, .45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-card { background: var(--bg); border-radius: 24px; padding: 20px; width: min(440px, 100%); max-height: 100%; overflow: auto; overscroll-behavior: contain; box-shadow: var(--sh); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.modal-card img.hero { width: 120px; margin: 0 auto; }
.modal-card h3 { margin: 0; font-size: 24px; }
.toasts { position: fixed; top: calc(var(--top) + 8px); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 45; pointer-events: none; width: min(460px, 92vw); }
.toast { padding: 9px 14px; border-radius: 14px; background: var(--card); box-shadow: var(--sh); font-weight: 700; animation: tin .25s ease-out; display: flex; gap: 8px; align-items: center; }
.toast.good { background: #e6f5ec; }
.toast.bad { background: #fde8e1; color: #7a2412; }
@keyframes tin { from { transform: translateY(-10px); opacity: 0; } }
.conn { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); background: #3a2a1e; color: #fff; padding: 6px 14px; border-radius: 99px; font-weight: 700; z-index: 46; }

/* ---------- điện thoại: thanh dưới, bảng trượt nằm dưới sân khấu ---------- */
@media (max-width: 899px) {
  :root { --top: 54px; }
  .game, .game.panel-open { grid-template-columns: 1fr; grid-template-rows: var(--top) 1fr 0 auto; grid-template-areas: "top" "stage" "panel" "rail"; }
  .game.panel-open { grid-template-rows: var(--top) minmax(calc(34 * var(--vh)), 1fr) minmax(0, calc(54 * var(--vh))) auto; }
  .game.panel-open.tall { grid-template-rows: var(--top) calc(26 * var(--vh)) minmax(0, 1fr) auto; }
  .rail { flex-direction: row; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--line); background: var(--card); overflow: visible; }
  .tab { flex: 1; padding: 4px 0; font-size: 11px; border-radius: 12px; }
  .tab img { width: 32px; height: 32px; }
  .panel { border: 0; border-top: 1px solid var(--line); border-radius: 22px 22px 0 0; box-shadow: 0 -6px 18px rgba(58, 36, 22, .12); }
  .panel-head { padding: 4px 10px 2px 14px; position: relative; }
  .panel-head .grip { display: block; position: absolute; top: 5px; left: 50%; transform: translateX(-50%); width: 42px; height: 5px; border-radius: 9px; background: var(--line); }
  .panel-head h3 { font-size: 18px; padding-top: 6px; }
  .top { gap: 6px; padding: 0 8px; }
  .top .name b { font-size: 15px; max-width: 30vw; }
  .top .clock { padding: 2px 8px; }
  .top .clock b { font-size: 16px; }
  .top .clock span.d2 { display: none; }
  .pill { padding: 3px 9px 3px 4px; font-size: 14px; }
  .pill img { width: 22px; height: 22px; }
  .top .hide-m { display: none; }
  .setup { width: 230px; }
  .grid3 { grid-template-columns: repeat(3, 1fr); }
  .tile img { width: 62px; height: 62px; }
  .editbar { bottom: 8px; flex-wrap: wrap; justify-content: center; width: calc(100% - 16px); border-radius: 18px; }
  .editbar .lab { flex-basis: 100%; justify-content: center; }
  .hide-m { display: none !important; }
  .rest-card { max-width: 92vw; padding: 10px; }
  .game.panel-open .hud.bl, .game.panel-open .hud.tc .chip { display: none; }
  .tip { font-size: 12px; padding: 4px 10px; max-width: 70vw; }
  .hud.bl { bottom: 8px; inset-inline-start: 8px; gap: 5px; }
  .hud.br { bottom: 8px; inset-inline-end: 8px; }
  .fab .icon-btn { width: 36px; height: 36px; }
}
@media (max-width: 420px) {
  .grid3 { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- cảnh báo tiền, tổng kết ngày, sổ sách ---------- */
.warnbar { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; border-radius: 16px; background: #c8402a; color: #fff; font-weight: 700; font-size: 14px; box-shadow: var(--sh); max-width: min(620px, calc(100vw - 24px)); }
.warnbar.soft { background: #fff1ec; color: #8a2a18; }
.warnbar .btn { flex: none; }
.sumcard { position: relative; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; padding: 10px 12px; border-radius: 16px; background: var(--card); box-shadow: var(--sh); font-size: 14px; max-width: 300px; }
.sumcard .x { position: absolute; top: 4px; inset-inline-end: 6px; color: var(--muted); font-size: 14px; }
.sumcard b { padding-inline-end: 18px; }
.chartwrap { position: relative; }
.ctip { position: absolute; top: 6px; width: 142px; padding: 8px 10px; border-radius: 12px; background: #3a2a1e; color: #fff; font-size: 12px; line-height: 1.5; pointer-events: none; box-shadow: var(--sh); z-index: 2; }
.ctip b { display: block; font-size: 13px; }
.ctip .num[style] { color: inherit !important; font-weight: 800; }
.daylist { display: flex; flex-direction: column; gap: 4px; }
.dayrow { display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: center; padding: 7px 10px; border-radius: 12px; background: var(--card2); font-size: 13px; font-weight: 700; text-align: start; width: 100%; }
.dayrow.on { background: #fdf0c4; box-shadow: inset 0 0 0 2px var(--gold); }
.dayrow.static { grid-template-columns: 1fr auto auto; }
.dayrow .ds { color: var(--muted); display: inline-flex; align-items: center; gap: 3px; }
.dayrow .dp { min-width: 64px; text-align: end; }
.ladder > div.neg { background: var(--rose); color: var(--red); }
.modal-card { position: relative; }
.modal-x { position: absolute; top: 10px; inset-inline-end: 10px; }
@media (max-width: 899px) {
  .warnbar { font-size: 12px; padding: 5px 6px 5px 10px; }
  .game.panel-open .sumcard { display: none; }
  .hud.tc { left: 8px; right: 8px; transform: none; max-width: none; }
  .warnbar { width: 100%; max-width: none; }
  .stage:has(#hud-tl:not(:empty)) .hud.tc { top: 62px; }
  .sumcard { max-width: 70vw; font-size: 13px; }
}
.chartwrap svg.chart { height: auto; aspect-ratio: 340 / 196; }

/* ---------- thanh trên: quán, nhiệm vụ, tài khoản ---------- */
.top button.name { text-align: start; padding: 2px 6px; border-radius: 12px; }
.top button.name:hover { background: var(--card2); }
.top .name .shopn { font-size: 12px; color: var(--muted); font-weight: 800; }
.icon-btn { position: relative; }
.icon-btn .badge { position: absolute; top: -4px; inset-inline-end: -4px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.icon-btn img.meav { width: 34px; height: 34px; border-radius: 10px; object-fit: cover; }
.seg.scroll { overflow-x: auto; scrollbar-width: none; }
.seg.scroll::-webkit-scrollbar { display: none; }
.seg.scroll button { flex: 1 0 auto; position: relative; }
.seg .dot { position: absolute; top: 4px; inset-inline-end: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.agree { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; font-weight: 600; text-align: start; margin: 4px 0; }
.agree input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--teal); flex: none; }
.agree a { color: var(--green); font-weight: 800; }

/* ---------- bảng mới ---------- */
.row.sel { box-shadow: inset 0 0 0 2px var(--gold); background: #fdf6dc; }
.row .emo { font-size: 28px; width: 44px; text-align: center; flex: none; }
.row .field { flex: 1; min-width: 0; }
.appdot { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 20px; flex: none; }
.tile .swatch { width: 100%; height: 46px; border-radius: 12px; box-shadow: inset 0 0 0 1px rgba(58, 36, 22, .12); }
.tile .swatch.wood { background-image: repeating-linear-gradient(0deg, rgba(90, 55, 25, .25) 0 2px, transparent 2px 12px); }
.tile .swatch.marble { background-image: linear-gradient(120deg, transparent 40%, rgba(140, 140, 150, .35) 42%, transparent 46%), linear-gradient(60deg, transparent 60%, rgba(140, 140, 150, .25) 62%, transparent 65%); }
.tile .swatch.terrazzo { background-image: radial-gradient(#7a9c8b 2px, transparent 3px), radial-gradient(#f3ead6 2px, transparent 3px); background-size: 14px 14px, 18px 18px; background-position: 0 0, 7px 9px; }
.tile .swatch.tiles { background-image: radial-gradient(circle at 50% 50%, #8fc2b0 0 22%, transparent 23%), linear-gradient(45deg, #efe0c2 25%, #f5ead3 25% 50%, #efe0c2 50% 75%, #f5ead3 75%); background-size: 23px 23px, 23px 23px; }
.tile.cur { border-color: var(--teal); }
.stepper.sm { gap: 4px; }
.stepper.sm .btn.sm { min-height: 28px; min-width: 30px; padding: 0 8px; }
.row.dish .dimg { width: 50px; height: 50px; flex: none; }
.row.dish.off { opacity: .6; }
.row.dish .sub { white-space: normal; }
.qty.sm button { padding: 2px 8px; font-size: 12px; }
.qty.wrap { flex-wrap: wrap; }
.qty button:disabled { opacity: .45; }

/* ---------- thành phố, chat ---------- */
.citymap { width: 100%; height: auto; display: block; border-radius: 18px; direction: ltr; }
.citymap .pin { cursor: pointer; }
.panel-body.chatmode { overflow: hidden; padding-bottom: 10px; }
.chatlist { flex: 1; min-height: 120px; overflow: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px; overscroll-behavior: contain; }
.chatform { display: flex; gap: 6px; }
.chatform .field { flex: 1; min-width: 0; }
.chatrules { font-size: 12px; }
.chatrules a { color: var(--green); font-weight: 800; }
.cmsg { display: flex; gap: 8px; align-items: flex-end; }
.cmsg .cav { width: 32px; height: 32px; border-radius: 10px; background: #fff; flex: none; object-fit: cover; }
.cmsg .cb { background: var(--card2); border-radius: 14px 14px 14px 4px; padding: 6px 10px; max-width: 80%; min-width: 0; }
[dir=rtl] .cmsg .cb { border-radius: 14px 14px 4px 14px; }
.cmsg.me { flex-direction: row-reverse; }
.cmsg.me .cb { background: var(--mint); border-radius: 14px 14px 4px 14px; }
[dir=rtl] .cmsg.me .cb { border-radius: 14px 14px 14px 4px; }
.cmsg .ch { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.cmsg .cn { font-weight: 800; font-size: 13px; color: var(--green); padding: 0; }
.cmsg time { font-size: 11px; color: var(--muted); }
.cmsg .ct { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; white-space: pre-wrap; }
.cmsg .rep { color: var(--muted); font-size: 14px; padding: 4px; opacity: .55; }
.cmsg .rep:hover { opacity: 1; color: var(--red); }
.cmsg.news { justify-content: center; flex-wrap: wrap; gap: 6px; font-size: 13px; font-weight: 700; color: #7a5a0a; background: #fdf6dc; border-radius: 12px; padding: 6px 10px; align-items: center; text-align: center; }
.cmsg.news.sys { background: #e8edfb; color: #2c3a7a; }
.cmsg .lnk { font-size: 12px; font-weight: 800; color: var(--green); padding: 2px 8px; border-radius: 9px; background: var(--card); }

/* ---------- ghé thăm ---------- */
.visitcard { width: 290px; display: flex; flex-direction: column; gap: 8px; }
.visitcard .vh { display: flex; gap: 10px; align-items: center; }
.visitcard .vh b { font-size: 17px; display: block; }
.visitcard .vav { width: 46px; height: 46px; border-radius: 12px; background: var(--card2); }
.visitcard .vs { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.visitcard .vmenu { display: flex; flex-wrap: wrap; gap: 4px; }
.visitcard .vmenu .chip { padding: 1px 8px 1px 2px; }
.visitcard .vmenu img { width: 22px; height: 22px; }
.floorbtn { background: var(--card); box-shadow: var(--sh2); }

/* ---------- tài khoản ---------- */
.modal-card .form { display: flex; flex-direction: column; gap: 6px; text-align: start; }
.avrow { display: flex; gap: 10px; justify-content: center; }
.avpick { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 10px; border-radius: 16px; background: var(--card); font-weight: 700; border: 2px solid transparent; }
.avpick img { width: 64px; height: 64px; }
.avpick.on { border-color: var(--teal); background: var(--mint); }
details.pw { background: var(--card); border-radius: 16px; padding: 8px 12px; text-align: start; }
details.pw summary { cursor: pointer; font-weight: 800; }
details.pw .form { margin-top: 8px; }
.shoprow { grid-template-columns: 1fr auto auto auto; }

@media (max-width: 899px) {
  .visitcard { width: min(290px, 70vw); padding: 10px; gap: 6px; }
  .visitcard .vmenu, .visitcard > .hint { display: none; }
  .icon-btn img.meav { width: 28px; height: 28px; }
}
/* không để nội dung bảng làm giãn bố cục, không để phần tử bị co về 0 */
.panel, .panel-tabs, .panel-body { min-width: 0; }
.panel-body > * { flex-shrink: 0; min-width: 0; }
.panel-body.chatmode > .chatlist { flex: 1 1 auto; min-height: 0; }
.chatlist > * { flex-shrink: 0; }
.citymap { aspect-ratio: 1000 / 760; }
.row > .qty { flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 899px) {
  .game, .game.panel-open { grid-template-columns: minmax(0, 1fr); }
}
a.btn { text-decoration: none; color: inherit; }

/* ---------- khung chat một bên ---------- */
:root { --chat: 330px; }
.chatbox { grid-area: chat; display: flex; flex-direction: column; background: var(--card); border-inline-start: 1px solid var(--line); min-height: 0; min-width: 0; z-index: 2; }
.chatbox .chead { display: flex; align-items: center; gap: 8px; padding: 10px 10px 4px 14px; position: relative; }
.chatbox .chead h3 { margin: 0; flex: 1; font-size: 18px; }
.chatbox .chead .grip { display: none; }
.chatbox .chatrules { padding: 0 14px 6px; font-size: 12px; }
.chatbox .chatlist { flex: 1 1 auto; min-height: 0; padding: 6px 10px; }
.chatbox .chatform { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.top .icon-btn.on { background: var(--mint); }
@media (min-width: 900px) {
  .game.chat-open { grid-template-columns: var(--rail) minmax(0, 1fr) var(--chat); grid-template-areas: "top top top" "rail stage chat"; }
  .game.chat-open.panel-open { grid-template-columns: var(--rail) minmax(0, 1fr) var(--chat) var(--panel); grid-template-areas: "top top top top" "rail stage chat panel"; }
  .hud.side { display: none; }
}
@media (min-width: 900px) and (max-width: 1280px) {
  .game.chat-open { --chat: 290px; }
  .game.chat-open.panel-open { --panel: 360px; }
}

/* ---------- điện thoại: nút phụ xếp dọc bên cạnh, chat thay chỗ bảng chức năng ---------- */
.hud.side { top: 10px; inset-inline-end: 8px; align-items: center; gap: 7px; }
.hud.side .sbtn { position: relative; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 20px; background: rgba(255, 250, 240, .96); box-shadow: var(--sh2); }
.hud.side .sbtn.on { background: var(--mint); box-shadow: inset 0 0 0 2px var(--teal); }
.hud.side .sbtn.rate { display: flex; flex-direction: column; gap: 0; line-height: 1; }
.hud.side .sbtn.rate .st { color: #f2b632; font-size: 16px; }
.hud.side .sbtn.rate b { font-size: 13px; }
.hud.side .sbtn.av img { width: 36px; height: 36px; border-radius: 11px; }
.hud.side .sbtn .badge { position: absolute; top: -5px; inset-inline-end: -5px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
@media (max-width: 899px) {
  .top .name { flex: 1 1 auto; min-width: 0; max-width: none; }
  .top .name b { max-width: 100%; font-size: 15px; }
  .top .grow { display: none; }
  .hud.tc { left: 8px; right: 60px; }
  [dir=rtl] .hud.tc { left: 60px; right: 8px; }
  .hud.tl { max-width: calc(100% - 70px); }
  .game.panel-open .hud.side .opt, .game.chat-open .hud.side .opt { display: none; }
  .game.chat-open .sumcard, .game.chat-open .hud.bl, .game.chat-open .hud.tc .chip { display: none; }
  .game.chat-open { grid-template-rows: var(--top) minmax(calc(30 * var(--vh)), 1fr) minmax(0, calc(56 * var(--vh))) auto; grid-template-areas: "top" "stage" "chat" "rail"; }
  .game.chat-open .panel { display: none; }
  .chatbox { border: 0; border-radius: 22px 22px 0 0; box-shadow: 0 -6px 18px rgba(58, 36, 22, .12); }
  .chatbox .chead { padding: 8px 10px 2px 14px; }
  .chatbox .chead .grip { display: block; position: absolute; top: 5px; left: 50%; transform: translateX(-50%); width: 42px; height: 5px; border-radius: 9px; background: var(--line); }
  .chatbox .chead h3 { padding-top: 6px; font-size: 17px; }
  .chatbox .chatform { padding-bottom: 8px; }
}

/* ---------- điện thoại: không phóng to cả trang, chừa tai thỏ, mọi thứ nằm trong màn hình ---------- */
:root { --vh: 1vh; }
@supports (height: 1dvh) { :root { --vh: 1dvh; } }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; overscroll-behavior: none; }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea, select, .cmsg .ct, .chatrules { -webkit-user-select: text; user-select: text; }
img { -webkit-user-drag: none; }
.screen { box-sizing: border-box; padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
.game { background: var(--card); }
.boot { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.modal { padding: max(14px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); overscroll-behavior: contain; }
.modal-card { max-width: 100%; min-width: 0; }
.modal-card > * { min-width: 0; max-width: 100%; }
.toasts { top: calc(var(--top) + env(safe-area-inset-top) + 8px); }
.conn { bottom: calc(12px + env(safe-area-inset-bottom)); }
/* cột nút dọc: hết chỗ thì tự sang cột thứ hai, không tràn khỏi sân khấu */
.hud.side { grid-auto-flow: column; grid-template-rows: repeat(auto-fill, 44px); gap: 7px; max-height: calc(100% - 66px); justify-items: center; }
@media (max-width: 899px) { .hud.side { display: grid; } }
.hud > * { max-width: 100%; }
.editbar { max-width: calc(100% - 16px); }
.card, .banner, .tip, .warnbar, .sumcard { max-width: 100%; }
@media (max-width: 899px) {
  input, select, textarea, input.field { font-size: 16px; } /* iOS tự phóng to khi chữ ô nhập nhỏ hơn 16px */
  .hud.br { max-width: calc(100% - 16px); }
  .hud.bl { max-width: calc(100% - 80px); bottom: 60px; } /* nằm trên hàng nút sân thượng / phóng to / sửa quán */
  .game:has(.sumcard) .hud.bl .tip { display: none; }
  .sumcard { max-width: min(70vw, calc(100% - 16px)); }
}
@media (max-width: 360px) {
  .top { gap: 4px; padding: 0 6px; }
  .top .clock span { display: none; }
  .pill { padding: 2px 7px 2px 3px; font-size: 13px; gap: 3px; }
  .pill img { width: 20px; height: 20px; }
}
@media (max-height: 520px) and (max-width: 950px) { /* điện thoại xoay ngang */
  :root { --top: 46px; }
  .tab { font-size: 10px; } .tab img { width: 26px; height: 26px; }
  .hud.side { grid-template-rows: repeat(auto-fill, 38px); } .hud.side .sbtn { width: 38px; height: 38px; font-size: 17px; }
}
/* chặn người chơi, nhắc nhở, xoá tài khoản */
.cmsg .cacts { display: flex; flex-direction: column; gap: 2px; align-self: flex-start; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--card); font-weight: 700; text-align: start; }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--teal); }
details.danger summary { color: var(--red); }
@media (max-width: 899px) { .hud.br .sumcard { margin-inline-end: 56px; max-width: calc(100vw - 80px); } }
@media (max-height: 520px) and (max-width: 950px) { .hud.br .sumcard { margin-inline-end: 104px; max-width: 46vw; } }

/* ---------- đăng nhập bằng Apple, tuổi, hỗ trợ, màn hình chặn ---------- */
.btn.apple { background: #000; color: #fff; box-shadow: var(--sh2); font-weight: 700; }
.btn.apple:active { background: #222; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; font-weight: 700; margin: 2px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: rgba(58, 36, 22, .15); }
.birth select { min-width: 0; }
select.field, textarea.field { width: 100%; padding: 10px 14px; border-radius: 14px; border: 2px solid var(--line); background-color: #fff; font: inherit; font-size: 16px; color: var(--ink); }
select.field:focus, textarea.field:focus { outline: none; border-color: var(--teal); }
.modal-card .sec, .modal-card .form, .modal-card .tickets { text-align: start; }
select.field { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-inline-end: 28px; }
[dir="rtl"] select.field { background-position: 16px 55%, 11px 55%; }
textarea.field { resize: vertical; min-height: 84px; font: inherit; line-height: 1.45; }
.toggle-row.dim input { opacity: .6; }
.big { font-size: 46px; line-height: 1; }
.block { display: grid; place-items: center; background: var(--bg); overflow: auto; z-index: 40; }
.block-card { width: min(440px, calc(100vw - 32px)); margin: 24px auto; padding: 26px 22px; background: var(--card); border-radius: 22px; box-shadow: var(--sh2); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.block-card .logo { width: 72px; }
.block-card h2 { margin: 0; font-size: 22px; }
.block-card p { margin: 0; }
.block-card .spin { margin-top: 4px; }
.tickets { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow: auto; }
.ticket summary { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.thread { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.tmsg { background: var(--card2); border-radius: 12px; padding: 6px 10px; max-width: 92%; text-align: start; white-space: pre-wrap; word-break: break-word; }
.tmsg.user { align-self: flex-end; background: #e7f3ef; }
.tmsg.admin { align-self: flex-start; }
.tmsg .th { display: flex; gap: 8px; justify-content: space-between; font-size: 12px; color: var(--muted); }
.tmsg .th time { direction: ltr; }
