:root {
  --bg: #1a0d08;
  --bg2: #2b130b;
  --panel: rgba(255, 240, 220, .05);
  --panel-border: rgba(243, 198, 107, .22);
  --gold: #f3c66b;
  --gold-deep: #c98a24;
  --text: #f6e7d0;
  --muted: #c9ae8d;
  --halo: rgba(255, 226, 150, .55);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: #140a06;
  color: var(--text);
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}
h1, h2, h3 { font-family: "Noto Serif", serif; color: var(--gold); margin: 0 0 .4em; }
button { font: inherit; cursor: pointer; color: inherit; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.screen { display: none; }
.screen.active { display: block; }

/* ===== Nút ===== */
.primary {
  background: linear-gradient(var(--gold), var(--gold-deep));
  color: #3a1a0e; border: 0; border-radius: 999px;
  padding: 10px 20px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(201, 138, 36, .35);
}
.primary:active { transform: scale(.97); }
.ghost {
  background: rgba(0, 0, 0, .2); border: 1px solid var(--panel-border); border-radius: 999px;
  padding: 6px 14px; color: var(--muted);
}
.ghost:hover { color: var(--gold); border-color: var(--gold-deep); }

/* ===== Cổng ===== */
#gate { position: relative; min-height: 100vh; padding: 16px 16px 40px; text-align: center; }
.gate-sky {
  position: absolute; inset: 0; z-index: -1;
  background: radial-gradient(circle at 50% 12%, rgba(243, 198, 107, .25), transparent 45%), linear-gradient(#3a1a0e, #140a06 60%);
}
.gate-inner { max-width: 1080px; margin: 0 auto; }
.me-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.gate-roof svg { width: min(340px, 86%); filter: drop-shadow(0 8px 20px rgba(0, 0, 0, .5)); }
#gate h1 { font-size: clamp(2rem, 6vw, 3.2rem); margin-top: 6px; }
.subtitle { color: var(--muted); max-width: 540px; margin: 0 auto 28px; line-height: 1.6; }
.note { color: var(--muted); font-size: .8rem; opacity: .7; margin-top: 28px; }

.temple-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.temple-card {
  background: linear-gradient(var(--card-a), #1a0d08);
  border: 1px solid var(--panel-border); border-radius: var(--radius);
  overflow: hidden; text-align: left;
  transition: transform .2s, border-color .2s;
  display: flex; flex-direction: column;
}
.temple-card:hover { transform: translateY(-4px); border-color: var(--gold); }
.card-thumb { height: 130px; overflow: hidden; }
.card-thumb svg { width: 100%; height: 100%; display: block; }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; flex: 1; }
.card-body h3 { margin: 0 0 2px; font-size: 1.1rem; }
.region { color: var(--gold-deep); font-size: .8rem; margin-bottom: 6px; }
.card-body p { color: var(--muted); font-size: .88rem; line-height: 1.5; margin: 0 0 10px; flex: 1; }
.card-body .primary { align-self: flex-start; }
.occ { display: flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--muted); margin-bottom: 12px; }
.occ-bar { flex: 1; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.occ-bar i { display: block; height: 100%; background: linear-gradient(90deg, #7bc67b, var(--gold)); }

.board { max-width: 520px; margin: 36px auto 0; text-align: left; }
.board h2 { text-align: center; }
.leaderboard { list-style: none; counter-reset: r; padding: 0; margin: 0; display: grid; gap: 6px; }
.leaderboard li {
  counter-increment: r; display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 8px 12px;
}
.leaderboard li::before { content: counter(r); width: 24px; color: var(--gold-deep); font-weight: 700; }
.leaderboard li:nth-child(1)::before { content: "🥇"; }
.leaderboard li:nth-child(2)::before { content: "🥈"; }
.leaderboard li:nth-child(3)::before { content: "🥉"; }
.leaderboard li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard li b { color: var(--gold); }
.leaderboard li.empty { color: var(--muted); justify-content: center; }
.leaderboard li.empty::before { content: none; }

/* ===== Chánh điện ===== */
#hall { background: var(--bg); min-height: 100vh; transition: background .6s; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px; background: rgba(0, 0, 0, .4);
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(6px);
}
.temple-title { text-align: center; min-width: 0; }
.temple-name { font-family: "Noto Serif", serif; color: var(--gold); font-weight: 600; }
.scene-title { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.merit { color: var(--gold); font-weight: 600; white-space: nowrap; }
.lotus-ico { color: #ff9fb6; }

.altar-scene {
  position: relative; height: clamp(400px, 52vw, 520px);
  overflow: hidden; background: var(--bg);
}
.backdrop { position: absolute; inset: 0; z-index: 0; }
.backdrop svg { width: 100%; height: 100%; display: block; }
.altar-scene::after {
  /* làm tối đáy để bàn thờ nổi lên */
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(transparent 72%, rgba(0, 0, 0, .5));
}
.particles { position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }

.halo {
  position: absolute; left: 50%; bottom: 90px; width: 320px; height: 320px; z-index: 2;
  transform: translateX(-50%); border-radius: 50%;
  background: radial-gradient(circle, var(--halo), transparent 65%);
  animation: halo 6s ease-in-out infinite;
}
.altar-scene.glow .halo { animation: halo-burst 1.2s ease-out; }
@keyframes halo { 50% { opacity: .7; transform: translateX(-50%) scale(1.06); } }
@keyframes halo-burst { 40% { transform: translateX(-50%) scale(1.4); opacity: 1; } }

.statue-wrap { position: absolute; left: 50%; bottom: 74px; width: 190px; transform: translateX(-50%); z-index: 3; }
.statue { width: 100%; display: block; filter: drop-shadow(0 0 18px rgba(255, 220, 150, .35)); }

.altar {
  position: absolute; left: 50%; bottom: 0; z-index: 4;
  width: min(560px, 94%); height: 96px; transform: translateX(-50%);
  background: linear-gradient(#7a2a14, #3a1208);
  border-top: 6px solid var(--gold-deep); border-radius: 6px 6px 0 0;
  display: flex; align-items: flex-start; justify-content: space-around; padding: 0 10px;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .4);
}
.candle {
  position: relative; width: 14px; height: 42px; margin-top: -42px;
  background: linear-gradient(90deg, #d8382a, #ff6a4a, #d8382a); border-radius: 3px;
}
.flame {
  position: absolute; left: 50%; top: -22px; width: 12px; height: 22px; transform: translateX(-50%);
  background: radial-gradient(ellipse at 50% 70%, #fff6c4, #ffb02e 50%, rgba(255, 80, 0, 0) 75%);
  border-radius: 50% 50% 45% 45%; animation: flicker .18s infinite alternate;
}
@keyframes flicker { to { transform: translateX(-50%) scale(.92, 1.08) rotate(2deg); opacity: .85; } }
.vase { margin-top: -44px; }

.burner-wrap { position: relative; width: 110px; margin-top: -38px; }
.burner {
  width: 110px; height: 42px; background: linear-gradient(#e0a53a, #8a5512);
  border-radius: 8px 8px 40px 40px; box-shadow: inset 0 6px 0 rgba(255, 240, 180, .4);
}
.incense-holder { position: absolute; left: 0; right: 0; bottom: 36px; height: 0; display: flex; justify-content: center; gap: 7px; }
.stick {
  position: relative; align-self: flex-end; width: 3px; height: 90px;
  background: linear-gradient(#b0331d 0 4px, #c97b3d 4px 70%, #a3271a 70%);
  transform-origin: bottom center; transform: rotate(var(--r, 0deg));
  animation: burn 60s linear forwards;
}
.stick::before {
  content: ""; position: absolute; top: -3px; left: -2px; width: 7px; height: 7px; border-radius: 50%;
  background: #ff5b1f; box-shadow: 0 0 8px 3px rgba(255, 110, 30, .8);
  animation: ember 1s ease-in-out infinite alternate;
}
@keyframes burn { to { height: 28px; } }
@keyframes ember { to { box-shadow: 0 0 4px 1px rgba(255, 110, 30, .5); } }
.smoke {
  position: absolute; left: -6px; top: -14px; width: 14px; height: 14px; border-radius: 50%;
  background: rgba(230, 220, 210, .35); filter: blur(4px);
  animation: smoke 3.2s ease-out forwards; pointer-events: none;
}
@keyframes smoke { to { transform: translate(var(--dx, 10px), -150px) scale(3.4); opacity: 0; } }

.offerings {
  position: absolute; left: 0; right: 0; bottom: 8px;
  display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; font-size: 24px; padding: 0 40px;
}
.offerings span { animation: drop .5s ease-out; }
@keyframes drop { from { transform: translateY(-40px); opacity: 0; } }

.presence {
  position: absolute; right: 12px; top: 10px; z-index: 6;
  background: rgba(0, 0, 0, .45); border: 1px solid var(--panel-border);
  padding: 4px 10px; border-radius: 999px; font-size: .8rem; color: var(--text);
}
.presence.full { border-color: #e0604a; color: #ffb3a3; }

.sky-lanterns { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.lantern {
  position: absolute; bottom: 60px; font-size: 30px;
  animation: rise 9s ease-in forwards; filter: drop-shadow(0 0 10px rgba(255, 170, 60, .9));
}
.lantern small {
  position: absolute; top: 34px; left: 50%; transform: translateX(-50%);
  font-size: 11px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; color: var(--gold);
  text-shadow: 0 1px 3px #000;
}
@keyframes rise { to { transform: translate(var(--dx, 0), -480px) scale(.55); opacity: 0; } }

.float-merit {
  position: absolute; color: var(--gold); font-weight: 700; pointer-events: none; z-index: 50;
  animation: floatup 1s ease-out forwards; white-space: nowrap; text-shadow: 0 1px 4px #000;
}
@keyframes floatup { to { transform: translateY(-60px); opacity: 0; } }

.toast {
  position: absolute; left: 50%; top: 46px; transform: translate(-50%, -20px); z-index: 8;
  background: rgba(20, 10, 5, .85); border: 1px solid var(--gold-deep);
  padding: 8px 16px; border-radius: 999px; font-size: .88rem;
  opacity: 0; transition: .3s; pointer-events: none; max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.queue-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 5, 3, .72); backdrop-filter: blur(3px);
}
.queue-box {
  max-width: 340px; text-align: center; background: rgba(30, 15, 8, .92);
  border: 1px solid var(--gold-deep); border-radius: var(--radius); padding: 20px;
}
.queue-box p { color: var(--text); line-height: 1.5; }
.queue-box b { color: var(--gold); font-size: 1.2em; }
.queue-ico { font-size: 2rem; }

/* ===== Hoạt động chung ===== */
.feed { max-width: 720px; margin: 0 auto; padding: 8px 16px 0; min-height: 30px; display: flex; flex-direction: column; gap: 2px; }
.feed-item { font-size: .8rem; color: var(--muted); animation: fade .4s; }
.feed-item:first-child { color: var(--text); }
.feed-item::before { content: "• "; color: var(--gold-deep); }

/* ===== Hạt bay ===== */
.particles i, .yard-particles i { position: absolute; display: block; animation-timing-function: linear; animation-fill-mode: forwards; }
.p-petal {
  top: -12px; width: calc(11px * var(--s)); height: calc(7px * var(--s));
  background: linear-gradient(#ffd0dc, #ff8fae); border-radius: 80% 0 80% 0; opacity: .85;
  animation-name: fall;
}
.p-blossom {
  top: -10px; width: calc(6px * var(--s)); height: calc(6px * var(--s)); border-radius: 50%;
  background: #fff; box-shadow: 0 0 4px #fff; opacity: .9; animation-name: fall;
}
@keyframes fall {
  0% { transform: translate(0, 0) rotate(0); }
  50% { transform: translate(calc(var(--dx) * -.5), 240px) rotate(260deg); }
  100% { transform: translate(var(--dx), 520px) rotate(540deg); opacity: .2; }
}
.p-firefly {
  width: 4px; height: 4px; border-radius: 50%; background: #fff6a0;
  box-shadow: 0 0 8px 3px rgba(255, 240, 120, .7); opacity: 0; animation-name: wander; animation-timing-function: ease-in-out;
}
@keyframes wander {
  20% { opacity: 1; } 50% { transform: translate(calc(var(--dx) * .6), -30px); opacity: .4; }
  80% { opacity: 1; } 100% { transform: translate(var(--dx), -10px); opacity: 0; }
}
.p-mist {
  width: 260px; height: 70px; margin-left: -130px; border-radius: 50%;
  background: rgba(235, 240, 250, .18); filter: blur(14px); opacity: 0; animation-name: mist;
}
@keyframes mist { 20%, 80% { opacity: 1; } 100% { transform: translateX(calc(var(--dx) * 3)); opacity: 0; } }
.p-sparkle {
  bottom: 60px; width: 4px; height: 4px; background: #ffe39a; transform: rotate(45deg);
  box-shadow: 0 0 6px 2px rgba(255, 220, 120, .8); animation-name: sparkle;
}
@keyframes sparkle { 0% { opacity: 0; } 30% { opacity: 1; } 100% { transform: translate(var(--dx), -240px) rotate(45deg); opacity: 0; } }
.p-glint {
  width: calc(3px * var(--s)); height: calc(3px * var(--s)); border-radius: 50%; background: #fff;
  box-shadow: 0 0 6px 2px rgba(255, 255, 255, .8); opacity: 0; animation-name: glint; animation-timing-function: ease-in-out;
}
@keyframes glint { 50% { opacity: .9; } }
.p-lantern {
  bottom: -20px; width: calc(14px * var(--s)); height: calc(18px * var(--s)); border-radius: 45%;
  background: radial-gradient(#ffd27a, #e0482a); box-shadow: 0 0 14px 4px rgba(255, 140, 60, .6);
  opacity: .85; animation-name: lift;
}
@keyframes lift { 100% { transform: translate(var(--dx), -560px) scale(.5); opacity: 0; } }

/* Chuyển động trong phong cảnh */
.shimmer { animation: shimmer 4s ease-in-out infinite; }
@keyframes shimmer { 50% { opacity: .05; } }
.drift { animation: drift 80s linear infinite; }
@keyframes drift { from { transform: translateX(-60px); } to { transform: translateX(60px); } }
.bird { animation: fly 22s linear infinite; }
@keyframes fly {
  from { transform: translate(-40px, var(--by)) scale(.9); }
  50% { transform: translate(240px, calc(var(--by) - 20px)) scale(.9, .6); }
  to { transform: translate(520px, calc(var(--by) - 10px)) scale(.9); }
}
.bob { animation: bob 4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translate(6px, 2px); } }
.sway { animation: sway 5s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
.win { animation: win 8s steps(1) infinite; }
@keyframes win { 70% { opacity: .2; } }
.waves { animation: waves 6s linear infinite; }
@keyframes waves { to { transform: translateX(40px); } }

@media (prefers-reduced-motion: reduce) {
  .shimmer, .drift, .bird, .bob, .sway, .win, .waves, .halo { animation: none; }
}

/* ===== Thanh hành động ===== */
.actions {
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px;
  background: rgba(0, 0, 0, .25); scrollbar-width: none; justify-content: safe center;
}
.actions button {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; border: 1px solid transparent; border-radius: 12px;
  padding: 6px 10px; font-size: .78rem; color: var(--muted);
}
.actions button span { font-size: 1.5rem; }
.actions button.active { border-color: var(--gold-deep); color: var(--gold); background: rgba(243, 198, 107, .08); }

.panels { max-width: 720px; margin: 0 auto; padding: 18px 16px 10px; }
.panel { display: none; animation: fade .3s; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
.panel p { color: var(--muted); line-height: 1.6; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.counter { color: var(--muted); }
.counter b { color: var(--gold); }

.bow-figure { font-size: 64px; text-align: center; transition: transform .6s; transform-origin: bottom center; }
.bow-figure.down { transform: scaleY(.7) translateY(10px); }

.moktak-area { position: relative; display: flex; justify-content: center; padding: 20px 0; }
.moktak { background: none; border: 0; padding: 0; width: 220px; touch-action: manipulation; }
.moktak svg { width: 100%; display: block; transition: transform .07s; }
.moktak.hit svg { transform: scale(.94); }
.mallet {
  position: absolute; top: 0; left: calc(50% + 60px); width: 90px; height: 14px; border-radius: 7px;
  background: linear-gradient(90deg, #6b3a14, #a5652c);
  transform-origin: right center; transform: rotate(-25deg); transition: transform .07s; pointer-events: none;
}
.mallet::before { content: ""; position: absolute; left: -12px; top: -8px; width: 28px; height: 28px; border-radius: 50%; background: #8b4a1f; }
.mallet.hit { transform: rotate(8deg); }
.switch { color: var(--muted); display: flex; align-items: center; gap: 6px; }

.bell-wrap { display: flex; justify-content: center; padding: 10px 0; }
.bell { background: none; border: 0; width: 160px; transform-origin: top center; }
.bell svg { width: 100%; }
.bell.ring { animation: swing 1.6s ease-out; }
@keyframes swing { 15% { transform: rotate(10deg); } 35% { transform: rotate(-8deg); } 55% { transform: rotate(5deg); } 75% { transform: rotate(-2deg); } }

form { display: grid; gap: 10px; }
input, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: rgba(0, 0, 0, .3); border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 10px 12px; resize: vertical;
}
input[type=checkbox] { width: auto; }
input[type=range] { width: 110px; padding: 0; accent-color: var(--gold-deep); background: none; border: 0; }
input:focus, textarea:focus { outline: 2px solid var(--gold-deep); outline-offset: 1px; }
form .primary { justify-self: start; }
.panel h3 { margin-top: 24px; font-size: 1.05rem; }
.wish-list, .visit-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.wish-list li, .visit-list li {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px 12px; line-height: 1.5;
}
.wish-list li small, .visit-list li small { display: block; color: var(--muted); font-size: .78rem; margin-top: 2px; }
.wish-list .empty, .visit-list .empty { color: var(--muted); border-style: dashed; }

.fortune-area { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; justify-content: center; padding: 10px 0; }
.tube { position: relative; width: 70px; height: 120px; background: linear-gradient(90deg, #6b1a12, #b0331d, #6b1a12); border-radius: 8px 8px 14px 14px; margin-top: 50px; }
.tube .sticks { position: absolute; bottom: 60px; left: 8px; right: 8px; display: flex; justify-content: space-between; }
.tube .sticks i { display: block; width: 5px; height: 60px; background: #d9b06a; border-radius: 2px; transition: transform .6s; }
.tube .sticks i:nth-child(odd) { height: 52px; }
.tube .sticks i.out { transform: translateY(-40px); }
.tube.shake { animation: shake .12s 10 alternate; }
@keyframes shake { from { transform: rotate(-12deg); } to { transform: rotate(12deg); } }

.fortune-card {
  margin-top: 16px; background: linear-gradient(#f7e6c4, #e9cf9b); color: #3a1a0e;
  border-radius: var(--radius); padding: 20px; text-align: center; animation: fade .5s; border: 3px double #a3271a;
}
.f-no { font-family: "Noto Serif", serif; font-size: 1.2rem; color: #a3271a; font-weight: 700; }
.f-level { display: inline-block; margin: 6px 0 10px; padding: 2px 12px; border-radius: 999px; background: #a3271a; color: #fff3d6; font-size: .85rem; }
.panel .f-poem { font-family: "Noto Serif", serif; font-size: 1.05rem; line-height: 1.8; white-space: pre-line; color: #3a1a0e; }
.panel .f-meaning { color: #5a3420; }
.panel .f-disclaimer { font-size: .75rem; color: #7a5a40; margin: 0; }

.offer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 10px; }
.offer-grid button {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
  padding: 12px 6px; font-size: 2rem; display: flex; flex-direction: column; align-items: center;
}
.offer-grid button:hover { border-color: var(--gold); }
.offer-grid small { font-size: .8rem; color: var(--muted); margin-top: 4px; }

.foot {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  max-width: 720px; margin: 10px auto 0; padding: 0 16px 30px;
  color: var(--muted); font-family: "Noto Serif", serif;
}
.sound-ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-family: "Be Vietnam Pro", sans-serif; }

/* ===== Hộp thoại ===== */
dialog {
  width: min(520px, calc(100% - 32px)); max-height: calc(100vh - 40px); overflow: auto;
  background: #22120a; color: var(--text); border: 1px solid var(--gold-deep); border-radius: var(--radius);
  padding: 20px; position: fixed;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(2px); }
dialog h3 { margin-top: 20px; font-size: 1rem; }
dialog p { line-height: 1.5; }
.dlg-close { position: absolute; right: 12px; top: 12px; display: block; }
.name-row { display: flex; gap: 8px; margin-top: 10px; }
.name-row input { flex: 1; min-width: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 16px; }
.stat { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 8px; text-align: center; }
.stat b { display: block; color: var(--gold); font-size: 1.1rem; }
.stat span { font-size: .75rem; color: var(--muted); }
.stat.big { grid-column: 1 / -1; }
.stat.big b { font-size: 1.6rem; }
.recovery { font-size: 1rem; color: var(--gold); letter-spacing: .05em; user-select: all; }

@media (max-width: 520px) {
  .statue-wrap { width: 140px; bottom: 72px; }
  .halo { width: 220px; height: 220px; bottom: 80px; }
  .altar { height: 84px; }
  .vase svg { width: 26px; }
  .actions { justify-content: flex-start; }
}
