:root {
  --ink: #fff8ec;
  --ink-soft: rgba(255, 248, 236, .72);
  --glass: rgba(52, 36, 22, .55);
  --glass-strong: rgba(30, 23, 16, .82);
  --line: rgba(255, 236, 200, .18);
  --gold: #e9c27a;
  --son: #b5432f;
  --green: #7fd17f;
  --red: #ff8a7a;
  --font: "Be Vietnam Pro", system-ui, sans-serif;
  --serif: "Baloo 2", "Be Vietnam Pro", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a2118; color: var(--ink); font-family: var(--font); user-select: none; -webkit-tap-highlight-color: transparent; }
#scene, #scene canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font-family: inherit; color: inherit; cursor: pointer; }
kbd { display: inline-block; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--line); background: rgba(255,255,255,.12); font-family: var(--font); font-size: 12px; }

#loading { position: fixed; inset: 0; display: grid; place-items: center; font-family: var(--serif); font-size: 22px; color: var(--gold); background: #2a2118; z-index: 50; text-align: center; padding: 20px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud button, #hud .pill { pointer-events: auto; }
.pill { position: absolute; display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-size: 14px; white-space: nowrap; }
.pill .sep { width: 1px; height: 16px; background: var(--line); }
.pill .dim { color: var(--ink-soft); }
.brand { font-family: var(--serif); font-weight: 800; font-size: 18px; color: var(--gold); letter-spacing: .01em; }
.tl { top: 14px; left: 14px; }
.tr { top: 14px; right: 14px; }
.tr .money b { color: var(--gold); font-size: 15px; }
.tr .nm { font-weight: 600; }
.energy { top: 60px; right: 14px; gap: 8px; }
.energy .et { width: 120px; height: 8px; border-radius: 6px; background: rgba(255,255,255,.12); overflow: hidden; }
#hud-energy-fill { height: 100%; background: linear-gradient(90deg, #8fd16a, #e9c27a); transition: width .3s; }
#hud-energy-fill.low { background: linear-gradient(90deg, #ff6a5a, #ff9a6a); }
.energy small { color: var(--ink-soft); min-width: 52px; }
#hud-time { font-variant-numeric: tabular-nums; font-weight: 600; }

.menu { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 8px; }
.menu button { width: 58px; height: 58px; border-radius: 20px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-size: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; transition: transform .15s, background .15s; }
.menu button small { font-size: 10px; color: var(--ink-soft); }
.menu button.wide { width: 88px; }
.menu button.wide small { white-space: nowrap; }
.menu button:hover { background: var(--glass-strong); transform: translateY(-2px); }

#toasts { position: absolute; left: 14px; top: 62px; width: min(420px, calc(100vw - 28px)); display: flex; flex-direction: column; gap: 6px; }
.toast { padding: 9px 13px; border-radius: 12px; background: var(--glass-strong); border: 1px solid var(--line); font-size: 13.5px; line-height: 1.45; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); animation: tin .3s ease; transition: opacity .5s, transform .5s; }
.toast.ok { border-left: 3px solid var(--green); }
.toast.bad { border-left: 3px solid var(--red); }
.toast.warn { border-left: 3px solid #f2b134; }
.toast.gold { border-left: 3px solid var(--gold); background: rgba(70, 50, 20, .88); }
.toast.news { border-left: 3px solid #7fb3ff; }
.toast.out { opacity: 0; transform: translateX(-20px); }
@keyframes tin { from { opacity: 0; transform: translateX(-20px); } }

#prompt { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(10px); opacity: 0; transition: .2s; padding: 10px 16px; border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--line); font-size: 15px; display: flex; gap: 10px; align-items: center; pointer-events: none; white-space: nowrap; }
#prompt.show { opacity: 1; transform: translateX(-50%); }
#prompt .ic { margin-right: 6px; }
#prompt .st { margin-left: 4px; }

#progress { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); width: 320px; padding: 10px 14px; pointer-events: auto; border-radius: 16px; background: var(--glass-strong); border: 1px solid var(--line); text-align: center; display: none; }
#progress.show { display: block; }
#progress-name { font-family: var(--serif); font-size: 17px; color: var(--gold); text-align: left; }
.pr-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
#progress-stop { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.08); font-size: 12px; }
#progress-info { display: block; margin-top: 5px; color: var(--ink-soft); font-size: 12px; text-align: left; }
.pt-track { height: 8px; border-radius: 6px; background: rgba(255,255,255,.12); overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #8fd16a, #e9c27a); }

body.nohud #hud, body.nohud #labels { display: none; }
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
.lbl { position: absolute; left: 0; top: 0; padding: 3px 8px; border-radius: 999px; background: rgba(30, 23, 16, .7); border: 1px solid var(--line); font-size: 15px; white-space: nowrap; will-change: transform; }

#joy, #btn-act { display: none; }
body.touch #joy { display: block; position: absolute; left: 22px; bottom: 22px; width: 120px; height: 120px; border-radius: 50%; background: var(--glass); border: 1px solid var(--line); pointer-events: auto; touch-action: none; }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%; background: rgba(255, 248, 236, .35); border: 1px solid var(--line); }
body.touch #btn-act { display: block; position: absolute; right: 22px; bottom: 90px; width: 74px; height: 74px; border-radius: 50%; background: rgba(181, 67, 47, .75); border: 1px solid var(--line); font-size: 30px; pointer-events: auto; }
body.touch #prompt { bottom: 175px; }
body.touch .menu button { width: 48px; height: 48px; font-size: 18px; }
body.touch .menu button small { display: none; }

/* ---------- Bảng ---------- */
#panel { position: fixed; right: 14px; top: 150px; bottom: 86px; width: min(440px, calc(100vw - 28px)); background: var(--glass-strong); border: 1px solid var(--line); border-radius: 20px; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); z-index: 8; display: flex; flex-direction: column; transform: translateX(30px); opacity: 0; pointer-events: none; transition: .22s ease; }
#panel.open { transform: none; opacity: 1; pointer-events: auto; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-family: var(--serif); font-weight: 700; font-size: 21px; color: var(--gold); }
#panel-close { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.06); font-size: 15px; }
#panel-body { padding: 12px 16px 16px; overflow-y: auto; flex: 1; font-size: 14px; line-height: 1.5; }
#panel-body p { margin: 6px 0; }
#panel-body::-webkit-scrollbar { width: 6px; }
#panel-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.info p b { color: var(--gold); }
.sec { margin: 14px 0 8px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.act { display: block; width: 100%; text-align: left; margin: 6px 0; padding: 10px 14px; border-radius: 16px; border: 1px solid var(--line); background: rgba(255,255,255,.06); transition: background .15s, transform .1s; }
.act:hover:not(:disabled) { background: rgba(255,255,255,.14); }
.act:active:not(:disabled) { transform: scale(.98); }
.act b { display: block; font-weight: 600; font-size: 14.5px; }
.act small { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 12px; }
.act.gold { background: linear-gradient(135deg, rgba(233,194,122,.32), rgba(181,67,47,.32)); border-color: rgba(233,194,122,.5); }
.act.owned { opacity: .55; }
.act:disabled { cursor: default; }
.bar { margin: 7px 0; }
.bar-l { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 3px; }
.bar-t { height: 7px; border-radius: 5px; background: rgba(255,255,255,.1); overflow: hidden; }
.bar-f { height: 100%; }
.bar-f.good { background: #8fd16a; } .bar-f.mid { background: #f2b134; } .bar-f.bad { background: #ff6a5a; }
.hint { color: var(--ink-soft); font-size: 12.5px; }
.news { padding: 8px 10px; margin: 8px 0; border-radius: 10px; background: rgba(127,179,255,.12); border: 1px solid rgba(127,179,255,.3); font-size: 12.5px; }

.tabs { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.tabs button { flex: 1; padding: 8px 6px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.05); font-size: 12.5px; }
.tabs button.on { background: rgba(233,194,122,.25); border-color: rgba(233,194,122,.5); }
.mlist { display: flex; flex-direction: column; gap: 6px; }
.mrow { display: grid; grid-template-columns: 30px 1fr auto; grid-template-areas: "ic mn mp" "ic sp mb"; gap: 2px 8px; align-items: center; padding: 8px 10px; border-radius: 12px; background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.mrow.dim { opacity: .55; }
.mrow .ic { grid-area: ic; font-size: 22px; }
.mrow .mn { grid-area: mn; min-width: 0; }
.mrow .mn small, .mrow .mp small { display: block; color: var(--ink-soft); font-size: 11.5px; }
.mrow .mp { grid-area: mp; text-align: right; }
.mrow .mp b { color: var(--gold); }
.mrow .spark { grid-area: sp; }
.mrow .mb { grid-area: mb; display: flex; gap: 4px; justify-content: flex-end; }
.spark { width: 80px; height: 20px; }
.mini { padding: 5px 9px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255,255,255,.08); font-size: 12px; line-height: 1.2; }
.mini:hover:not(:disabled) { background: rgba(233,194,122,.25); }
.mini:disabled { opacity: .35; cursor: default; }
.tr.up { color: var(--green); } .tr.down { color: var(--red); } .tr.flat { color: var(--ink-soft); }
.pt { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.pt th { text-align: left; color: var(--ink-soft); font-weight: 500; padding: 4px; }
.pt td { padding: 5px 4px; border-top: 1px solid var(--line); }
.inv { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.slot { padding: 8px; border-radius: 12px; background: rgba(255,255,255,.06); border: 1px solid var(--line); text-align: center; }
.slot .ic { font-size: 24px; display: block; }
.slot b { display: block; color: var(--gold); }
.slot small { color: var(--ink-soft); font-size: 11px; }
.alist { display: flex; flex-direction: column; gap: 5px; }
.arow { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 11px; background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.arow.ready { border-color: rgba(233,194,122,.55); }
.arow .ai { font-size: 22px; }
.arow div { flex: 1; min-width: 0; }
.arow small { display: block; color: var(--ink-soft); font-size: 11.5px; }
.quests .q { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.quests .q.done { color: var(--ink-soft); text-decoration: line-through; }
.quests small { color: var(--gold); }
.log p { font-size: 12.5px; }
.log small { color: var(--ink-soft); }
.talk p { font-family: var(--serif); font-size: 17px; line-height: 1.6; }
.help ol { padding-left: 20px; margin: 6px 0; }
.help li { margin: 4px 0; }

/* ---------- Màn hình mở đầu ---------- */
.overlay { position: fixed; inset: 0; display: none; place-items: center; z-index: 20; background: radial-gradient(ellipse at center, rgba(20,15,10,.25), rgba(20,15,10,.7)); padding: 16px; }
.overlay.open { display: grid; }
.title-card { max-width: 560px; text-align: center; padding: 34px 30px; border-radius: 26px; background: var(--glass-strong); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.title-card .kicker { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); }
.title-card h1 { font-family: var(--serif); font-size: clamp(42px, 9vw, 68px); line-height: 1.05; margin: 8px 0 12px; color: #ffe08a; font-weight: 800; text-shadow: 0 4px 0 #8a4a20, 0 8px 18px rgba(0,0,0,.35); }
.title-card h1 span { color: var(--son); background: #f4e3c0; padding: 0 12px; border-radius: 12px; }
.title-card p { color: var(--ink-soft); line-height: 1.65; }
.tbtns { display: flex; gap: 10px; margin: 18px 0 12px; flex-wrap: wrap; }
.tbtns .act { flex: 1; min-width: 200px; text-align: center; padding: 14px; }
.ctrl { color: var(--ink-soft); }

.overlay-side { position: fixed; left: 14px; top: 14px; bottom: 14px; width: min(470px, calc(100vw - 28px)); z-index: 20; display: none; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 22px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); overflow-y: auto; padding: 18px 20px; }
.overlay-side.open { display: block; }
#creator h2 { font-family: var(--serif); color: var(--gold); margin: 0 0 10px; }
.cr-row { margin: 10px 0; }
.cr-row label { display: block; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 5px; }
.cr-row input { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--ink); font-family: inherit; font-size: 15px; outline: none; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips button { padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.06); font-size: 13px; }
.chips button.on { background: rgba(233,194,122,.3); border-color: var(--gold); }
.sw { display: flex; gap: 7px; flex-wrap: wrap; }
.sw button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); }
.sw button.on { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(233,194,122,.5); }
.bgs { display: flex; flex-direction: column; gap: 5px; }
.bgs button { text-align: left; padding: 8px 11px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.05); }
.bgs button.on { background: rgba(233,194,122,.22); border-color: var(--gold); }
.bgs b { display: block; font-size: 13.5px; }
.bgs small { color: var(--ink-soft); font-size: 12px; }
.cr-btns { display: flex; gap: 8px; margin-top: 14px; position: sticky; bottom: -18px; padding: 10px 0 4px; background: linear-gradient(transparent, rgba(30,23,16,.95) 30%); }
.cr-btns .act { text-align: center; }

#fade { position: fixed; inset: 0; background: #05070d; opacity: 0; pointer-events: none; transition: opacity .8s; z-index: 30; }
#fade.on { opacity: 1; }

@media (max-width: 640px) {
  .hide-sm, .tl .brand, .tl .brand + .sep { display: none; }
  .tl { font-size: 12.5px; padding: 7px 11px; gap: 7px; }
  .tr { font-size: 12.5px; padding: 7px 11px; top: 54px; left: 14px; right: auto; }
  .tr .nm, .tr .sep { display: none; }
  .energy { top: 54px; right: 14px; }
  .energy .et { width: 70px; }
  #toasts { top: 98px; }
  #panel { top: auto; bottom: 0; right: 0; left: 0; width: 100%; max-height: 62vh; border-radius: 20px 20px 0 0; }
  .menu { bottom: auto; top: 98px; right: 14px; flex-direction: column; }
  body.touch .menu { top: 98px; }
}

/* ---------- Chơi nhiều người ---------- */
.login { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.login input { padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--ink); font-family: inherit; font-size: 15px; outline: none; }
.login input:focus { border-color: var(--gold); }
.login .tbtns { margin: 4px 0 0; }
#lg-msg { min-height: 20px; font-size: 13.5px; color: var(--ink-soft); }
#lg-msg.bad { color: var(--red); }
.link { background: none; border: none; color: var(--ink-soft); text-decoration: underline; font-size: 13px; padding: 4px; }
#hud-online b { color: var(--green); }
.nametag { position: absolute; left: 0; top: 0; pointer-events: none; white-space: nowrap; will-change: transform; }
.nametag span { display: inline-block; padding: 2px 9px; border-radius: 999px; background: rgba(30, 23, 16, .72); border: 1px solid rgba(255,236,200,.25); font: 600 12.5px var(--font); color: #fff3d6; }
.bubble { position: absolute; left: 0; top: 0; max-width: 220px; padding: 7px 11px; border-radius: 14px; background: #fffaf0; color: #3a2618; font: 500 13.5px/1.35 var(--font); box-shadow: 0 3px 0 rgba(58,38,24,.25); pointer-events: none; will-change: transform; animation: pop .2s ease; white-space: normal; text-align: center; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: #fffaf0; }
.bubble.big { font-size: 30px; padding: 2px 8px; background: transparent; box-shadow: none; }
.bubble.big::after { display: none; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
#chat { position: absolute; left: 14px; bottom: 14px; width: min(400px, calc(100vw - 120px)); display: none; flex-direction: column; gap: 6px; pointer-events: none; }
#chat.on { display: flex; }
#chat-log { max-height: 150px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; opacity: 0; transition: opacity .4s; }
#chat.recent #chat-log, #chat.typing #chat-log { opacity: 1; }
#chat.typing #chat-log { pointer-events: auto; }
.cl { font-size: 13px; padding: 3px 9px; border-radius: 10px; background: rgba(30,23,16,.62); align-self: flex-start; max-width: 100%; word-wrap: break-word; }
.cl b { color: var(--gold); }
.cl.mine b { color: var(--green); }
.chat-row { display: flex; gap: 6px; align-items: center; pointer-events: auto; }
#chat-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); font-size: 18px; flex: none; }
#chat-input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass-strong); color: var(--ink); font-family: inherit; font-size: 13.5px; outline: none; display: none; }
#chat.typing #chat-input { display: block; }
.emo { display: flex; gap: 3px; }
#chat.typing .emo { display: none; }
.emo button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); font-size: 16px; padding: 0; }
body.touch #chat { bottom: 150px; }

.food { top: 104px; right: 14px; gap: 8px; cursor: pointer; }
.food .et { width: 120px; height: 8px; border-radius: 6px; background: rgba(255,255,255,.12); overflow: hidden; }
#hud-food-fill { height: 100%; background: linear-gradient(90deg, #f2c94c, #ffe08a); transition: width .3s; }
#hud-food-fill.low { background: linear-gradient(90deg, #ff6a5a, #ff9a6a); }
.food small { color: var(--ink-soft); min-width: 52px; }
.rest { left: 50%; top: 14px; transform: translateX(-50%); display: none; color: #fff3d6; }
.rest.on { display: flex; }
@media (max-width: 640px) { .food { top: 98px; } .food .et { width: 70px; } #progress { top: 140px; width: calc(100vw - 28px); } }

/* ---------- Số lượng mua bán ---------- */
.mrow { grid-template-areas: "ic mn mp" "ic sp sp" "qt qt qt"; }
.qty { grid-area: qt; display: flex; gap: 4px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.qty input { width: 64px; padding: 5px 6px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--ink); font-family: inherit; font-size: 13px; text-align: center; }
.qty .go { margin-left: auto; background: rgba(233,194,122,.28); border-color: rgba(233,194,122,.55); font-weight: 600; }
/* ---------- Cửa hàng ---------- */
.srow { padding: 8px 10px; border-radius: 12px; background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.srow .sh { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.srow .sh .pr { margin-left: auto; color: var(--gold); font-weight: 600; }
.sw.small button { width: 26px; height: 26px; }
.chipb { padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.06); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.chipb.on { background: rgba(233,194,122,.3); border-color: var(--gold); }
.chipb i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 1px solid rgba(255,255,255,.4); }
/* ---------- Xe ---------- */
.vehchip { left: 50%; bottom: 150px; transform: translateX(-50%); display: none; font-size: 13px; }
.vehchip.on { display: flex; }
/* ---------- Hướng dẫn ---------- */
.tut { position: absolute; right: 14px; top: 150px; width: 270px; padding: 10px 12px; border-radius: 16px; background: rgba(52, 36, 22, .78); border: 1px solid rgba(233,194,122,.45); backdrop-filter: blur(10px); pointer-events: auto; font-size: 13.5px; line-height: 1.45; }
.tut p { margin: 6px 0 0; }
.tut p b { color: var(--gold); }
.tut-h { display: flex; justify-content: space-between; align-items: center; color: var(--gold); }
.tut-h button { border: none; background: rgba(255,255,255,.1); border-radius: 6px; width: 24px; height: 22px; }
.tut .tut-min { border: none; background: none; color: var(--gold); font-weight: 600; padding: 0; }
#story .story-card { max-width: 560px; padding: 30px 30px 22px; border-radius: 26px; background: var(--glass-strong); border: 1px solid var(--line); backdrop-filter: blur(14px); text-align: center; }
.story-kicker { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
.story-icon { font-size: 64px; margin: 10px 0 2px; }
#story h2 { font-family: var(--serif); color: #ffe08a; margin: 6px 0 10px; font-size: 28px; }
#story p { line-height: 1.7; color: #f3e6cf; font-size: 15.5px; }
#story p b { color: var(--gold); }
.story-btns { display: flex; gap: 10px; margin-top: 16px; }
.story-btns .act { text-align: center; }
/* ---------- Trò chơi ---------- */
#mg { position: fixed; inset: 0; display: none; place-items: center; z-index: 25; background: rgba(20,15,10,.45); padding: 12px; }
#mg.open { display: grid; }
.mg-card { width: min(640px, 100%); max-height: 96vh; overflow: auto; border-radius: 22px; background: var(--glass-strong); border: 1px solid var(--line); backdrop-filter: blur(14px); padding: 14px 16px; }
.mg-head { display: flex; justify-content: space-between; align-items: center; }
.mg-head h3 { margin: 0; font-family: var(--serif); color: var(--gold); font-size: 22px; }
.mg-x { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.06); }
.oaq-score { display: flex; justify-content: space-between; margin: 10px 4px; font-size: 15px; }
.oaq-score b { color: var(--gold); font-size: 18px; }
.oaq-board { display: grid; grid-template-columns: 70px 1fr 70px; grid-template-rows: 1fr 1fr; gap: 0; background: #c9a06a; border: 4px solid #6b4a2b; border-radius: 60px 60px 60px 60px / 90px 90px 90px 90px; padding: 8px; }
.oaq-board .q { grid-row: 1 / span 2; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 3px; padding: 6px; border: 3px solid #6b4a2b; position: relative; min-height: 130px; }
.oaq-board .q0 { grid-column: 1; border-radius: 60px 0 0 60px; border-right-width: 1px; }
.oaq-board .q6 { grid-column: 3; border-radius: 0 60px 60px 0; border-left-width: 1px; }
.oaq-board .row { grid-column: 2; display: grid; grid-template-columns: repeat(5, 1fr); }
.oaq-board .top { grid-row: 1; } .oaq-board .bot { grid-row: 2; }
.oaq-board .o { border: 2px solid #6b4a2b; min-height: 64px; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 3px; padding: 4px; position: relative; }
.oaq-board .o.mine { cursor: pointer; }
.oaq-board .o.mine:hover { background: rgba(255,255,255,.18); }
.oaq-board .hl { background: rgba(255,240,160,.55) !important; }
.oaq-board .sel { background: rgba(127,209,127,.45) !important; }
.oaq-board i { width: 9px; height: 9px; border-radius: 50%; background: #5a4a3e; box-shadow: inset -2px -2px 0 rgba(0,0,0,.3); display: inline-block; }
.oaq-board i.bigq { width: 22px; height: 22px; background: #3a2a20; }
.oaq-board em { position: absolute; right: 4px; bottom: 2px; font-style: normal; font-size: 11px; color: #3a2618; font-weight: 700; }
.oaq-msg { min-height: 24px; margin: 10px 2px 4px; font-size: 14.5px; }
.oaq-msg b { color: var(--gold); }
.oaq-dir { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.oaq-dir .act { flex: 1; text-align: center; min-width: 120px; }
.oaq-rule { margin-top: 8px; font-size: 13px; color: var(--ink-soft); }
.dacau canvas { width: 100%; max-width: 360px; display: block; margin: 8px auto; border-radius: 14px; touch-action: none; }

.bgcard { text-align: left; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--gold); background: rgba(233,194,122,.18); }
.bgcard b { display: block; font-size: 15px; }
.bgcard small { color: var(--ink-soft); font-size: 12.5px; }
#cr-reroll { margin-top: 6px; }
.tip { margin: 8px 0; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.05); border: 1px solid var(--line); font-size: 12.8px; line-height: 1.55; }
.tip b { color: var(--gold); }

/* ---------- Bảng chỉ số ---------- */
.stats { position: absolute; top: 60px; right: 14px; width: 232px; padding: 8px 12px; border-radius: 16px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); display: flex; flex-direction: column; gap: 5px; pointer-events: auto; }
.stats .st { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.stats .st.click { cursor: pointer; }
.stats .et { flex: 1; height: 8px; border-radius: 6px; background: rgba(255,255,255,.12); overflow: hidden; }
.stats .et > div { height: 100%; transition: width .3s; }
.stats small { color: var(--ink-soft); min-width: 56px; text-align: right; font-size: 12px; }
#hud-energy-fill { background: linear-gradient(90deg, #8fd16a, #e9c27a); }
#hud-awake-fill { background: linear-gradient(90deg, #8a9cff, #c8b8ff); }
#hud-spirit-fill { background: linear-gradient(90deg, #ff9fb6, #ffd166); }
#hud-energy-fill.low, #hud-food-fill.low, #hud-awake-fill.low, #hud-spirit-fill.low { background: linear-gradient(90deg, #ff6a5a, #ff9a6a); }
.tut { top: 188px !important; }
#panel { top: 188px !important; }
#sleepfx { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, rgba(10,12,30,.25), rgba(5,6,18,.78)); opacity: 0; transition: opacity 1.2s; display: grid; place-items: center; z-index: 3; }
#sleepfx span { font-family: var(--serif); font-size: 46px; color: rgba(220,225,255,.75); letter-spacing: .3em; animation: zz 3s ease-in-out infinite; }
body.sleeping #sleepfx { opacity: 1; }
@keyframes zz { 0%, 100% { transform: translateY(0); opacity: .5; } 50% { transform: translateY(-14px); opacity: 1; } }
@media (max-width: 640px) { .stats { top: 98px; width: 170px; } .tut, #panel { top: 230px !important; } }

#hud-health-fill { background: linear-gradient(90deg, #ff6f8a, #ffb3c1); }
#hud-health-fill.low { background: linear-gradient(90deg, #d32f2f, #ff6a5a); }
#hud-health.sick small { color: #ff9a8a; font-weight: 600; }
.tut { top: 212px !important; }
#panel { top: 212px !important; }
@media (max-width: 640px) { .tut, #panel { top: 252px !important; } }

/* ---------- Bản đồ ---------- */
#minimap { position: absolute; left: 14px; bottom: 64px; width: 150px; height: 150px; border-radius: 50%; pointer-events: auto; cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,.35); }
body.touch #minimap { left: auto; right: 14px; bottom: auto; top: 270px; width: 96px; height: 96px; }
#bigmap { position: fixed; inset: 0; z-index: 22; display: none; place-items: center; background: rgba(20,15,10,.55); padding: 10px; }
#bigmap.open { display: grid; }
.bm-card { padding: 12px 14px; border-radius: 20px; background: var(--glass-strong); border: 1px solid var(--line); backdrop-filter: blur(12px); max-width: 100%; }
.bm-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.bm-head b { font-family: var(--serif); font-size: 21px; color: var(--gold); }
.bm-head span { color: var(--ink-soft); font-size: 12.5px; flex: 1; }
.bm-x { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.06); }
.bm-card canvas { display: block; border-radius: 12px; max-width: 100%; }
.bm-leg { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: var(--ink-soft); }
.bm-leg i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
#chat { bottom: 14px; left: 178px; }
body.touch #chat { left: 14px; }

.bm-travel { margin-top: 8px; font-size: 13px; }
.bm-travel b { color: var(--gold); }
.bm-dests { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; max-height: 92px; overflow-y: auto; }
.bm-dests .mini small { color: var(--gold); margin-left: 3px; }
.bm-z { width: 32px; height: 32px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--ink); font-size: 15px; cursor: pointer; }
.bm-card canvas { touch-action: none; cursor: grab; }
.bm-lot { margin-top: 6px; font-size: 13px; color: var(--ink-soft); }
.bm-lot input { padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--ink); }
.bm-dests { max-height: 96px; overflow-y: auto; }

/* ---------- cột phải: hướng dẫn + việc cần làm ---------- */
.rcol { position: absolute; right: 14px; top: 212px; width: 270px; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 300px); overflow-y: auto; pointer-events: auto; }
.rcol .tut { position: static; width: auto; }
.todo { padding: 8px 10px; border-radius: 16px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 13px; }
.todo-h { display: flex; justify-content: space-between; align-items: center; color: var(--gold); }
.todo-min { border: none; background: rgba(255,255,255,.1); border-radius: 6px; width: 24px; height: 22px; color: var(--ink); cursor: pointer; }
.todo-it { display: flex; align-items: center; gap: 7px; width: 100%; margin-top: 5px; padding: 6px 8px; border-radius: 10px; border: 1px solid transparent; background: rgba(255,255,255,.06); color: var(--ink); text-align: left; cursor: pointer; font-size: 12.5px; line-height: 1.3; }
.todo-it:hover { background: rgba(255,255,255,.14); border-color: var(--line); }
.todo-it.on { border-color: var(--gold); background: rgba(233,194,122,.18); }
.todo-it em { flex: 1; font-style: normal; }
.todo-it i { font-style: normal; color: var(--gold); }
.todo-empty { margin-top: 5px; color: var(--ink-soft); font-size: 12.5px; }
/* ---------- ẩn / hiện thanh công cụ ---------- */
#hud-show { display: none; position: absolute; right: 14px; bottom: 14px; width: 58px; height: 58px; border-radius: 20px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(12px); font-size: 22px; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--ink); }
#hud-show small { font-size: 10px; color: var(--ink-soft); }
body.hud-off #hud-show { display: flex; }
body.hud-off #hud .stats, body.hud-off #hud .menu, body.hud-off #hud .rcol, body.hud-off #hud #minimap,
body.hud-off #hud #hud-veh, body.hud-off #hud .top, body.hud-off #hud .pill:not(.rest), body.hud-off #labels { display: none !important; }
@media (max-width: 760px) { .rcol { width: 230px; top: 200px; } }

/* ---------- nút ẩn từng phần ---------- */
.hud-x { pointer-events: auto; width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: rgba(40,28,16,.85); color: var(--ink); font-size: 14px; line-height: 16px; cursor: pointer; opacity: .55; transition: opacity .15s; }
.hud-x:hover { opacity: 1; }
.stats .hud-x { position: absolute; top: -7px; left: -7px; }
.menu button.hud-x { width: 20px; height: 20px; border-radius: 50%; font-size: 14px; align-self: flex-start; display: block; }
.mm-wrap .hud-x { position: absolute; left: 146px; bottom: 198px; }
.todo-h .hud-x { margin-left: 6px; width: 22px; height: 22px; border-radius: 6px; opacity: .8; }
.todo-h b { flex: 1; }
body.hide-top #hud .pill.tl, body.hide-top #hud .pill.tr,
body.hide-stats #hud .stats, body.hide-tut #hud #tut, body.hide-todo #hud #todo,
body.hide-map #hud .mm-wrap, body.hide-menu #hud .menu, body.hide-labels #labels .lbl { display: none !important; }
body.hide-menu #hud-show { display: flex; }
body.hide-stats .rcol { top: 60px; }
/* ---------- bảng giải thích chỉ số ---------- */
.st-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.st-nav .mini.on { border-color: var(--gold); color: var(--gold); }
.st-what { margin: 4px 0 8px; }
.st-live { margin: 8px 0; }
.st-why { margin: 6px 0 0 18px; padding: 0; }
.st-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.st-cols h4 { margin: 0 0 4px; color: var(--gold); font-size: 14px; }
.st-cols ul { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.45; }
@media (max-width: 640px) { .st-cols { grid-template-columns: 1fr; } }

.bm-pick { position: absolute; display: none; z-index: 3; width: 180px; padding: 8px; border-radius: 12px; background: rgba(40,28,16,.94); border: 1px solid var(--gold); box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.bm-pick b { display: block; color: var(--gold); font-size: 13.5px; }
.bm-pick small { display: block; color: var(--ink-soft); margin: 2px 0 6px; font-size: 12px; }
.bm-pick button { display: block; width: 100%; margin-top: 4px; text-align: left; }
.bm-pick .bm-cancel { position: absolute; top: 4px; right: 4px; width: 22px; padding: 0; text-align: center; margin: 0; }

.vbtn { margin-left: 6px; padding: 2px 8px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255,255,255,.1); color: var(--ink); font-size: 12px; cursor: pointer; }
.vbtn:hover { background: rgba(255,255,255,.2); }
#hud-drunk { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); background: rgba(150,60,30,.85); cursor: pointer; }

/* ============================================================
   ĐIỆN THOẠI: bố cục riêng cho màn dọc và màn ngang
   ============================================================ */
/* ---------- màn dọc (điện thoại đứng) ---------- */
@media (max-width: 640px) {
  .tl { top: 8px; left: 8px; }
  .tr { top: 46px; left: 8px; right: auto; }
  .stats { top: 8px; right: 8px; width: 150px; padding: 6px 9px; gap: 3px; border-radius: 14px; }
  .stats .st { font-size: 11.5px; gap: 5px; }
  .stats small { min-width: 38px; font-size: 10.5px; }
  .stats .et { height: 6px; }
  .rcol { top: 84px; left: 8px; right: auto; width: min(250px, calc(100vw - 176px)); max-height: 34vh; }
  .rcol .tut { font-size: 12px; padding: 7px 9px; }
  .todo { font-size: 12px; padding: 6px 8px; }
  .todo-it { font-size: 11.5px; padding: 5px 6px; margin-top: 4px; }
  #minimap, body.touch #minimap { left: auto; right: 8px; top: 142px; bottom: auto; width: 86px; height: 86px; }
  .mm-wrap .hud-x { left: auto; right: 86px; top: 138px; bottom: auto; }
  #toasts { top: auto; bottom: 252px; left: 8px; width: calc(100vw - 16px); }
  .toast { font-size: 12.5px; padding: 7px 10px; }
  .menu, body.touch .menu { top: auto; bottom: 6px; left: 6px; right: 6px; flex-direction: row; overflow-x: auto; gap: 6px; justify-content: flex-start; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .menu::-webkit-scrollbar { display: none; }
  .menu button, body.touch .menu button, .menu button.wide { width: 44px; height: 44px; flex: none; border-radius: 14px; font-size: 18px; }
  .menu button small { display: none; }
  .menu button.hud-x { width: 22px; height: 22px; align-self: center; }
  body.touch #joy { left: 14px; bottom: 62px; width: 110px; height: 110px; }
  body.touch #btn-act { right: 16px; bottom: 66px; width: 68px; height: 68px; }
  #prompt, body.touch #prompt { bottom: 188px; font-size: 13.5px; max-width: calc(100vw - 20px); }
  .vehchip { bottom: 226px; flex-wrap: wrap; justify-content: center; white-space: normal; max-width: calc(100vw - 16px); text-align: center; }
  .rest { top: auto; bottom: 226px; max-width: calc(100vw - 16px); white-space: normal; }
  #hud-drunk { top: auto; bottom: 264px; }
  #progress { top: auto; bottom: 140px; width: calc(100vw - 16px); }
  #panel { top: auto !important; bottom: 0; left: 0; right: 0; width: 100%; max-height: 74vh; border-radius: 18px 18px 0 0; transform: translateY(30px); }
  #panel.open { transform: none; }
  #chat, body.touch #chat { left: 136px; bottom: 128px; width: auto; }
  #chat .emo { display: none; }
  #chat.typing { left: 8px; right: 8px; bottom: 252px; }
  #hud-show { right: 8px; bottom: 8px; width: 44px; height: 44px; }
  .bm-card { padding: 8px; max-height: 100vh; overflow-y: auto; }
  .bm-head { flex-wrap: wrap; gap: 6px; }
  .bm-head span { display: none; }
  .bm-head b { font-size: 18px; flex: 1; }
  .bm-z, .bm-x { width: 30px; height: 30px; }
  .bm-dests { max-height: 120px; }
  .bm-leg { display: none; }
  #story .story-card { padding: 18px 16px 14px; }
  .story-icon { font-size: 44px; }
  #story h2 { font-size: 23px; }
  #story p { font-size: 14px; }
  .title-card { padding: 22px 16px; }
}

/* ---------- màn ngang (điện thoại nằm ngang) ---------- */
@media (max-height: 500px) {
  .tl { top: 6px; left: 6px; font-size: 12px; padding: 6px 10px; gap: 7px; }
  .tl .brand, .tl .brand + .sep, .hide-sm { display: none; }
  .tr { top: 6px; right: 6px; left: auto; font-size: 12px; padding: 6px 10px; }
  .stats { top: 42px; right: 6px; width: 160px; padding: 5px 8px; gap: 2px; border-radius: 14px; }
  .stats .st { font-size: 11px; gap: 5px; }
  .stats small { min-width: 38px; font-size: 10.5px; }
  .stats .et { height: 6px; }
  #minimap, body.touch #minimap { left: auto; right: 6px; top: 146px; bottom: auto; width: 76px; height: 76px; }
  .mm-wrap .hud-x { left: auto; right: 74px; top: 142px; bottom: auto; }
  .rcol { top: 42px; left: 6px; right: auto; width: 230px; max-height: calc(100vh - 168px); }
  .rcol .tut { font-size: 12px; padding: 6px 9px; }
  .todo { font-size: 12px; padding: 6px 8px; }
  .todo-it { font-size: 11.5px; padding: 4px 6px; margin-top: 3px; }
  #toasts { top: 6px; left: 50%; transform: translateX(-50%); width: min(360px, calc(100vw - 440px)); min-width: 230px; }
  .toast { font-size: 12px; padding: 6px 10px; }
  .menu, body.touch .menu { top: auto; bottom: 6px; left: 122px; right: 88px; flex-direction: row; overflow-x: auto; gap: 5px; justify-content: flex-start; scrollbar-width: none; }
  .menu::-webkit-scrollbar { display: none; }
  .menu button, body.touch .menu button, .menu button.wide { width: 40px; height: 40px; flex: none; border-radius: 12px; font-size: 17px; }
  .menu button small { display: none; }
  .menu button.hud-x { width: 20px; height: 20px; align-self: center; }
  body.touch #joy { left: 10px; bottom: 10px; width: 100px; height: 100px; }
  body.touch #btn-act { right: 12px; bottom: 12px; width: 62px; height: 62px; }
  #prompt, body.touch #prompt { bottom: 54px; font-size: 13px; }
  .vehchip { bottom: 94px; }
  .rest { top: auto; bottom: 94px; }
  #hud-drunk { top: auto; bottom: 130px; }
  #progress { top: auto; bottom: 54px; width: min(360px, calc(100vw - 250px)); }
  #panel { top: 6px !important; bottom: 6px; right: 6px; left: auto; width: min(430px, 58vw); max-height: none; border-radius: 16px; }
  #panel-body { padding: 8px 12px 12px; }
  #chat, body.touch #chat { left: 118px; bottom: 54px; width: auto; }
  #chat .emo { display: none; }
  #chat.typing { left: 118px; right: 90px; }
  #hud-show { right: 80px; bottom: 6px; width: 40px; height: 40px; }
  .bm-card { padding: 8px; max-height: 100vh; overflow-y: auto; }
  .bm-head span { display: none; }
  .bm-head { margin-bottom: 4px; }
  .bm-dests { max-height: 70px; }
  .bm-leg { display: none; }
  #story .story-card { padding: 12px 18px 10px; max-height: calc(100vh - 20px); overflow-y: auto; }
  .story-icon { font-size: 34px; margin: 2px 0 0; }
  #story h2 { font-size: 21px; margin: 2px 0 6px; }
  #story p { font-size: 13.5px; line-height: 1.5; }
  .title-card { padding: 14px 18px; max-height: calc(100vh - 16px); overflow-y: auto; }
  .title-card h1 { font-size: 36px; margin: 4px 0 6px; }
  .overlay-side { top: 6px; bottom: 6px; left: 6px; padding: 12px 14px; }
}
