/* Chánh điện 3D – bố cục: trái (thông tin) · giữa (3D) · phải (hành lễ) · dưới (điều khiển) */
body.page-temple { height: 100vh; height: 100dvh; overflow: hidden; }
body.page-temple .sitefooter { display: none; }
.temple-app { flex: 1; min-height: 0; display: grid; grid-template-columns: 230px 1fr 140px; grid-template-rows: 1fr auto; grid-template-areas: "left stage right" "bottom bottom bottom"; }
.side { background: linear-gradient(90deg, rgba(43,26,16,.97), rgba(59,36,22,.95)); padding: 12px; overflow-y: auto; }
.side-left { grid-area: left; border-right: 1px solid rgba(201,161,74,.35); }
.side-right { grid-area: right; border-left: 1px solid rgba(201,161,74,.35); display: flex; flex-direction: column; gap: 8px; }
.side h3 { font-size: 1rem; margin: 14px 0 6px; }
.avatar-card { display: flex; gap: 10px; align-items: center; padding: 8px; border: 1px solid rgba(201,161,74,.4); border-radius: 12px; background: rgba(30,18,11,.6); }
.avatar-card img { border-radius: 50%; border: 2px solid var(--gold); }
.avatar-card small { display: block; color: var(--muted); font-size: .78rem; }
.today, .tasks { list-style: none; padding: 0; margin: 0; }
.today li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed rgba(201,161,74,.2); font-size: .92rem; }
.today b { color: var(--gold-light); }
.tasks li label { margin: 4px 0; font-weight: 400; font-size: .9rem; display: flex; align-items: flex-start; }
.act { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; border-radius: 12px; border: 1px solid rgba(201,161,74,.5); background: rgba(30,18,11,.75); color: var(--cream); font: inherit; font-size: .88rem; cursor: pointer; }
.act span { font-size: 1.5rem; } .act:hover:not(:disabled) { background: rgba(201,161,74,.2); }
.act.primary { background: linear-gradient(#e2bb62, #b8892f); color: #2b1a10; font-weight: 700; }
.act:disabled { opacity: .45; cursor: not-allowed; }
.side-right.flash .act:not(:disabled) { animation: glow 1.2s ease; }
@keyframes glow { 50% { box-shadow: 0 0 0 3px var(--gold-light); } }

.stage { grid-area: stage; position: relative; min-height: 0; overflow: hidden; background: #120a06; }
#scene { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scene:active { cursor: grabbing; }
.zone-label { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); padding: 4px 14px; border-radius: 999px; background: rgba(30,18,11,.7); border: 1px solid var(--gold); color: var(--gold-light); font-family: var(--serif); font-size: .95rem; pointer-events: none; }
.interact-prompt { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); padding: 8px 18px; border-radius: 999px; background: rgba(201,161,74,.92); color: #2b1a10; font-weight: 700; cursor: pointer; box-shadow: var(--shadow); }
.joystick { display: none; position: absolute; left: 22px; bottom: 22px; width: 120px; height: 120px; border-radius: 50%; background: rgba(30,18,11,.35); border: 2px solid rgba(201,161,74,.6); touch-action: none; }
.joystick .knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(232,193,105,.8); }
body.is-touch .joystick { display: block; }

.loading, .fallback2d { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: radial-gradient(circle, #3b2416, #120a06); text-align: center; padding: 20px; z-index: 5; }
.fallback2d { z-index: 1; } .fallback2d p { max-width: 520px; }
.loading img { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.08); opacity: .8; } }
.progress { width: min(320px, 80%); height: 8px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--lotus), var(--gold-light)); transition: width .3s; }

.worship-hud { position: absolute; top: 50px; left: 50%; transform: translateX(-50%); text-align: center; padding: 12px 24px; border-radius: 16px; background: rgba(30,18,11,.72); border: 1px solid var(--gold); }
.worship-count { font-family: var(--serif); font-size: 2.6rem; color: var(--gold-light); line-height: 1; }
.worship-step { color: var(--cream); margin: 4px 0 8px; min-height: 1.4em; }
.btn.small { padding: 4px 12px; font-size: .85rem; }

.chant-hud { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(560px, calc(100% - 24px)); text-align: center; padding: 14px 18px; border-radius: 18px; background: rgba(30,18,11,.78); border: 1px solid var(--gold); box-shadow: var(--shadow); }
.chant-text { font-family: var(--serif); font-size: clamp(1.4rem, 4vw, 2.1rem); letter-spacing: .08em; color: var(--gold-light); text-shadow: 0 0 18px rgba(232,193,105,.5); }
.chant-count { font-size: 1.1rem; margin: 4px 0 8px; } .chant-count span:first-child { font-size: 2rem; font-weight: 700; color: var(--cream); display: inline-block; }
.chant-count .pulse { animation: pulse .35s ease; }
@keyframes pulse { 40% { transform: scale(1.25); color: var(--gold-light); } }
.chant-hud .progress { width: 100%; margin: 0 auto; }
.chant-meta { display: flex; justify-content: space-between; font-size: .88rem; color: var(--muted); margin: 6px 0 10px; }
.chant-buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn.big { padding: 14px 28px; font-size: 1.1rem; }
.chant-hud.paused .chant-text { opacity: .5; }
body.is-chanting .side-right, body.is-chanting .zone-label { opacity: .25; pointer-events: none; }

.bottombar { grid-area: bottom; display: flex; align-items: center; gap: 12px; padding: 6px 12px; background: linear-gradient(#2b1a10, #1e120b); border-top: 1px solid var(--gold); }
.hint { flex: 1; font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.is-touch .hint { display: none; }
.mini-chant { display: flex; align-items: center; gap: 8px; font-size: .82rem; min-width: 220px; }
.mini-chant .progress { width: 110px; }
.tools { display: flex; gap: 6px; margin-left: auto; }
.tool { width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(201,161,74,.55); background: rgba(30,18,11,.8); color: var(--gold-light); font-size: 1.05rem; cursor: pointer; }
.tool:hover { background: rgba(201,161,74,.2); }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(10,6,3,.62); padding: 16px; }
.modal-card { width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; background: linear-gradient(#3b2416, #2b1a10); border: 1px solid var(--gold); border-radius: 18px; padding: 18px 22px; box-shadow: var(--shadow); }
.modal-card.center { text-align: center; }
.modal-card h2 { margin-top: 4px; }
.creator-card { width: min(860px, 100%); }
.creator-grid { display: grid; grid-template-columns: 300px 1fr; gap: 18px; align-items: start; }
#creatorPreview { width: 100%; max-width: 300px; aspect-ratio: 4/5; height: auto; border-radius: 14px; background: radial-gradient(circle at 50% 40%, #5a3820, #1e120b); border: 1px solid rgba(201,161,74,.5); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { margin: 0; cursor: pointer; } .chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid rgba(201,161,74,.5); background: rgba(30,18,11,.6); font-weight: 500; font-size: .9rem; }
.chip input:checked + span { background: linear-gradient(#e2bb62, #b8892f); color: #2b1a10; border-color: var(--gold-light); }
.chip input:focus-visible + span { outline: 2px solid var(--gold-light); }
.chip-input { width: 110px; margin: 0; padding: 6px 10px; }
.radio { font-weight: 400; display: flex; gap: 4px; align-items: baseline; flex-wrap: wrap; } .radio.disabled { opacity: .55; }
.chant-preview { text-align: center; font-family: var(--serif); color: var(--gold-light); font-size: 1.4rem; letter-spacing: .08em; }
.dedication { font-family: var(--serif); font-style: italic; color: var(--lotus); font-size: 1.1rem; }
.menu-buttons { display: grid; gap: 8px; margin: 12px 0; }
.help { font-size: .9rem; }
.map-svg { width: 100%; height: auto; background: #1e120b; border-radius: 12px; border: 1px solid rgba(201,161,74,.4); }
.map-svg text { font-size: 2px; fill: var(--cream); text-anchor: middle; } .map-svg text.muted { fill: var(--muted); }
.map-ground { fill: #4a4238; } .map-hall { fill: #8b1e14; stroke: var(--gold); stroke-width: .3; } .map-hall.alt { fill: #5a3a20; }
.map-dot { fill: #7a5a2a; } .map-me { fill: var(--gold-light); stroke: #fff; stroke-width: .3; }
.map-lake { fill: #3f8c8a; stroke: #b3aa98; stroke-width: .4; }

.panel { position: fixed; top: 64px; right: 12px; bottom: 60px; width: min(440px, calc(100% - 24px)); z-index: 40; }
.panel-card { height: 100%; overflow-y: auto; background: linear-gradient(#3b2416, #2b1a10); border: 1px solid var(--gold); border-radius: 18px; padding: 14px 18px; box-shadow: var(--shadow); }
.panel-card header { display: flex; justify-content: space-between; align-items: center; }
.panel-card h2 { margin: 0; }
.tabs { display: flex; gap: 6px; margin: 10px 0; }
.tabs button { flex: 1; padding: 8px; border-radius: 10px; border: 1px solid rgba(201,161,74,.5); background: rgba(30,18,11,.6); color: var(--cream); font: inherit; cursor: pointer; }
.tabs button.is-active { background: rgba(201,161,74,.3); color: var(--gold-light); }
.mem-list { display: grid; gap: 8px; }
.mem-card { display: flex; gap: 10px; align-items: center; text-align: left; padding: 8px; border-radius: 12px; border: 1px solid rgba(201,161,74,.4); background: rgba(30,18,11,.6); color: var(--cream); font: inherit; cursor: pointer; }
.mem-card:hover { background: rgba(201,161,74,.15); }
.mem-info { display: flex; flex-direction: column; } .mem-info small { color: var(--muted); }
.mem-photo { width: 56px; height: 70px; flex: none; display: grid; place-items: center; font-size: 1.6rem; border: 2px solid var(--gold); border-radius: 6px; overflow: hidden; background: #2b1a10; }
.mem-photo img { width: 100%; height: 100%; object-fit: cover; }
.mem-photo.big { width: 110px; height: 140px; font-size: 3rem; }
.mem-head { display: flex; gap: 14px; } .mem-head h3 { margin: 0 0 4px; } .mem-head p { margin: 2px 0; }
.epitaph { font-style: italic; color: var(--cream); }
.mem-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.tribute-form { background: rgba(30,18,11,.5); padding: 8px 12px; border-radius: 12px; border: 1px solid rgba(201,161,74,.3); }
.check { font-weight: 400; display: flex; gap: 6px; align-items: flex-start; }
.tributes { display: grid; gap: 8px; }
.tribute { padding: 8px 12px; border-radius: 10px; background: rgba(30,18,11,.55); border-left: 3px solid var(--gold); }
.tribute.letter { border-left-color: var(--lotus); }
.tribute header { font-size: .82rem; color: var(--muted); } .tribute p { margin: 4px 0 0; }
.photo-preview img { max-width: 140px; max-height: 180px; border-radius: 8px; border: 2px solid var(--gold); }

.toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(460px, calc(100% - 24px)); pointer-events: none; }
.toast { padding: 10px 14px; border-radius: 12px; background: rgba(30,18,11,.95); border: 1px solid var(--gold); box-shadow: var(--shadow); transition: opacity .4s, transform .4s; }
.toast.out { opacity: 0; transform: translateY(-8px); }
.toast-ok { border-color: var(--ok); } .toast-warn { border-color: var(--warn); } .toast-error { border-color: var(--err); }

/* ---------- Điện thoại / máy tính bảng ---------- */
@media (max-width: 1000px) { .temple-app { grid-template-columns: 190px 1fr 118px; } .mini-chant { min-width: 0; } .hint { display: none; } }
@media (max-width: 760px) {
  .temple-app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; grid-template-areas: "stage" "bottom"; }
  .side-left { display: none; }
  .side-right { position: absolute; right: 8px; top: 120px; bottom: auto; z-index: 6; background: none; border: 0; padding: 0; width: 64px; overflow: visible; }
  .side-right .act { padding: 6px 2px; font-size: .62rem; background: rgba(30,18,11,.72); }
  .side-right .act span { font-size: 1.2rem; }
  .side-right .act[disabled] { display: none; }
  .stage { grid-row: 1; } .temple-app > .side-right { grid-area: stage; align-self: start; justify-self: end; margin-top: 46px; position: relative; top: 0; }
  .mini-chant { display: none; } body.is-chanting .mini-chant { display: flex; }
  .tools { margin: 0 auto; } .tool { width: 36px; height: 36px; }
  .creator-grid { grid-template-columns: 1fr; } #creatorPreview { max-width: 200px; margin: 0 auto; display: block; }
  .chant-hud { bottom: 8px; padding: 10px 12px; } .btn.big { padding: 12px 20px; }
  body.is-chanting .side-right { display: none; }
  .worship-hud { top: 44px; }
  .panel { top: 56px; bottom: 56px; right: 8px; }
  .interact-prompt { bottom: 150px; }
}
/* Lớp phủ HUD luôn nằm trên nền 2D dự phòng */
.worship-hud, .chant-hud, .interact-prompt, .zone-label { z-index: 3; }
body.is-2d .fallback2d { justify-content: flex-start; padding-top: 40px; }
@media (max-width: 760px) {
  .temple-app { grid-template-columns: minmax(0, 1fr); }
  .bottombar { overflow: hidden; padding: 6px; }
  .tools { flex-wrap: nowrap; gap: 4px; } .tool { width: 34px; height: 34px; font-size: .95rem; }
  body.is-chanting .mini-chant, body.is-chanting .joystick { display: none; }
  .chant-hud { left: 8px; right: 8px; width: auto; transform: none; }
  .chant-buttons .btn { padding: 10px 14px; }
  .chant-buttons .btn.big { flex-basis: 100%; }
}
@media (max-width: 760px) { .zone-label { white-space: nowrap; font-size: .8rem; max-width: calc(100% - 90px); overflow: hidden; text-overflow: ellipsis; } }

/* ---------- Chánh điện chung: giờ thật & người đang online ---------- */
.temple-clock { position: absolute; top: 10px; left: 12px; padding: 4px 12px; border-radius: 999px; background: rgba(30,18,11,.7); border: 1px solid rgba(201,161,74,.6); color: var(--gold-light); font-variant-numeric: tabular-nums; font-size: .95rem; pointer-events: none; z-index: 3; }
.temple-clock small { color: var(--muted); font-size: .78rem; }
.online-pill { position: absolute; top: 10px; right: 12px; display: flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: rgba(30,18,11,.75); border: 1px solid rgba(120,200,140,.7); color: #d9f5df; font-size: .88rem; cursor: pointer; z-index: 3; }
.online-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: #5fd47c; box-shadow: 0 0 0 0 rgba(95,212,124,.7); animation: onlinePulse 2s infinite; }
@keyframes onlinePulse { 70% { box-shadow: 0 0 0 7px rgba(95,212,124,0); } 100% { box-shadow: 0 0 0 0 rgba(95,212,124,0); } }
.online-list { position: absolute; top: 46px; right: 12px; width: min(300px, calc(100% - 24px)); max-height: 50%; overflow: auto; padding: 10px 14px; border-radius: 12px; background: rgba(30,18,11,.94); border: 1px solid var(--gold); z-index: 4; box-shadow: var(--shadow); }
.online-list h4 { margin: 0 0 6px; color: var(--gold-light); font-family: var(--serif); }
.online-list ul { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.online-list li { padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.group-banner { position: absolute; top: 46px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; max-width: calc(100% - 24px); padding: 6px 8px 6px 14px; border-radius: 14px; background: rgba(30,18,11,.88); border: 1px solid var(--gold); color: var(--gold-light); font-size: .9rem; z-index: 3; }
.group-banner.is-live { border-color: #ffcf6a; box-shadow: 0 0 18px rgba(255,190,80,.35); }
.group-banner .btn { white-space: nowrap; }
.map-other { fill: #5fd47c; stroke: #10301a; stroke-width: .2; }
body.is-chanting .online-pill, body.is-chanting .group-banner, body.is-chanting .temple-clock { opacity: .35; }
@media (max-width: 700px) {
  .temple-clock { top: 44px; left: 8px; font-size: .82rem; padding: 3px 9px; }
  .temple-clock small { display: none; }
  .online-pill { top: 44px; left: 74px; right: auto; font-size: .8rem; padding: 3px 9px; }
  .online-list { top: 76px; left: 8px; right: auto; }
  .group-banner { top: 78px; left: 8px; transform: none; max-width: calc(100% - 112px); flex-wrap: wrap; text-align: left; font-size: .8rem; padding: 6px 8px; }
}

/* Khấn nguyện + bia công đức */
.pray-card { width: min(720px, 100%); }
.pray-card textarea, .lake-card textarea { resize: vertical; }
.lake-card { width: min(560px, 100%); }
.pray-boards { display: grid; grid-template-columns: 1fr 1.3fr; gap: 14px; margin-top: 14px; border-top: 1px solid rgba(201,161,74,.35); padding-top: 10px; }
.pray-boards h3 { font-family: var(--serif); color: var(--gold-light); margin: 4px 0 8px; font-size: 1.05rem; }
.merit-list { margin: 0; padding-left: 0; list-style: none; }
.merit-list li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dashed rgba(201,161,74,.2); }
.merit-list li.me { color: var(--gold-light); font-weight: 600; }
.recent-prayers { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.recent-prayers li { padding: 6px 0; border-bottom: 1px dashed rgba(201,161,74,.2); }
.recent-prayers b { color: var(--gold-light); }
@media (max-width: 640px) { .pray-boards { grid-template-columns: 1fr; } }
/* Màn hình thấp: thu gọn cột hành lễ để đủ 7 nút */
@media (min-width: 761px) and (max-height: 820px) { .side-right { gap: 5px; padding: 8px; } .side-right .act { padding: 5px 6px; font-size: .8rem; } .side-right .act span { font-size: 1.1rem; } }

/* Con đường tu thành chánh quả */
.rank-card { display: block; width: 100%; margin: 8px 0 4px; padding: 8px 10px; text-align: left; cursor: pointer; color: inherit; font: inherit;
  background: linear-gradient(135deg, rgba(201,161,74,.22), rgba(122,58,20,.25)); border: 1px solid rgba(201,161,74,.55); border-radius: 10px; }
.rank-card:hover, .rank-card:focus-visible { border-color: var(--gold-light); }
.rank-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.rank-top b { color: var(--gold-light); font-size: .95rem; }
.rank-top small { opacity: .8; white-space: nowrap; }
.rank-bar { display: block; height: 7px; margin: 6px 0 4px; border-radius: 4px; background: rgba(0,0,0,.35); overflow: hidden; }
.rank-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #c9a14a, #ffe08a); transition: width .6s; }
.rank-hint { display: block; font-size: .74rem; opacity: .85; line-height: 1.3; }
.rank-modal { width: min(760px, 100%); max-height: 88vh; overflow: auto; }
.rank-now { font-size: 1.05rem; }
.rank-ladder { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
.rank-ladder li { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 8px; background: rgba(255,255,255,.05); border: 1px solid rgba(201,161,74,.2); }
.rank-ladder li .n { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: rgba(0,0,0,.3); font-weight: bold; }
.rank-ladder li.done .n { background: #c9a14a; color: #3a1a06; }
.rank-ladder li.current { border-color: var(--gold-light); background: rgba(201,161,74,.18); }
.rank-ladder li small { display: block; opacity: .75; }
.rank-ladder li .req { font-size: .78rem; opacity: .85; text-align: right; }
.rank-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.rank-table th, .rank-table td { padding: 4px 6px; border-bottom: 1px solid rgba(201,161,74,.2); text-align: right; }
.rank-table th:first-child, .rank-table td:first-child { text-align: left; }

.fallback-tips { text-align: left; max-width: 560px; margin: 0; padding-left: 1.2em; line-height: 1.45; }
.fallback-tips li { margin: 4px 0; }
#fallbackDetail { max-width: 560px; word-break: break-word; opacity: .6; }
.rank-ladder li small.reward { opacity: .95; color: #ffe2a0; margin-top: 2px; }
.rank-ladder li:not(.done) small.reward { opacity: .7; }
