:root {
  --bg: #120a06;
  --panel: rgba(28, 16, 9, 0.82);
  --panel-solid: #1f130b;
  --line: rgba(232, 190, 110, 0.22);
  --text: #f6e7cf;
  --muted: #c9b08c;
  --gold: #e3b45a;
  --gold-strong: #f0c45c;
  --red: #8e1b16;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); overscroll-behavior: none; }
/* Không cho phóng to cả trang trên điện thoại (pinch, chạm đúp); chỉ cho cuộn ở các vùng có chữ dài */
html, body { touch-action: none; }
button { touch-action: pan-x pan-y; }
html, body, button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.lobby, .kinh-text, .modal, .modal-card, .actions { touch-action: pan-x pan-y; }
textarea, input { touch-action: pan-x pan-y; -webkit-user-select: text; user-select: text; }
body { font-family: 'Be Vietnam Pro', system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- Sảnh ---------- */
.lobby {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(18,10,6,0.35), rgba(18,10,6,0.85));
  overflow-y: auto;
}
.lobby-card {
  width: min(520px, 100%); padding: 28px 24px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}
.lotus { font-size: 44px; line-height: 1; }
h1 { font-family: 'Noto Serif', Georgia, serif; font-weight: 700; color: var(--gold-strong); margin: 10px 0 8px; font-size: clamp(26px, 6vw, 34px); letter-spacing: 0.5px; }
.sub { color: var(--muted); line-height: 1.6; margin: 0 0 20px; font-size: 15px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); font-weight: 600; margin: 0 0 10px; }
.rooms { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 20px; }
.room {
  padding: 8px 4px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,0.03);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 14px; font-weight: 600;
}
.room small { font-size: 11px; color: var(--muted); font-weight: 400; }
.room.on { border-color: var(--gold); background: rgba(227,180,90,0.16); }
.room.full { opacity: 0.4; cursor: not-allowed; }
.room .bar { width: 70%; height: 3px; border-radius: 2px; background: rgba(255,255,255,0.1); overflow: hidden; }
.room .bar i { display: block; height: 100%; background: var(--gold); }
.hint { color: var(--muted); font-size: 12px; margin: 14px 0 0; opacity: 0.8; }

.primary {
  border: 0; border-radius: 999px; padding: 14px 28px; font-weight: 700; font-size: 16px;
  background: linear-gradient(180deg, #f0c45c, #c8902e); color: #2a1606;
  box-shadow: 0 6px 20px rgba(227,180,90,0.25);
}
.primary:disabled { opacity: 0.5; cursor: default; }
.primary.small { padding: 9px 18px; font-size: 14px; }
.ghost { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 9px 16px; }
.ghost.small { font-size: 13px; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px; pointer-events: none;
  background: linear-gradient(180deg, rgba(18,10,6,0.7), transparent);
}
.hud > * { pointer-events: auto; }
.hall { font-family: 'Noto Serif', serif; font-weight: 700; color: var(--gold-strong); font-size: 17px; }
.meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.meta #me-name { color: var(--text); font-weight: 600; }
.hud-right { display: flex; gap: 8px; }
.icon {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); display: grid; place-items: center; font-size: 17px; padding: 0;
}
.icon.small { width: 32px; height: 32px; font-size: 14px; }

/* ---------- Thanh hành lễ ---------- */
.actions {
  position: fixed; left: 12px; right: 12px; margin: 0 auto; width: max-content; bottom: calc(14px + var(--safe-b));
  display: flex; gap: 6px; padding: 8px; max-width: calc(100% - 24px); overflow-x: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); scrollbar-width: none;
}
.actions::-webkit-scrollbar { display: none; }
.actions button {
  flex: 0 0 auto; min-width: 70px; border: 0; background: transparent; border-radius: 14px;
  padding: 8px 8px 6px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 12px; color: var(--muted); font-weight: 500; transition: background 0.15s, color 0.15s, transform 0.1s;
}
.actions button span { font-size: 22px; line-height: 1; }
.actions button:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.actions button:active { transform: scale(0.94); }
.actions button.accent { color: var(--gold-strong); }
.actions button.cooling { opacity: 0.45; }

/* ---------- Kinh ---------- */
.kinh {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(100px + var(--safe-b));
  width: min(560px, calc(100% - 24px)); max-height: min(52vh, 460px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}
.kinh-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 10px 6px 12px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: transparent; padding: 7px 12px; border-radius: 999px; color: var(--muted); font-size: 14px; font-weight: 500; }
.tabs button.on { background: rgba(227,180,90,0.16); color: var(--gold-strong); }
.kinh-text {
  overflow-y: auto; padding: 14px 18px; font-family: 'Noto Serif', serif; font-size: 18px; line-height: 1.85;
  color: rgba(246,231,207,0.62); scroll-behavior: smooth;
}
.kinh-text h3 { font-size: 15px; color: var(--gold); margin: 0 0 8px; font-weight: 700; text-align: center; }
.kinh-text p { margin: 0 0 2px; }
.kinh-text .w { border-radius: 4px; transition: color 0.15s, background 0.15s; padding: 0 1px; }
.kinh-text .w.done { color: var(--text); }
.kinh-text .w.now { color: #2a1606; background: var(--gold-strong); }
.kinh-foot { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tempo { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.tempo input { width: 100px; accent-color: var(--gold); }
.count { font-size: 13px; color: var(--gold-strong); font-weight: 600; }

/* ---------- Thông báo ---------- */
.toasts { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: calc(100% - 32px); }
.toast {
  background: var(--panel); border: 1px solid var(--line); padding: 7px 14px; border-radius: 999px; font-size: 13px;
  color: var(--text); animation: toast 3.2s ease forwards; max-width: 100%; text-align: center;
}
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.loading { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); color: var(--muted); font-size: 13px; }

@media (max-width: 520px) {
  .rooms { grid-template-columns: repeat(4, 1fr); }
  .lobby-card { padding: 22px 16px; }
  .actions { flex-wrap: wrap; justify-content: center; width: auto; gap: 2px; padding: 6px; }
  .actions button { flex: 1 0 23%; min-width: 0; font-size: 11px; padding: 6px 2px 5px; }
  .kinh { bottom: calc(150px + var(--safe-b)); max-height: 46vh; }
  .kinh-text { font-size: 16px; padding: 12px 14px; }
  .meta { font-size: 11.5px; }
}

/* ---------- Tính năng mới ---------- */
.linkish { border: 0; background: none; padding: 0; color: var(--text); font-weight: 600; text-decoration: underline dotted rgba(246,231,207,0.4); text-underline-offset: 3px; font-size: inherit; }
.meta.lunar { color: var(--gold); opacity: 0.9; }
.special {
  display: inline-block; margin-top: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: linear-gradient(90deg, rgba(227,180,90,0.25), rgba(209,48,30,0.25)); border: 1px solid rgba(240,196,92,0.5); color: var(--gold-strong);
}

.modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(8,4,2,0.55); z-index: 20; animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; } }
.modal-card {
  position: relative; width: min(440px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px 20px 20px; text-align: center;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.modal-card h3 { font-family: 'Noto Serif', serif; color: var(--gold-strong); margin: 0 0 8px; font-size: 22px; }
.modal-card .close { position: absolute; top: 12px; right: 12px; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 14px; }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

/* Ống xăm */
.ong-xam { position: relative; width: 120px; height: 190px; margin: 6px auto 18px; transform-origin: 50% 90%; }
.ong-xam.shaking { animation: shake 0.16s linear infinite; }
@keyframes shake { 0% { transform: rotate(-9deg); } 50% { transform: rotate(9deg) translateY(-3px); } 100% { transform: rotate(-9deg); } }
.ong-xam .tube {
  position: absolute; bottom: 0; left: 20px; width: 80px; height: 120px; border-radius: 10px 10px 14px 14px;
  background: linear-gradient(90deg, #6b1410, #a8261c 40%, #7d1712); border: 2px solid #d9a845; display: grid; place-items: center;
  box-shadow: inset 0 -8px 0 rgba(0,0,0,0.2);
}
.ong-xam .tube span { font-family: 'Noto Serif', serif; color: var(--gold-strong); font-size: 30px; }
.ong-xam .sticks { position: absolute; bottom: 90px; left: 26px; width: 68px; height: 90px; display: flex; justify-content: space-around; align-items: flex-end; }
.ong-xam .sticks i { display: block; width: 4px; border-radius: 2px 2px 0 0; background: linear-gradient(#c2271b 0 10%, #e8c88a 10%); }
.ong-xam .sticks i:nth-child(odd) { height: 80px; } .ong-xam .sticks i:nth-child(even) { height: 66px; } .ong-xam .sticks i:nth-child(3n) { height: 88px; }
.ong-xam .fallen { position: absolute; left: 50%; top: 0; width: 6px; height: 96px; border-radius: 3px; opacity: 0; background: linear-gradient(#c2271b 0 10%, #f0d39a 10%); }
.ong-xam .fallen.drop { animation: drop 0.9s cubic-bezier(.3,.6,.4,1) forwards; }
@keyframes drop { 0% { opacity: 1; transform: translate(-50%, 0) rotate(0); } 60% { transform: translate(60px, 120px) rotate(70deg); } 100% { opacity: 1; transform: translate(70px, 140px) rotate(88deg); } }
.xam-result { text-align: left; animation: fade 0.4s ease; }
.que-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 10px; }
.que-head span { color: var(--muted); font-size: 14px; }
.que-head b { font-family: 'Noto Serif', serif; color: var(--gold-strong); font-size: 18px; }
.que-head b.ha { color: #e7a07a; }
blockquote { margin: 0 0 12px; padding: 12px 14px; border-left: 3px solid var(--gold); background: rgba(227,180,90,0.08); border-radius: 0 10px 10px 0; font-family: 'Noto Serif', serif; font-size: 17px; line-height: 1.8; }
.xam-result p { font-size: 14.5px; line-height: 1.6; margin: 0 0 8px; }
.xam-result p b { color: var(--gold); }

/* Đèn hoa đăng */
textarea {
  width: 100%; resize: none; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--text);
  font: 16px/1.5 'Be Vietnam Pro', sans-serif; padding: 10px 12px; outline: none;
}
textarea:focus { border-color: var(--gold); }
.den-meta { text-align: right; font-size: 12px; color: var(--muted); margin: 4px 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 16px; }
.chips button { border: 1px solid var(--line); background: rgba(255,255,255,0.03); border-radius: 999px; padding: 6px 12px; font-size: 13px; color: var(--muted); }
.chips button:hover, .chips button.on { border-color: var(--gold); color: var(--gold-strong); background: rgba(227,180,90,0.12); }
.chips.big button { padding: 10px 16px; font-size: 15px; }
.wish-card { background: radial-gradient(circle at 50% 0, rgba(246,165,189,0.18), transparent 60%), var(--panel-solid); }
.wish-lotus { font-size: 40px; }
.wish-by { color: var(--muted); margin: 6px 0 4px; font-size: 14px; }
.wish-by b { color: var(--text); }
.wish-text { font-family: 'Noto Serif', serif; font-size: 20px; line-height: 1.6; margin: 0 0 8px; color: var(--gold-strong); }

/* Thiền */
body.meditating .hud, body.meditating .actions, body.meditating .kinh, body.meditating .toasts { opacity: 0; pointer-events: none; transition: opacity 1.5s; }
.hud, .actions { transition: opacity 0.6s; }
.thien-overlay { position: fixed; top: max(24px, env(safe-area-inset-top)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 5; }
.thien-overlay button { pointer-events: auto; margin-top: 6px; opacity: 0.6; }
.thien-time { font-family: 'Noto Serif', serif; font-size: 34px; color: rgba(246,231,207,0.75); letter-spacing: 2px; }
.thien-breath { font-size: 14px; color: var(--muted); transition: opacity 2s; }

/* Khoá lễ chung */
.le-banner { padding: 8px 14px; font-size: 13px; font-weight: 600; color: #2a1606; background: linear-gradient(90deg, #f0c45c, #c8902e); text-align: center; }

/* Sổ công đức */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255,255,255,0.03); }
.stat b { display: block; font-family: 'Noto Serif', serif; font-size: 26px; color: var(--gold-strong); }
.stat span { font-size: 12.5px; color: var(--muted); }

.actions button.accent span { filter: drop-shadow(0 0 6px rgba(240,196,92,0.45)); }
@media (min-width: 521px) { .actions button { min-width: 64px; } }
@media (max-width: 520px) {
  .actions button { flex-basis: 15%; }
  .kinh { bottom: calc(160px + var(--safe-b)); }
}
/* Chữ trên HUD không chặn việc chạm vào đèn hoa đăng phía sau */
.hud .hud-left { pointer-events: none; }
.hud .hud-left button { pointer-events: auto; }

/* ---------- Tụng chung ---------- */
.voice-bar { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.voice-people { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; align-items: center; }
.muted-s { font-size: 12.5px; color: var(--muted); }
.vp {
  --lv: 0; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border-radius: 999px; font-size: 12.5px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.04);
  box-shadow: 0 0 calc(var(--lv) * 14px) rgba(120,220,140, calc(var(--lv) * 0.9));
  border-color: rgba(120,220,140, calc(0.2 + var(--lv) * 0.8));
}
.vp i { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-size: 11px; background: rgba(120,220,140, calc(0.15 + var(--lv) * 0.85)); }
.vp.me { font-weight: 600; }
.vp.failed { opacity: 0.5; text-decoration: line-through; }
.voice-ctl { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet p { margin: 0; padding: 6px 10px; border-radius: 10px; cursor: pointer; transition: background 0.2s, color 0.2s; }
.sheet p:hover { background: rgba(255,255,255,0.04); }
.sheet p.past { color: rgba(246,231,207,0.4); }
.sheet p.now { color: #2a1606; background: var(--gold-strong); font-weight: 700; }
.sheet-foot { justify-content: space-between; }

/* Đi nhanh tới các khu */
.hud { position: fixed; }
.places {
  position: absolute; top: calc(max(12px, env(safe-area-inset-top)) + 46px); right: 16px; display: flex; flex-direction: column; gap: 2px;
  padding: 6px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}
.places button { border: 0; background: transparent; text-align: left; padding: 9px 14px; border-radius: 10px; font-size: 14px; }
.places button:hover { background: rgba(227,180,90,0.14); color: var(--gold-strong); }

/* Nút hoạt động theo khu vực (lầu chuông, hồ sen, nhà ăn) */
.ctx {
  position: fixed; left: 12px; right: 12px; margin: 0 auto; width: max-content; max-width: calc(100% - 24px);
  bottom: calc(96px + var(--safe-b)); display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center;
  padding: 8px 10px; border-radius: 999px; background: var(--panel); border: 1px solid rgba(240,196,92,0.45);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); animation: fade 0.25s ease;
}
.ctx .ctx-label { font-size: 12.5px; color: var(--muted); padding: 0 4px; }
.ctx button { border: 0; border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 14px; background: linear-gradient(180deg, #f0c45c, #c8902e); color: #2a1606; }
.ctx button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.ctx button:disabled { opacity: 0.5; }
.nguquan { text-align: left; margin: 0 0 16px; padding-left: 22px; line-height: 1.7; font-family: 'Noto Serif', serif; font-size: 15.5px; }
@media (max-width: 520px) { .ctx { bottom: calc(150px + var(--safe-b)); border-radius: 18px; } }

/* Pháp danh */
.name-field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 18px; text-align: left; }
.name-field > span:first-child { font-size: 13px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); font-weight: 600; text-align: center; }
.name-row { display: flex; gap: 8px; align-items: center; }
.name-row input {
  flex: 1; min-width: 0; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--text);
  font: 16px 'Be Vietnam Pro', sans-serif; padding: 10px 12px; outline: none;
}
.name-row input:focus { border-color: var(--gold); }
.name-error { min-height: 20px; margin: 8px 0 10px; font-size: 13px; color: #f0a07a; }
.pen { text-decoration: none; font-size: 12px; opacity: 0.8; }

/* Nói chuyện theo khoảng cách */
#btn-talk.on { background: rgba(90,200,120,0.25); border-color: rgba(120,220,140,0.8); }
.talk-bar {
  position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 92px); left: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 8px 6px 12px; border-radius: 999px; font-size: 12.5px; background: var(--panel); border: 1px solid rgba(120,220,140,0.5);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); max-width: calc(100% - 32px);
}
.talk-dot { width: 8px; height: 8px; border-radius: 50%; background: #6fdc8c; box-shadow: 0 0 8px #6fdc8c; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.talk-bar .ghost.small { padding: 5px 10px; font-size: 12px; }
body.meditating .talk-bar { opacity: 0.3; }

/* ---------- Đấu Mõ ---------- */
.actions button.duel-btn span { animation: duelWiggle 2.6s ease-in-out infinite; display: inline-block; }
@keyframes duelWiggle { 0%, 80%, 100% { transform: none; } 85% { transform: rotate(-14deg) scale(1.15); } 90% { transform: rotate(12deg) scale(1.15); } }

.duel-card { max-height: min(88vh, 760px); overflow-y: auto; }
.duel-card h4 { margin: 16px 0 8px; font-size: 13px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.duel-me { padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: linear-gradient(135deg, rgba(227,180,90,0.14), rgba(142,27,22,0.18)); text-align: left; }
.dm-rank { display: flex; gap: 12px; align-items: center; }
.dm-rank b { display: block; font-size: 17px; color: var(--gold-strong); }
.dm-rank small { color: var(--muted); font-size: 12px; }
.dm-icon { font-size: 34px; line-height: 1; filter: drop-shadow(0 4px 10px rgba(227,180,90,0.4)); }
.dm-bar { height: 6px; border-radius: 4px; background: rgba(255,255,255,0.08); margin: 10px 0; overflow: hidden; }
.dm-bar i { display: block; height: 100%; background: linear-gradient(90deg, #f0c45c, #ff8a3a); border-radius: 4px; }
.dm-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; text-align: center; }
.dm-stats span { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; }
.dm-stats b { font-size: 16px; color: var(--text); }
.dm-gift { margin: 10px 0 0; font-size: 13px; color: var(--gold-strong); }
.muted-s { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.duel-go { display: flex; gap: 8px; margin-top: 14px; }
.duel-go .primary { flex: 1.4; }
.duel-go .ghost { flex: 1; }
.duel-wait { margin-top: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--text); }
.duel-wait small { flex-basis: 100%; color: var(--gold-strong); }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--gold-strong); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.duel-people { display: flex; flex-direction: column; gap: 6px; max-height: 150px; overflow-y: auto; }
.dp { display: flex; justify-content: space-between; align-items: center; padding: 6px 6px 6px 12px; border-radius: 10px; background: rgba(255,255,255,0.04); font-size: 14px; }
.duel-tabs { margin: 16px 0 6px; }
.duel-top-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.duel-top-list li { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 10px; background: rgba(255,255,255,0.03); font-size: 14px; text-align: left; }
.duel-top-list li em { font-style: normal; text-align: center; color: var(--muted); }
.duel-top-list li b { color: var(--gold-strong); font-size: 13px; }
.duel-top-list li small { color: #ff9a4a; }

.duel-invite {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(76px + env(safe-area-inset-top, 0px)); z-index: 40;
  width: min(440px, calc(100% - 24px)); display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 16px;
  background: linear-gradient(135deg, #4a120c, #2a160b); border: 1px solid var(--gold); border-radius: 16px;
  box-shadow: 0 16px 50px rgba(0,0,0,0.5), 0 0 30px rgba(227,180,90,0.25); animation: inviteIn 0.35s cubic-bezier(.2,1.4,.4,1);
}
.duel-invite div { flex: 1; font-size: 14px; }
.duel-invite small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
@keyframes inviteIn { from { transform: translate(-50%, -20px) scale(0.9); opacity: 0; } }

.duel {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 50% 100%, rgba(120,40,10,0.55), rgba(10,5,3,0.94) 70%), rgba(10,5,3,0.9);
  padding: max(10px, env(safe-area-inset-top)) 12px calc(12px + var(--safe-b)); touch-action: none;
}
.duel-top { display: flex; align-items: center; gap: 10px; padding: 0 44px 0 0; }
.duel-side { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.duel-side b { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.duel-side span { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text); }
.duel-side.opp { text-align: right; }
.duel-side em { font-style: normal; font-size: 12px; color: #ff9a4a; font-weight: 700; min-height: 15px; }
.duel-vs { font-weight: 900; font-size: 15px; color: var(--gold-strong); letter-spacing: 1px; }
.duel-tug { height: 10px; border-radius: 6px; background: linear-gradient(90deg, #6aa8ff, #3a5aa8); margin: 6px 44px 4px 0; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08); }
.duel-tug i { display: block; height: 100%; width: 50%; background: linear-gradient(90deg, #ff8a3a, #f0c45c); transition: width 0.25s ease; box-shadow: 0 0 12px rgba(255,170,80,0.7); }
.duel-tug.lead i { background: linear-gradient(90deg, #ff6a2a, #ffd76a); }
#duel-canvas { flex: 1; width: 100%; min-height: 0; display: block; }
.duel-emotes { display: flex; justify-content: center; gap: 6px; margin: 4px 0 8px; }
.duel-emotes button { border: 1px solid var(--line); background: rgba(255,255,255,0.05); border-radius: 999px; width: 38px; height: 34px; font-size: 18px; padding: 0; }
.duel-emotes button:active { transform: scale(0.88); }
.duel-pads { display: flex; gap: 10px; align-items: stretch; width: min(560px, 100%); margin: 0 auto; }
.duel-pad {
  flex: 1; height: clamp(84px, 15vh, 120px); border-radius: 22px; border: 0; font-weight: 800; font-size: 15px; letter-spacing: 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; touch-action: none;
  box-shadow: 0 8px 0 rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.2); transition: transform 0.05s, box-shadow 0.05s;
}
.duel-pad span { font-size: 34px; line-height: 1; }
.duel-pad:active { transform: translateY(6px); box-shadow: 0 2px 0 rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.2); }
.duel-pad.mo { background: linear-gradient(180deg, #b0622a, #6a3214); color: #ffe2c0; }
.duel-pad.chuong { background: linear-gradient(180deg, #f0c45c, #a8761e); color: #2a1606; }
.duel-smoke {
  --p: 0%; width: 76px; border-radius: 18px; border: 1px solid var(--line); font-size: 11px; font-weight: 700; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; touch-action: none;
  background: linear-gradient(0deg, rgba(200,200,190,0.28) var(--p), rgba(255,255,255,0.04) var(--p));
}
.duel-smoke span { font-size: 24px; filter: grayscale(1); opacity: 0.6; }
.duel-smoke.ready { color: #fff; border-color: #e8e2da; animation: smokeReady 0.9s ease-in-out infinite; }
.duel-smoke.ready span { filter: none; opacity: 1; }
@keyframes smokeReady { 50% { box-shadow: 0 0 22px rgba(232,226,218,0.7); transform: scale(1.05); } }
.duel-quit { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px; }
.duel-emote { position: absolute; font-size: 54px; pointer-events: none; animation: emoteUp 1.8s ease-out forwards; }
.duel-emote.theirs { right: 18%; top: 18%; }
.duel-emote.mine { left: 18%; top: 30%; font-size: 40px; }
@keyframes emoteUp { 0% { transform: scale(0.3); opacity: 0; } 15% { transform: scale(1.25); opacity: 1; } 70% { opacity: 1; } 100% { transform: translateY(-80px) scale(1); opacity: 0; } }

.duel-result { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(10,5,3,0.72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); overflow-y: auto; }
.res-card { width: min(440px, 100%); padding: 22px 20px; border-radius: 22px; text-align: center; background: var(--panel-solid); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0,0,0,0.6); animation: inviteIn 0.4s cubic-bezier(.2,1.4,.4,1); }
.res-card.win { border-color: var(--gold); box-shadow: 0 30px 80px rgba(0,0,0,0.6), 0 0 60px rgba(240,196,92,0.25); }
.res-title { font-size: 30px; font-weight: 900; color: var(--gold-strong); letter-spacing: 1px; }
.res-card.lose .res-title { color: #ff9a8a; }
.res-line { color: var(--muted); margin: 6px 0 14px; font-size: 14px; }
.res-rankup { display: inline-block; padding: 6px 14px; border-radius: 999px; margin-bottom: 10px; font-weight: 800; color: #2a1606; background: linear-gradient(90deg, #ffd76a, #ff9a4a); animation: smokeReady 1s ease-in-out infinite; }
.res-scores { display: flex; align-items: center; justify-content: center; gap: 14px; }
.res-scores div { display: flex; flex-direction: column; min-width: 0; }
.res-scores b { font-size: 28px; font-variant-numeric: tabular-nums; }
.res-scores span { font-size: 12px; color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res-scores i { font-style: normal; color: var(--muted); }
.res-delta { margin: 10px 0; font-weight: 800; font-size: 18px; }
.res-delta.up { color: #7fe08a; }
.res-delta.down { color: #ff8a7a; }
.res-delta small { font-weight: 500; font-size: 12px; color: var(--muted); }
.res-stats { display: flex; justify-content: center; gap: 12px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.res-stats b { color: var(--text); }
.res-rank { text-align: left; padding: 12px; border-radius: 14px; background: rgba(255,255,255,0.04); }
.res-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.res-actions .pulse { animation: smokeReady 0.8s ease-in-out infinite; }
@media (max-width: 520px) {
  .dm-stats b { font-size: 14px; }
  .duel-side span { font-size: 22px; }
  .res-title { font-size: 26px; }
}
.duel-top-list li.muted-s { display: block; text-align: center; }

/* ---------- Chat ---------- */
.chat {
  position: fixed; left: 12px; bottom: calc(100px + var(--safe-b)); width: min(400px, calc(100% - 24px));
  display: flex; flex-direction: column; gap: 6px; pointer-events: none; z-index: 5;
}
.chat-log { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.chat-row {
  max-width: 100%; padding: 5px 11px; border-radius: 14px; font-size: 13px; line-height: 1.4; color: var(--text);
  background: rgba(20,11,6,0.62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: chatIn 0.25s ease; transition: opacity 1.5s; overflow-wrap: anywhere;
}
.chat-row b { color: var(--gold); font-weight: 600; }
.chat-row.me b { color: var(--gold-strong); }
.chat-row.old { opacity: 0.35; }
@keyframes chatIn { from { opacity: 0; transform: translateY(6px); } }
.chat-bar {
  pointer-events: auto; display: flex; gap: 6px; padding: 6px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.chat-bar input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 16px; padding: 6px 10px; outline: none;
}
.chat-bar input::placeholder { color: var(--muted); }
@media (max-width: 520px) {
  .chat { bottom: calc(160px + var(--safe-b)); }
  .chat-row { font-size: 12.5px; }
}

/* Hòm công đức */
.qr-card .qr-img { display: block; width: min(280px, 78vw); height: auto; margin: 4px auto 0; border-radius: 14px; background: #fff; }
.qr-save { display: inline-block; color: var(--text); text-decoration: none; }

/* Lộc chùa */
.qr-after { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.qr-after .muted { margin-bottom: 8px; }
.check { display: flex; gap: 8px; align-items: center; justify-content: center; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.check input { accent-color: var(--gold); width: 16px; height: 16px; }
.gift-bag { display: block; margin: 10px auto 6px; border: 0; background: none; padding: 0; position: relative; width: 150px; height: 180px; animation: sway 2.4s ease-in-out infinite; transform-origin: 50% 0; }
@keyframes sway { 50% { transform: rotate(4deg); } }
.gift-bag .bag {
  position: absolute; left: 10px; right: 10px; bottom: 0; height: 140px; border-radius: 26px 26px 40px 40px;
  background: radial-gradient(circle at 35% 30%, #d8372a, #8e1b16 70%); border: 3px solid #e8b44e; display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(200,40,20,0.35);
}
.gift-bag .bag b { font-family: 'Noto Serif', serif; font-size: 54px; color: #f6cf6a; text-shadow: 0 2px 0 rgba(0,0,0,0.25); }
.gift-bag .tie { position: absolute; left: 50%; top: 18px; width: 70px; height: 28px; margin-left: -35px; border-radius: 50%; border: 6px solid #e8b44e; }
.gift-bag.open { animation: open 0.7s ease forwards; }
@keyframes open { 30% { transform: scale(1.08) rotate(-6deg); } 100% { transform: scale(0.2) rotate(20deg); opacity: 0; } }
.gift-kind { color: var(--gold-strong); font-weight: 600; margin: 0 0 10px; }
.gift-canvas { width: min(300px, 70vw); height: auto; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.45); animation: fade 0.5s ease; }

/* Trang phục */
.lobby-look { display: block; margin: -8px auto 18px; }
.look-card { width: min(640px, 100%); text-align: left; }
.look-card h3 { text-align: center; }
.look-body { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.look-canvas { flex: 0 0 auto; width: 200px; height: 250px; border-radius: 16px; background: radial-gradient(circle at 50% 35%, #3a2616, #1a0f08); }
.look-opts { flex: 1; min-width: 0; }
.look-opts h4 { margin: 0 0 6px; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.look-opts .chips { justify-content: flex-start; margin-bottom: 12px; }
.outfits { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.outfit { display: flex; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.03); text-align: left; }
.outfit.on { border-color: var(--gold); background: rgba(227,180,90,0.12); }
.outfit i { flex: 0 0 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.25); }
.outfit b { display: block; font-size: 13px; }
.outfit small { display: block; font-size: 11px; color: var(--muted); line-height: 1.3; }
.look-card > .primary { display: block; margin: 0 auto; }
@media (max-width: 560px) {
  .look-body { flex-direction: column; align-items: center; }
  .look-canvas { width: 160px; height: 200px; }
  .outfits { grid-template-columns: 1fr; }
}

/* Cấp tu hành */
.lv-chip {
  pointer-events: auto; margin-top: 6px; display: grid; grid-template-columns: auto 90px; grid-template-rows: auto auto; column-gap: 8px; align-items: center;
  padding: 5px 10px; border-radius: 12px; border: 1px solid rgba(240,196,92,0.45); background: var(--panel); text-align: left;
}
.lv-chip b { font-size: 12.5px; color: var(--gold-strong); white-space: nowrap; }
.lv-chip small { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }
.lv-bar { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.1); overflow: hidden; }
.lv-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #c8902e, #f0c45c); transition: width 0.6s ease; }
.lv-chip.pop { animation: lvpop 0.6s ease; }
@keyframes lvpop { 40% { transform: scale(1.08); box-shadow: 0 0 18px rgba(240,196,92,0.6); } }
.tu-card { width: min(520px, 100%); text-align: left; }
.tu-card h3, .tu-card > .muted { text-align: center; }
.tu-card h4 { margin: 14px 0 8px; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.ranks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.rank { padding: 7px 8px; border-radius: 10px; border: 1px solid var(--line); font-size: 12.5px; opacity: 0.55; }
.rank small { display: block; color: var(--muted); font-size: 11px; }
.rank.done { opacity: 1; }
.rank.now { opacity: 1; border-color: var(--gold); background: rgba(227,180,90,0.14); }
.xp-rules { display: flex; flex-direction: column; gap: 5px; }
.xp-rule { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 13px; }
.xp-rule span { color: var(--muted); font-size: 12px; text-align: right; }
.xp-rule .lv-bar { grid-column: 1 / -1; height: 4px; }
.tu-khaile { margin: 6px 0 4px; padding: 10px 12px; border-radius: 12px; background: rgba(209,48,30,0.15); border: 1px solid rgba(240,196,92,0.5); text-align: center; font-size: 13.5px; }
.tu-khaile p { margin: 0 0 8px; }
.outfit.locked { opacity: 0.45; }
.outfit.locked small::after { content: ' 🔒'; }
@media (max-width: 520px) { .lv-chip { grid-template-columns: auto 60px; } .ranks { grid-template-columns: repeat(2, 1fr); } }
