/* ===================== Sân chùa 2.5D ===================== */
#yard { position: relative; height: 100vh; height: 100svh; min-height: 520px; overflow: hidden; background: #000; }
.yard-stage { position: absolute; inset: 0; overflow: hidden; }
.ylayer {
  position: absolute; inset: -4% -7%;
  transform: translate(var(--px, 0), var(--py, 0));
  transform-origin: 50% 64%;
  transition: transform .6s ease-out, opacity 1.9s;
  will-change: transform;
}
.ylayer svg { width: 100%; height: 100%; display: block; }
.yard-stage.walking .ylayer {
  transform: scale(calc(1 + var(--d) * 4.2));
  opacity: calc(1.45 - var(--d));
  transition: transform 1.9s cubic-bezier(.55, 0, .75, .45), opacity 1.9s;
}
.yard-particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.walk-fade {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .9s;
  background: radial-gradient(circle at 50% 62%, #fff3c4, #ffb84a 40%, #2a1206);
}
.walk-fade.on { opacity: 1; }
.topbar.floating { position: absolute; left: 0; right: 0; top: 0; background: linear-gradient(rgba(0, 0, 0, .55), transparent); backdrop-filter: none; }
.yard-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 36px 16px 22px; text-align: center;
  background: linear-gradient(transparent, rgba(0, 0, 0, .7));
}
.yard-desc { max-width: 520px; margin: 0 auto 4px; color: #fff3e0; text-shadow: 0 1px 4px #000; line-height: 1.45; font-size: .9rem; }
.yard-occ { color: var(--gold); font-size: .85rem; margin-bottom: 12px; text-shadow: 0 1px 3px #000; }
.primary.big { padding: 14px 34px; font-size: 1.1rem; }

.tree-sway { animation: tsway 6s ease-in-out infinite; }
@keyframes tsway { 0%, 100% { transform: rotate(-1.2deg); } 50% { transform: rotate(1.2deg); } }
.door-glow { animation: doorglow 3s ease-in-out infinite; }
@keyframes doorglow { 50% { opacity: .65; } }
.smoke-line { animation: doorglow 4s ease-in-out infinite; }

/* ===================== Chánh điện 3D ===================== */
.altar-scene {
  perspective: 700px; perspective-origin: 50% 42%;
  background: radial-gradient(ellipse at 50% 70%, var(--wall, #3a1208), #070302 75%);
}
#cam {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0; transform-style: preserve-3d;
  transform: scale3d(var(--k, 1), var(--k, 1), var(--k, 1)) translate3d(var(--cx, 0), var(--cy, 0), var(--cz, 0));
  transition: transform 2.6s cubic-bezier(.45, 0, .2, 1);
}
#cam.instant { transition: none; }
#room {
  position: absolute; left: 0; top: 0; transform-style: preserve-3d;
  transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transition: transform .8s ease-out;
}
#room > div { position: absolute; left: 0; top: 0; transform-style: preserve-3d; }
#room > div > div { position: absolute; left: 0; top: 0; }

.h-back {
  width: 1400px; height: 900px; transform-origin: 0 0;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .16) 0 3px, transparent 3px 140px),
    linear-gradient(#0d0604, var(--wall) 45%, var(--wall));
  box-shadow: inset 0 -40px 80px rgba(0, 0, 0, .5);
}
#room .h-back > .h-back-inner {
  left: 50%; top: auto; bottom: 0; width: 560px; height: 420px;
  transform: translateX(-50%) scale(1.6); transform-origin: 50% 100%;
}
.plaque {
  position: absolute; top: -34px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: linear-gradient(#6b1a0e, #4a0f08); border: 3px solid var(--gold-deep); border-radius: 4px;
  color: var(--gold); font-family: "Noto Serif", serif; font-weight: 700; font-size: 17px; letter-spacing: .06em; padding: 4px 20px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
}
.h-floor {
  width: 1400px; height: 1700px; transform-origin: 0 0;
  background:
    linear-gradient(90deg, transparent 610px, rgba(140, 20, 20, .55) 610px 790px, transparent 790px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .25) 0 2px, transparent 2px 140px),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, .18) 0 2px, transparent 2px 70px),
    linear-gradient(#1a0c08, var(--floor) 30%, var(--floor));
}
.h-side {
  height: 760px; transform-origin: 0 0; filter: brightness(.75);
  background:
    repeating-linear-gradient(90deg, var(--wall) 0 130px, transparent 130px 240px),
    linear-gradient(var(--wall) 0 24%, var(--window) 24% 56%, var(--wall) 56%);
}
.h-pillar {
  width: 48px; height: 760px; border-radius: 6px;
  background: linear-gradient(90deg, rgba(0, 0, 0, .5), var(--pillar) 30%, rgba(255, 160, 120, .35) 48%, var(--pillar) 66%, rgba(0, 0, 0, .55));
}
.h-pillar::before, .h-pillar::after { content: ""; position: absolute; left: -4px; right: -4px; height: 14px; background: var(--gold-deep); border-radius: 3px; }
.h-pillar::before { top: 90px; }
.h-pillar::after { bottom: 0; height: 30px; background: #5a4a3a; }
.h-lantern { width: 32px; height: 44px; }
.h-lantern i {
  display: block; width: 32px; height: 40px; border-radius: 45%; margin-top: 4px;
  background: radial-gradient(#ffe6a8, #d8382a 72%); box-shadow: 0 0 34px 12px rgba(255, 140, 60, .35);
  animation: sway 5s ease-in-out infinite; transform-origin: 50% -200px;
}
.h-lantern::before { content: ""; position: absolute; left: 15px; bottom: 100%; width: 2px; height: 300px; background: #2a160c; }

.cushion {
  width: 68px; height: 68px; border-radius: 50%; transform-origin: 0 0;
  background: radial-gradient(circle at 50% 42%, #b4482c, #6a1a10 72%);
  box-shadow: inset 0 0 0 4px rgba(201, 138, 36, .55), 0 0 0 3px rgba(0, 0, 0, .3);
  display: grid; place-items: center;
}
.cushion span { font-size: 18px; font-weight: 700; color: rgba(243, 198, 107, .55); }
.cushion.mine { background: radial-gradient(circle at 50% 42%, #ffe08a, #c98a24 72%); box-shadow: 0 0 40px 14px rgba(255, 200, 100, .55); }
.cushion.mine span { color: #5a2a0c; }
.sitter { width: 60px; height: 70px; }
.sitter svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .5)); }
.sitter small {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); white-space: nowrap;
  font-size: 12px; color: var(--text); background: rgba(0, 0, 0, .55); padding: 1px 6px; border-radius: 6px; opacity: 0; transition: opacity .2s;
}
.sitter:hover small { opacity: 1; }
.seat-marker {
  color: var(--gold); font-size: 34px; text-align: center; white-space: nowrap;
  text-shadow: 0 0 14px rgba(255, 200, 100, .9); animation: markerpulse 1.6s ease-in-out infinite;
}
.seat-marker small { display: block; font-size: 15px; font-weight: 600; }
@keyframes markerpulse { 50% { opacity: .45; } }
.seated .seat-marker { display: none; }

.kinh-banner {
  position: absolute; left: 12px; top: 10px; z-index: 6; max-width: calc(100% - 110px);
  background: rgba(0, 0, 0, .5); border: 1px solid var(--panel-border); border-radius: 999px;
  padding: 4px 12px; font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.kinh-banner:empty { display: none; }
.kinh-banner b { color: var(--gold); font-weight: 600; }
.sit-bar {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 7;
  display: flex; flex-direction: column; align-items: center; gap: 8px; transition: opacity .5s;
}
.seat-label { background: rgba(0, 0, 0, .6); border: 1px solid var(--gold-deep); border-radius: 999px; padding: 3px 12px; font-size: .8rem; color: var(--gold); white-space: nowrap; }
.seated .sit-bar { opacity: 0; pointer-events: none; }
.stand-btn { position: absolute; right: 12px; bottom: 12px; z-index: 7; }

.kinh-text {
  margin-top: 14px; max-height: 260px; overflow: auto;
  background: rgba(0, 0, 0, .25); border: 1px solid var(--panel-border); border-radius: 12px; padding: 12px 16px;
  font-family: "Noto Serif", serif; line-height: 1.9;
}
.kinh-text:empty { display: none; }
.panel .kinh-text p { margin: 0; color: var(--muted); transition: color .4s, transform .4s; }
.panel .kinh-text p.on { color: var(--gold); transform: translateX(4px); }
.panel .kinh-text p.big { font-size: 1.6rem; text-align: center; color: var(--gold); padding: 18px 0 6px; }
.kinh-schedule { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.kinh-schedule li { display: flex; gap: 12px; padding: 6px 10px; border-radius: 8px; font-size: .9rem; color: var(--muted); border: 1px solid transparent; }
.kinh-schedule li time { color: var(--gold-deep); font-variant-numeric: tabular-nums; min-width: 92px; }
.kinh-schedule li.now { background: rgba(243, 198, 107, .1); color: var(--text); border-color: var(--gold-deep); }
.kinh-schedule li.now::after { content: "đang tụng"; margin-left: auto; font-size: .75rem; color: var(--gold); }
.small { font-size: .8rem; }

/* ===================== Góc nhìn & nhân vật ===================== */
#cam.dragging { transition: transform .08s linear; }
.altar-scene { touch-action: pan-y; cursor: grab; }
.altar-scene:active { cursor: grabbing; }
.h-back, #room .h-back > .h-back-inner, .h-side { backface-visibility: hidden; }

#room .sitter { width: 76px; height: 84px; transform-style: preserve-3d; }
.sitter .face { position: absolute; inset: 0; backface-visibility: hidden; }
.sitter .face.front { transform: rotateY(180deg); }
.sitter .chibi { width: 100%; height: 100%; display: block; overflow: visible; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .45)); }
.sitter .breathe { transform-origin: 50% 100%; animation: breathe 4s ease-in-out infinite; animation-delay: var(--delay, 0s); }
@keyframes breathe { 50% { transform: scale(1.015, 1.035); } }
.sitter.me::before {
  content: ""; position: absolute; left: 50%; bottom: -6px; width: 110px; height: 30px; margin-left: -55px; border-radius: 50%;
  background: radial-gradient(rgba(255, 220, 140, .7), transparent 70%); animation: doorglow 3s ease-in-out infinite;
}
.sitter.me { animation: appear .8s ease-out; }
@keyframes appear { from { opacity: 0; } }

.view-bar { position: absolute; right: 10px; top: 46px; z-index: 7; display: flex; flex-direction: column; gap: 6px; }
.view-bar button {
  width: 40px; height: 40px; border-radius: 50%; padding: 0; font-size: 17px; line-height: 1;
  background: rgba(0, 0, 0, .5); border: 1px solid var(--panel-border); color: var(--text);
}
.view-bar button.on { border-color: var(--gold); box-shadow: 0 0 10px rgba(243, 198, 107, .5); }
.view-bar button[hidden] { display: none; }
.view-name {
  position: absolute; right: 58px; top: 52px; z-index: 7; font-size: .75rem; color: var(--gold);
  background: rgba(0, 0, 0, .5); padding: 2px 8px; border-radius: 999px; pointer-events: none; transition: opacity .6s;
}
.drag-hint { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 6; font-size: .72rem; color: var(--muted); pointer-events: none; opacity: .8; }
.seated .drag-hint { bottom: 54px; }

/* ===================== Đăng ký & phí duy trì ===================== */
.gender-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.gender-pick label {
  border: 2px solid var(--panel-border); border-radius: 14px; padding: 8px; text-align: center; cursor: pointer;
  background: var(--panel); transition: border-color .2s, transform .2s;
}
.gender-pick label:has(input:checked) { border-color: var(--gold); transform: translateY(-2px); background: rgba(243, 198, 107, .08); }
.gender-pick input { position: absolute; opacity: 0; pointer-events: none; }
.gender-pick svg { width: 96px; height: 106px; display: block; margin: 0 auto; }
.gender-pick span { font-weight: 600; }
.fee-pick { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.fee-pick label { flex: 1; min-width: 120px; border: 2px solid var(--panel-border); border-radius: 12px; padding: 10px; text-align: center; cursor: pointer; }
.fee-pick label:has(input:checked) { border-color: var(--gold); background: rgba(243, 198, 107, .08); }
.fee-pick input { position: absolute; opacity: 0; pointer-events: none; }
.fee-pick b { display: block; font-size: 1.2rem; color: var(--gold); }
.pay-box { display: grid; gap: 10px; justify-items: center; text-align: center; margin-top: 10px; }
.pay-box img { width: min(260px, 100%); border-radius: 12px; background: #fff; }
.pay-info { width: 100%; display: grid; gap: 4px; font-size: .9rem; text-align: left; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px 12px; }
.pay-info b { color: var(--gold); }
.pay-code { font-size: 1.3rem; letter-spacing: .08em; color: var(--gold); user-select: all; }
.pay-wait { color: var(--muted); font-size: .85rem; }
.pay-wait::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); margin-right: 6px; animation: markerpulse 1.2s infinite; }
.pay-ok { color: #9be39b; font-weight: 600; }
.note-box { font-size: .82rem; color: var(--muted); background: rgba(0, 0, 0, .2); border-radius: 10px; padding: 8px 12px; line-height: 1.5; }
#room .sitter { transition: opacity .6s; }
#room .sitter.behind { opacity: .12; }
dialog { overflow-x: hidden; }

/* ===================== Sân chùa 3D ===================== */
.yard-stage { background: linear-gradient(var(--sky, #6a8ab0), #20140c); touch-action: pan-y; cursor: grab; }
.yard-stage:active { cursor: grabbing; }
.y3cam {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0; transform-style: preserve-3d;
  transition: transform 3s cubic-bezier(.42, 0, .25, 1);
}
.y3cam.instant { transition: none; }
.y3cam.dragging { transition: transform .08s linear; }
.y3world, .g3 { position: absolute; left: 0; top: 0; transform-style: preserve-3d; }
.p3 { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.p3 > svg { display: block; }
.p3.face { background-color: #7a2a14; }
.p3.face > div { width: 100%; height: 100%; }
.p3.stone { background-color: #8e887c; }
.p3.stone.side { background-color: #6e695f; }
.p3.stone.top, .p3.stone-top { background-color: #9c968a; background-image: repeating-linear-gradient(0deg, #0002 0 2px, transparent 2px 60px), repeating-linear-gradient(90deg, #0002 0 2px, transparent 2px 60px); }
.p3.roof { background-image: repeating-linear-gradient(90deg, rgba(0, 0, 0, .28) 0 4px, transparent 4px 18px), linear-gradient(rgba(255, 255, 255, .08), rgba(0, 0, 0, .25)); }
.p3.gable { clip-path: polygon(50% 0, 100% 100%, 0 100%); background-image: linear-gradient(rgba(0, 0, 0, .25), rgba(0, 0, 0, .4)); }
.p3.shadow { background: radial-gradient(closest-side, rgba(0, 0, 0, .45), transparent); }
.p3.ground {
  background-image:
    radial-gradient(ellipse at 50% 70%, transparent 30%, rgba(0, 0, 0, .35) 75%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, .12) 0 1px, transparent 1px calc(90px / var(--s, 1))),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .12) 0 1px, transparent 1px calc(90px / var(--s, 1)));
}
.p3.water { opacity: .95; box-shadow: inset 0 0 60px rgba(255, 255, 255, .15); }
.p3.water::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0 22px, rgba(255, 255, 255, .12) 22px 24px);
  animation: ripple 6s linear infinite;
}
@keyframes ripple { to { background-position: 0 48px; } }
.cloud3, .bird3 { display: block; width: 100%; height: 100%; }
.cloud3 { animation: cdrift var(--dur) linear infinite; animation-delay: var(--del); }
@keyframes cdrift { from { transform: translateX(-900px); } to { transform: translateX(900px); } }
.bird3 { animation: bfly 34s linear infinite; animation-delay: var(--del); }
@keyframes bfly { 0% { transform: translate(0, 0) scaleY(1); } 25% { transform: translate(700px, -60px) scaleY(.5); } 50% { transform: translate(1400px, -20px) scaleY(1); } 75% { transform: translate(2100px, -80px) scaleY(.5); } 100% { transform: translate(2800px, 0) scaleY(1); } }
.gate3 { transition: opacity .8s .5s, visibility 0s 1.3s; }
.yard-stage.walking .gate3 { opacity: 0; visibility: hidden; }
.yard-stage.night { background: linear-gradient(#03050f, #0c1024); }
@media (prefers-reduced-motion: reduce) { .cloud3, .bird3, .p3.water::after { animation: none; } }

/* Tên trên đầu: luôn hiện, hai mặt để nhìn từ phía nào chữ cũng xuôi */
#room .sitter small.name {
  position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
  opacity: 1; font-size: 28px; font-weight: 600; line-height: 1.2; white-space: nowrap; max-width: 116px; overflow: hidden; text-overflow: ellipsis;
  color: #fff3e0; background: rgba(0, 0, 0, .5); padding: 2px 10px; border-radius: 999px;
  text-shadow: 0 1px 2px #000; backface-visibility: hidden; pointer-events: none;
}
#room .sitter small.name.flip { transform: translateX(-50%) rotateY(180deg); }
#room .sitter.me small.name { color: var(--gold); border: 1px solid var(--gold-deep); }
#room .sitter.me::before { display: none; }

/* ===================== Sơ đồ toàn điện ===================== */
.hall-map {
  position: absolute; inset: 44px 58px 12px 12px; z-index: 8; overflow: auto;
  background: rgba(12, 6, 4, .88); border: 1px solid var(--gold-deep); border-radius: 14px; padding: 12px;
  backdrop-filter: blur(4px); cursor: default; touch-action: pan-y;
}
.map-close { position: sticky; top: 0; float: right; z-index: 2; padding: 2px 10px; }
.map-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: .85rem; }
.map-head b { color: var(--gold); }
.map-head span { color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.map-head span i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 6px; }
.map-floor { perspective: 900px; }
.map-altar {
  margin: 0 auto 10px; width: 60%; text-align: center; font-size: .75rem; color: var(--gold);
  border: 1px solid var(--gold-deep); border-radius: 6px; padding: 3px; background: rgba(201, 138, 36, .12);
}
.map-blocks { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; transform: rotateX(18deg); transform-origin: 50% 0; }
.map-block { background: rgba(255, 255, 255, .04); border: 1px solid var(--panel-border); border-radius: 8px; padding: 4px 6px 6px; }
.map-block.here { border-color: var(--gold); box-shadow: 0 0 10px rgba(243, 198, 107, .35); }
.map-block > b { display: block; font-size: .68rem; color: var(--muted); text-align: center; margin-bottom: 3px; font-weight: 600; }
.map-block.here > b { color: var(--gold); }
.map-grid { display: grid; grid-template-columns: repeat(9, 9px); gap: 3px; }
.map-grid i { width: 9px; height: 9px; border-radius: 50%; background: transparent; box-shadow: inset 0 0 0 1.5px rgba(201, 138, 36, .45); }
.map-grid i.none { box-shadow: none; }
.map-grid i.nam, .map-head i.nam { background: #8fb0dc; box-shadow: none; }
.map-grid i.nu, .map-head i.nu { background: #f0a6bd; box-shadow: none; }
.map-grid i.me, .map-head i.me { background: var(--gold); box-shadow: 0 0 6px var(--gold); }
