:root {
  --ink: #2a2218;
  --paper: #f7efe0;
  --paper-dim: #e9dcc4;
  --gold: #d9a93f;
  --gold-soft: #f3d58b;
  --lacquer: #8c2418;
  --glass: rgba(34, 27, 19, 0.62);
  --glass-strong: rgba(28, 22, 15, 0.82);
  --line: rgba(243, 213, 139, 0.28);
  --ui: "Be Vietnam Pro", system-ui, sans-serif;
  --serif: "Noto Serif", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1d1810; color: var(--paper); font-family: var(--ui); -webkit-tap-highlight-color: transparent; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: rgba(247, 239, 224, 0.68); }

/* Màn hình chào */
#splash {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 30%, rgba(60, 44, 24, 0.55), rgba(18, 14, 9, 0.92));
  backdrop-filter: blur(3px);
}
.splash-card { width: min(640px, 100%); text-align: center; padding: 36px 28px 26px; border-radius: 22px; background: var(--glass-strong); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45); }
.splash-card h1 { font-family: var(--serif); font-size: clamp(44px, 11vw, 64px); margin: 6px 0 4px; color: var(--gold-soft); letter-spacing: 0.02em; }
.tagline { margin: 0 0 22px; font-size: 17px; color: var(--paper-dim); }
.splash-date { margin: 0; font-size: 13px; color: rgba(247, 239, 224, 0.7); }
.splash-special { display: inline-block; margin: 10px 0 0; padding: 5px 12px; border-radius: 99px; background: rgba(217, 169, 63, 0.18); color: var(--gold-soft); font-size: 13px; font-weight: 600; }
.identity { display: flex; gap: 8px; justify-content: center; align-items: baseline; flex-wrap: wrap; margin-bottom: 14px; }
.identity strong { font-family: var(--serif); font-size: 22px; color: var(--paper); }
/* Pháp danh chọn từng chữ từ danh sách, không có ô gõ chữ tự do. */
.name-pick { display: inline-flex; gap: 6px; align-items: center; }
.name-ho { font: 600 20px var(--serif); color: var(--paper); white-space: nowrap; }
.name-pick input { width: 9.5em; min-width: 0; padding: 3px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07); color: var(--paper); font: 600 20px var(--serif); }
.name-pick input:hover, .name-pick input:focus-visible { border-color: var(--gold); outline: none; }
.name-note { margin: -6px 0 12px; font-size: 12px; line-height: 1.5; color: #f0b27a; }
.link { background: none; border: 0; color: var(--gold-soft); text-decoration: underline; text-underline-offset: 3px; padding: 4px; font-size: 14px; }
.robes { display: flex; gap: 10px; justify-content: center; margin-bottom: 22px; }
.robes button { display: flex; align-items: center; gap: 8px; white-space: nowrap; padding: 7px 14px 7px 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.06); border: 1px solid transparent; font-size: 14px; }
.robes button[aria-checked="true"] { border-color: var(--gold); background: rgba(217, 169, 63, 0.14); }
.robes i { width: 20px; height: 20px; border-radius: 50%; display: block; box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.3); }
#splash { overflow-y: auto; align-items: safe center; }

/* Chọn nhân vật: khung xem trước 3D bên trái, lựa chọn bên phải */
.avatar { display: grid; grid-template-columns: 210px 1fr; gap: 18px; align-items: center; text-align: left; margin-bottom: 20px; }
.avatar-preview { width: 100%; height: 260px; display: block; border-radius: 18px; cursor: grab; touch-action: none; background: radial-gradient(ellipse at 50% 70%, rgba(217, 169, 63, 0.22), rgba(255, 255, 255, 0.03) 70%); border: 1px solid var(--line); }
.avatar-preview:active { cursor: grabbing; }
.avatar .identity { justify-content: flex-start; margin-bottom: 12px; }
.opt { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.opt:last-child { margin-bottom: 0; }
.opt-label { font-size: 12px; letter-spacing: 0.04em; color: rgba(247, 239, 224, 0.6); }
.avatar .robes { justify-content: flex-start; flex-wrap: wrap; gap: 6px; margin-bottom: 0; }
.robes button[role="switch"] { padding-left: 14px; }
.primary { width: 100%; padding: 14px 18px; border-radius: 14px; border: 0; background: linear-gradient(180deg, #e6b54e, #b7832a); color: #2a1c08; font-weight: 600; font-size: 17px; box-shadow: 0 8px 24px rgba(183, 131, 42, 0.35); }
.primary:disabled { opacity: 0.6; cursor: progress; }
.ghost { padding: 12px 18px; border-radius: 14px; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); }
.fineprint { margin: 18px 0 0; font-size: 12px; line-height: 1.6; color: rgba(247, 239, 224, 0.55); }

/* Thanh trên */
#hud-top { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; gap: 8px; justify-content: space-between; align-items: center; padding: max(12px, env(safe-area-inset-top)) 16px 0; pointer-events: none; }
#hud-top > * { pointer-events: auto; }
.chip { padding: 8px 14px; border-radius: 99px; background: var(--glass); backdrop-filter: blur(8px); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.chip.date { text-align: center; }
.chip-group { display: flex; gap: 8px; align-items: center; }
.merit strong { color: var(--gold-soft); font-variant-numeric: tabular-nums; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--glass); backdrop-filter: blur(8px); border: 1px solid var(--line); font-weight: 600; }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.icon-btn.off { opacity: 0.5; }
.panel { position: fixed; z-index: 12; top: 60px; right: 16px; width: min(340px, calc(100vw - 32px)); padding: 16px 18px; border-radius: 16px; background: var(--glass-strong); border: 1px solid var(--line); backdrop-filter: blur(10px); font-size: 14px; line-height: 1.55; }
.panel label { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.panel h3 { margin: 0 0 8px; font-family: var(--serif); color: var(--gold-soft); }
.panel ul { margin: 0; padding-left: 18px; }
.panel li { margin-bottom: 6px; }
.presence { position: fixed; z-index: 9; top: 58px; left: 16px; font-size: 12px; color: rgba(247, 239, 224, 0.75); text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6); }

/* Thanh hành động */
#actions { position: fixed; z-index: 10; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 6px; padding: 6px; border-radius: 22px; background: var(--glass); backdrop-filter: blur(10px); border: 1px solid var(--line); max-width: calc(100vw - 32px); }
#actions button { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 72px; padding: 9px 10px 7px; border-radius: 16px; background: transparent; border: 0; font-size: 12px; font-weight: 500; }
#actions button:hover, #actions button.on { background: rgba(217, 169, 63, 0.18); }
#actions button.on span { color: var(--gold-soft); }
#actions svg, #context-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--gold-soft); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#context-btn { position: fixed; z-index: 10; left: 50%; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 84px); transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 11px 20px; border-radius: 99px; border: 1px solid var(--gold); background: rgba(70, 44, 14, 0.82); backdrop-filter: blur(8px); font-weight: 600; font-size: 15px; color: var(--gold-soft); animation: rise 0.35s ease; }
#context-btn kbd { font: 600 11px var(--ui); padding: 2px 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.12); color: var(--paper); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* Thông báo và chữ nổi */
#toasts { position: fixed; z-index: 11; top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 520px); }
.toast { padding: 9px 16px; border-radius: 12px; background: var(--glass-strong); border: 1px solid var(--line); font-size: 14px; text-align: center; animation: toast 4.2s ease forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 8%, 82% { opacity: 1; transform: none; } 100% { opacity: 0; } }
#floats { position: fixed; inset: 0; z-index: 8; pointer-events: none; overflow: hidden; }
.float { position: absolute; transform: translate(-50%, -100%); font-weight: 600; font-size: 15px; color: var(--gold-soft); text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); white-space: nowrap; animation: floatUp 1.6s ease-out forwards; }
.float.small { font-size: 12px; font-weight: 500; color: var(--paper); }
.float.wish { font-family: var(--serif); font-weight: 500; font-size: 16px; color: var(--paper); max-width: 70vw; white-space: normal; text-align: center; animation-duration: 6s; }
@keyframes floatUp { from { opacity: 0; margin-top: 0; } 15% { opacity: 1; } to { opacity: 0; margin-top: -70px; } }

/* Hộp thoại */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(12, 9, 5, 0.5); backdrop-filter: blur(2px); }
.modal-card { width: min(420px, 100%); padding: 24px; border-radius: 20px; background: var(--glass-strong); border: 1px solid var(--line); }
.modal-card h2 { margin: 0 0 6px; font-family: var(--serif); color: var(--gold-soft); }
.modal-card p { margin: 0 0 14px; font-size: 14px; }
.modal-card textarea { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--paper); font: 15px var(--ui); resize: none; }
.sticks { display: flex; gap: 16px; margin-bottom: 12px; font-size: 15px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .primary { flex: 1; }

/* Chuỗi hạt */
.beads { position: fixed; inset: 0; z-index: 15; display: flex; flex-direction: column; align-items: center; background: radial-gradient(ellipse at 50% 45%, rgba(40, 28, 14, 0.78), rgba(10, 8, 5, 0.94)); backdrop-filter: blur(6px); }
.beads canvas { flex: 1; width: 100%; min-height: 0; cursor: pointer; touch-action: none; }
.beads-head { padding: max(20px, env(safe-area-inset-top)) 16px 0; text-align: center; }
.beads-count { font-family: var(--serif); font-size: 40px; color: var(--gold-soft); font-variant-numeric: tabular-nums; }
.mantra { margin: 0; font-family: var(--serif); font-size: 20px; color: var(--paper); opacity: 0.85; }
.mantra.pulse { animation: mantra 0.9s ease; }
@keyframes mantra { from { opacity: 0.2; transform: scale(0.97); } to { opacity: 0.85; transform: none; } }
.beads-hint { margin: 8px 0 0; font-size: 13px; color: rgba(247, 239, 224, 0.55); text-align: center; padding: 0 16px; }
.beads-close { margin: 14px 0 max(18px, env(safe-area-inset-bottom)); min-width: 140px; }

/* Phòng, người cùng ở đây, cài đặt: các bảng trượt bên phải (trên điện thoại là bảng dưới đáy) */
.chip-btn { display: inline-flex; align-items: center; gap: 8px; color: var(--paper); }
.chip-btn .count { color: rgba(247, 239, 224, 0.7); font-variant-numeric: tabular-nums; }
.chip-btn svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.chip-btn:hover, .icon-btn:hover { border-color: var(--gold); }
.sheet { max-height: calc(100vh - 140px); overflow-y: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sheet-head h3 { margin: 0; }
.close { width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.08); font-size: 20px; line-height: 1; }
.sheet-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 10px 0; }
.small { font-size: 12px; }
.ghost.small { padding: 6px 12px; border-radius: 10px; font-size: 13px; }
.room-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.room-list button { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); border: 1px solid transparent; font-size: 14px; }
.room-list button[aria-current="true"] { border-color: var(--gold); background: rgba(217, 169, 63, 0.16); }
.room-list button:disabled { opacity: 0.45; cursor: not-allowed; }
.room-list .n { font-variant-numeric: tabular-nums; color: rgba(247, 239, 224, 0.7); font-size: 12px; }
.people { list-style: none; margin: 8px 0; padding: 0; max-height: 46vh; overflow-y: auto; }
.people li { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid rgba(243, 213, 139, 0.1); }
.people li i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.people li em { margin-left: auto; font-style: normal; font-size: 12px; color: rgba(247, 239, 224, 0.6); }
.set { padding: 12px 0; border-bottom: 1px solid rgba(243, 213, 139, 0.12); display: grid; gap: 8px; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.set-row small, .set > small { display: block; font-size: 12px; color: rgba(247, 239, 224, 0.62); }
.set input[type="range"] { width: 100%; accent-color: var(--gold); }
.switch { position: relative; width: 44px; height: 26px; flex: none; padding: 0 !important; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: rgba(255, 255, 255, 0.16); transition: background 0.2s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--paper); transition: transform 0.2s; }
.switch input:checked + span { background: var(--gold); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--gold-soft); outline-offset: 2px; }
.credits { margin: 12px 0 0; font-size: 11px; line-height: 1.6; color: rgba(247, 239, 224, 0.5); }

/* Nút nghe niệm Phật và băng báo khóa lễ */
.pill { padding: 8px 16px; border-radius: 99px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(8px); font-size: 13px; font-weight: 500; }
.pill.on { border-color: var(--gold); color: var(--gold-soft); background: rgba(70, 44, 14, 0.8); }
.pill.small { padding: 5px 12px; font-size: 12px; }
#chant-btn { position: fixed; z-index: 10; top: calc(max(12px, env(safe-area-inset-top)) + 46px); right: 16px; }
.service-banner { position: fixed; z-index: 10; top: calc(max(12px, env(safe-area-inset-top)) + 46px); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 16px; border-radius: 99px; background: rgba(70, 44, 14, 0.85); border: 1px solid var(--gold); color: var(--gold-soft); font-size: 13px; white-space: nowrap; }

/* Màn gõ mõ */
.mo-screen { position: fixed; inset: 0; z-index: 15; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: radial-gradient(ellipse at 50% 50%, rgba(40, 28, 14, 0.7), rgba(10, 8, 5, 0.92)); backdrop-filter: blur(8px); }
.mo-count { text-align: center; }
.mo-count strong { display: block; font-family: var(--serif); font-size: 40px; color: var(--gold-soft); font-variant-numeric: tabular-nums; }
.mo-count span { font-size: 13px; color: rgba(247, 239, 224, 0.6); }
.mo-hit { position: relative; width: min(64vw, 360px); aspect-ratio: 1; border: 0; padding: 0; background: none; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.mo-hit img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.5)); pointer-events: none; }
.mo-hit.knock img { animation: knock 0.22s ease-out; }
@keyframes knock { 30% { transform: scale(0.94) rotate(-2deg); } }
.mo-plus { position: absolute; transform: translate(-50%, -100%); font-weight: 600; color: var(--gold-soft); text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); white-space: nowrap; pointer-events: none; animation: floatUp 1s ease-out forwards; }
.mo-tools { display: flex; gap: 10px; margin-bottom: max(18px, env(safe-area-inset-bottom)); }
.mo-tools [aria-pressed="true"] { border-color: var(--gold); color: var(--gold-soft); }
.modal-card.center { text-align: center; }
.modal-card.center .primary { margin-top: 6px; }

@media (max-width: 640px) {
  .sheet { top: auto; bottom: 0; right: 0; left: 0; width: 100%; max-height: 72vh; border-radius: 18px 18px 0 0; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  #chant-btn { top: auto; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 84px); right: 12px; }
  .service-banner { top: 100px; font-size: 12px; max-width: calc(100vw - 24px); white-space: normal; }
  .chip-btn { padding: 8px 10px; }
  .robes { gap: 6px; }
  .robes button { padding: 6px 10px 6px 6px; font-size: 13px; gap: 6px; }
  .splash-card { padding: 22px 16px 20px; }
  .splash-card h1 { font-size: 40px; margin: 2px 0; }
  .tagline { margin-bottom: 14px; font-size: 15px; }
  .avatar { grid-template-columns: 1fr; gap: 12px; text-align: center; }
  .avatar-preview { height: 190px; }
  .avatar .identity, .avatar .robes { justify-content: center; }
  .opt { margin-bottom: 8px; }
  #hud-top { padding-left: 12px; padding-right: 12px; flex-wrap: wrap; }
  .chip.date { order: 3; width: 100%; font-size: 12px; }
  [data-me] { font-size: 12px; }
  .merit span { display: none; }
  #actions button { min-width: 0; flex: 1; padding: 8px 4px 6px; font-size: 11px; }
  #actions { width: calc(100vw - 32px); }
  .presence { top: 98px; }
  #toasts { top: 120px; }
}

.has-banner #toasts { top: 104px; }
@media (max-width: 640px) { .has-banner #toasts { top: 150px; } }

/* Chế độ phát trực tiếp (src/live.js). --fx, --fw, --fh, --fu: vị trí, cỡ khung vẽ và 1% cạnh ngắn của khung. */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { padding: 8px 0; border-radius: 10px; background: rgba(255, 255, 255, 0.06); border: 1px solid transparent; font-size: 13px; }
.seg button[aria-checked="true"] { border-color: var(--gold); background: rgba(217, 169, 63, 0.16); color: var(--gold-soft); }
.set kbd { font: 600 11px var(--ui); padding: 1px 6px; margin-left: 4px; border-radius: 6px; background: rgba(255, 255, 255, 0.12); }
.set code { font-size: 11px; word-break: break-all; color: var(--gold-soft); }
body.live-clean #hud-top, body.live-clean #actions, body.live-clean #chant-btn, body.live-clean #context-btn,
body.live-clean #service-banner, body.live-clean #toasts, body.live-clean .panel { display: none !important; }
body.live-portrait { background: #000; }
#live-fade { position: fixed; z-index: 4; top: 0; left: var(--fx, 0px); width: var(--fw, 100vw); height: var(--fh, 100vh); background: #000; opacity: 0; pointer-events: none; }
#live-hint { position: fixed; z-index: 20; top: 12px; right: 12px; }
#live-overlay {
  position: fixed; z-index: 6; top: calc(var(--fu) * 3); left: calc(var(--fx) + var(--fu) * 3); max-width: calc(var(--fw) - var(--fu) * 6);
  display: grid; gap: calc(var(--fu) * 0.5); padding: calc(var(--fu) * 1.6) calc(var(--fu) * 2.4); border-radius: calc(var(--fu) * 1.8);
  background: rgba(24, 17, 10, 0.6); border: 1px solid rgba(243, 213, 139, 0.3); backdrop-filter: blur(6px);
  font-size: calc(var(--fu) * 2.6); line-height: 1.3; pointer-events: none; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
#live-overlay .lo-title { font-family: var(--serif); font-size: 1.45em; color: var(--gold-soft); }
#live-overlay .lo-date { font-family: var(--ui); font-size: 0.6em; color: rgba(247, 239, 224, 0.78); margin-left: 0.4em; }
#live-overlay .lo-join { color: rgba(247, 239, 224, 0.82); font-size: 0.9em; }
#live-overlay .lo-service { color: var(--gold-soft); font-weight: 600; }
#live-overlay .lo-service:empty { display: none; }
/* Khung dọc: đặt giữa, dưới dải tên kênh của TikTok (khoảng 13% phía trên). */
body.live-tall #live-overlay { left: calc(var(--fx) + var(--fw) / 2); transform: translateX(-50%); top: calc(var(--fh) * 0.13); text-align: center; font-size: calc(var(--fu) * 3.4); width: max-content; }
