:root {
  --bg: #1a0805;
  --bg2: #3a120a;
  --red: #8b1a10;
  --gold: #e8c66a;
  --gold-dark: #b08a2e;
  --text: #f6e7c1;
  --muted: #c9ae7a;
  --card: rgba(40, 12, 6, 0.85);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Serif", Georgia, serif;
  color: var(--text);
  background:
    radial-gradient(ellipse at 50% 20%, rgba(232, 198, 106, 0.18), transparent 60%),
    linear-gradient(180deg, var(--bg2), var(--bg));
  background-attachment: fixed;
}

h1, h2 { color: var(--gold); margin: 0 0 12px; }
h2 { font-size: 1.1rem; letter-spacing: 0.5px; }

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

.card {
  background: var(--card);
  border: 1px solid var(--gold-dark);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 1rem;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s, box-shadow 0.2s;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #d6402b, var(--red));
  color: #fff4d6;
  border: 1px solid var(--gold-dark);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 0 14px rgba(232, 198, 106, 0.5); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--gold-dark); }
.btn.small { padding: 6px 12px; font-size: 0.85rem; }
.btn.big { font-size: 1.2rem; padding: 14px 32px; margin-top: 24px; }

input[type="text"] {
  font-family: inherit;
  font-size: 1rem;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--gold-dark);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  outline: none;
}
input[type="text"]:focus { border-color: var(--gold); }
input:disabled { opacity: 0.5; }

/* Visually hidden, still read by search engines and screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-bottom: 1px solid var(--gold-dark);
  background: rgba(0, 0, 0, 0.3);
}
.incense-count b { color: var(--gold); font-size: 1.2rem; }

/* ---------- Temple layout ---------- */
.temple {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px;
}
@media (max-width: 860px) {
  .temple { grid-template-columns: 1fr; }
}

.altar-area { display: flex; flex-direction: column; align-items: center; text-align: center; }

.buddha {
  --statue-h: 280px; /* statue height; halo position/size scale with it */
  position: relative;
  margin-bottom: 8px;
}
@media (max-width: 600px) {
  .buddha { --statue-h: 220px; }
}
.halo {
  /* --luck (0-100) and --halo-alpha are set by JS from the luck % */
  position: absolute;
  left: 50%; /* behind the Buddha's head */
  top: calc(var(--statue-h) * 0.18);
  pointer-events: none;
  /* bigger luck -> bigger halo: ~0.61x statue height at 50%, ~0.96x at 100% */
  width: calc(var(--statue-h) * (0.26 + var(--luck, 50) * 0.007));
  height: calc(var(--statue-h) * (0.26 + var(--luck, 50) * 0.007));
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle,
    rgba(255, 240, 180, var(--halo-alpha, 0.5)) 0%,
    rgba(255, 210, 110, calc(var(--halo-alpha, 0.5) * 0.7)) 30%,
    rgba(255, 190, 80, calc(var(--halo-alpha, 0.5) * 0.25)) 55%,
    transparent 72%);
  transition: width 1s ease, height 1s ease;
  animation: glow 4s ease-in-out infinite;
}
.halo::before {
  content: "";
  position: absolute;
  inset: 32%;
  border-radius: 50%;
  border: 2px solid rgba(255, 225, 140, var(--halo-alpha, 0.5));
  box-shadow: 0 0 18px rgba(255, 215, 120, var(--halo-alpha, 0.5));
}
.buddha-img {
  position: relative;
  display: block;
  height: var(--statue-h);
  width: auto;
  margin: 0 auto;
  filter: drop-shadow(0 0 18px rgba(255, 215, 120, 0.35));
}
.altar-title { position: relative; color: var(--gold); letter-spacing: 2px; font-weight: 700; }

@keyframes glow {
  0%, 100% { opacity: 0.85; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
}

.altar {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 36px;
  /* Leave room above so the incense sticks don't cover the statue */
  margin-top: 90px;
  padding: 0 30px 12px;
  border-bottom: 12px solid var(--red);
  border-radius: 4px;
}

/* Candles */
.candle {
  position: relative;
  width: 18px;
  height: 70px;
  background: linear-gradient(90deg, #c4281a, #e44b33, #c4281a);
  border-radius: 3px;
}
.flame {
  position: absolute;
  left: 50%;
  top: -22px;
  width: 12px;
  height: 22px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at 50% 70%, #fff6b0, #ffb02e 50%, transparent 72%);
  border-radius: 50% 50% 40% 40%;
  animation: flicker 0.25s infinite alternate;
}
@keyframes flicker {
  from { transform: translateX(-50%) scale(1, 1); }
  to { transform: translateX(-50%) scale(0.9, 1.1); }
}

/* Incense burner */
.burner { position: relative; width: 200px; }
.bowl { display: block; width: 200px; height: 90px; position: relative; z-index: 2; }
.sticks {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 74px;
  height: 90px;
  z-index: 1;
}
/* Incense stick: body (burns down via --left) + red stub (remains) */
.stick {
  position: absolute;
  bottom: 0;
  width: 4px;
  height: 90px;
  margin-left: -2px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  transform: rotate(var(--tilt));
  transform-origin: bottom center;
}
.stick.new { animation: rise 0.8s ease-out; }
@keyframes rise {
  from { transform: translateY(40px) rotate(var(--tilt)); opacity: 0; }
  to { transform: rotate(var(--tilt)); opacity: 1; }
}
.stick-body {
  position: relative;
  height: calc(63px * var(--left, 1));
  background: #7a3b16;
  transition: height 1s linear;
}
.stick-foot {
  height: 27px;
  background: #c0392b;
}
.stick.burnt .stick-body { display: none; }
.stick.burnt .stick-foot { border-top: 2px solid #3a3a3a; }
.ember {
  position: absolute;
  top: -3px;
  left: -2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff5a1f;
  box-shadow: 0 0 8px 3px rgba(255, 110, 40, 0.8);
  animation: ember 1.2s ease-in-out infinite alternate;
}
@keyframes ember { from { opacity: 0.6; } to { opacity: 1; } }

.smoke {
  position: absolute;
  top: -10px;
  left: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(220, 220, 220, 0.35);
  filter: blur(4px);
  animation: smoke 3.5s linear infinite;
}
.smoke.s2 { animation-delay: 1.75s; }
@keyframes smoke {
  0% { transform: translate(0, 0) scale(0.6); opacity: 0.7; }
  50% { transform: translate(8px, -40px) scale(1.4); opacity: 0.35; }
  100% { transform: translate(-6px, -80px) scale(2); opacity: 0; }
}

.hint { color: var(--muted); max-width: 420px; }

/* ---------- Side ---------- */
.side { display: flex; flex-direction: column; gap: 18px; }

.fortune-empty, .wish-empty { color: var(--muted); font-style: italic; }
.f-cat { font-weight: 700; color: var(--gold); font-size: 1.05rem; }
.f-level {
  display: inline-block;
  margin: 8px 0;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--red);
  border: 1px solid var(--gold-dark);
  font-weight: 700;
}
.f-poem { font-style: italic; color: var(--gold); margin: 6px 0 10px; font-size: 1.05rem; }
.f-meaning { line-height: 1.55; }

.wish-list {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.wish {
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
  border-left: 3px solid var(--gold);
}
.wish-text { word-break: break-word; }
.wish-time { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.wish-form { display: flex; gap: 8px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.7);
  z-index: 10;
}
.modal-card { max-width: 420px; width: 100%; text-align: center; }
.modal-card .btn { margin-top: 16px; }
.hidden { display: none !important; }

/* ---------- Drawing a fortune (~5s): shake -> merit light flies in -> toss one stick out ---------- */
.shake-box { padding: 12px 0 4px; }
.shake-box p { margin: 14px 0 0; color: var(--gold); min-height: 1.4em; transition: opacity 0.2s; }
.tube {
  position: relative;
  display: inline-block;
  width: 94px;
  height: 180px;
  margin-top: 30px; /* room for the stick to fly up */
  transform-origin: 50% 92%;
}
/* Tube picture (assets/fortune-tube.png, from 15.png); the mouth is ~30% from its top */
.tube-img { position: relative; z-index: 1; display: block; width: 100%; height: 100%; transition: filter 0.3s; }
/* The stick that gets tossed out, drawn like the ones in the picture: light wood, red pointed tip */
.tube-fly {
  position: absolute;
  z-index: 0;
  left: 40px;
  top: 6px;
  width: 15px;
  height: 80px;
  background:
    radial-gradient(circle at 50% 13px, #f0c75e 0 3px, transparent 3.5px),
    linear-gradient(to bottom, #c23a22 0 24px, #e9cf98 24px, #d5ae6a);
  clip-path: polygon(50% 0, 100% 9%, 100% 100%, 0 100%, 0 9%);
  transform-origin: 50% 60%;
  opacity: 0;
}

/* ① gentle shake */
.shake-box.is-shaking .tube { animation: tube-shake 0.32s ease-in-out infinite; }
@keyframes tube-shake {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}
/* ② merit light arrives: the tube glows */
.shake-box.is-charged .tube-img {
  filter: drop-shadow(0 0 10px rgba(255, 214, 110, 0.95)) drop-shadow(0 0 24px rgba(255, 190, 80, 0.6));
}
.shake-box.is-charged .tube::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 50px;
  width: 140px;
  height: 140px;
  margin-left: -70px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 230, 150, 0.9), rgba(255, 200, 90, 0) 65%);
  animation: tube-flash 0.6s ease-out forwards;
  pointer-events: none;
}
@keyframes tube-flash {
  from { transform: scale(0.3); opacity: 1; }
  to { transform: scale(1.4); opacity: 0; }
}
/* ③ hard shake, then one stick flies out */
.shake-box.is-tossing .tube { animation: tube-toss 0.14s linear infinite; }
@keyframes tube-toss {
  0%, 100% { transform: rotate(-10deg) translateY(0); }
  25% { transform: rotate(0deg) translateY(-4px); }
  50% { transform: rotate(10deg) translateY(0); }
  75% { transform: rotate(0deg) translateY(-4px); }
}
.shake-box.is-out .tube { animation: none; transform: rotate(-4deg); transition: transform 0.2s; }
.shake-box.is-out .tube-fly { animation: stick-out 1s cubic-bezier(0.2, 0.7, 0.3, 1) forwards; }
/* rises out of the mouth behind the rim, flips over and lands to the right of the tube */
@keyframes stick-out {
  0% { opacity: 1; transform: translateY(20px) rotate(0); }
  25% { opacity: 1; transform: translate(4px, -70px) rotate(20deg); z-index: 0; }
  26% { z-index: 2; }
  60% { opacity: 1; transform: translate(40px, -80px) rotate(200deg); z-index: 2; }
  100% { opacity: 1; transform: translate(84px, 60px) rotate(250deg); z-index: 2; }
}

/* Merit light: a comet from the công đức score into the tube (positioned by app.js) */
.merit-orb {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, #fffbe6 0%, #ffe08a 35%, rgba(255, 190, 70, 0.5) 60%, rgba(255, 170, 50, 0) 72%);
  box-shadow: 0 0 18px 6px rgba(255, 210, 110, 0.7);
}
.luck-info.is-giving { animation: luck-give 0.7s ease-out; }
@keyframes luck-give {
  0% { filter: none; transform: scale(1); }
  40% { filter: drop-shadow(0 0 10px #ffd86e) brightness(1.4); transform: scale(1.08); }
  100% { filter: none; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .shake-box .tube,
  .shake-box.is-out .tube-fly { animation-duration: 0.01s !important; animation-iteration-count: 1 !important; }
}

/* ---------- Wish steps ---------- */
.step-label { font-size: 0.85rem; color: var(--muted); margin: 12px 0 6px; }
.step-label:first-of-type { margin-top: 0; }
.step-label b { color: var(--gold); }
.categories { display: flex; gap: 8px; flex-wrap: wrap; }
.cat-btn {
  flex: 1 1 0;
  min-width: 96px;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid var(--gold-dark);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  cursor: pointer;
}
/* Picture icon sized like the emoji next to it */
.cat-icon { width: 1.4em; height: 1.4em; vertical-align: -0.35em; object-fit: contain; }
.cat-btn .cat-icon { width: 1.6em; height: 1.6em; }
.cat-btn:hover:not(:disabled) { border-color: var(--gold); }
.cat-btn.selected {
  background: linear-gradient(180deg, #d6402b, var(--red));
  border-color: var(--gold);
  color: #fff4d6;
  box-shadow: 0 0 10px rgba(232, 198, 106, 0.4);
}
.cat-btn:disabled { opacity: 0.45; cursor: not-allowed; }
textarea#wish-input {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--gold-dark);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  outline: none;
  resize: vertical;
}
textarea#wish-input:focus { border-color: var(--gold); }
textarea#wish-input:disabled { opacity: 0.5; }

/* ---------- Hide side cards until there is a fortune ---------- */
.temple.solo { grid-template-columns: 1fr; }

/* ---------- Prayer cushion ---------- */
.cushion {
  position: relative;
  margin-top: 28px;
  width: 220px;
  height: 92px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}
.cushion-top {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 0;
  height: 70px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #f0c75e 0 7px, transparent 8px),
    repeating-radial-gradient(circle at 50% 50%, #a8261a 0 10px, #8b1a10 10px 12px);
  border: 3px solid var(--gold-dark);
  box-shadow: 0 10px 0 #5e120a, 0 14px 20px rgba(0, 0, 0, 0.5);
  transition: transform 0.2s, box-shadow 0.2s;
}
.cushion-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -14px;
  color: var(--gold);
  font-size: 0.95rem;
  font-weight: 700;
}
.cushion:hover:not(:disabled) .cushion-top {
  transform: translateY(-3px);
  box-shadow: 0 13px 0 #5e120a, 0 0 24px rgba(232, 198, 106, 0.6);
}
.cushion:not(:disabled) .cushion-top { animation: invite 2.4s ease-in-out infinite; }
.cushion:disabled { cursor: not-allowed; opacity: 0.5; }
@keyframes invite {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.2); }
}
.hint { margin-top: 26px; }

/* ---------- Prayer popup ---------- */
.pray-card { position: relative; }
.modal-x {
  position: absolute;
  top: 8px;
  right: 10px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}
.modal-x:hover { color: var(--gold); }
.pray-card h2 { margin-top: 6px; }
.pray-card .cat-btn { font-size: 1rem; padding: 14px 6px; line-height: 1.6; }
.pray-card textarea { margin-bottom: 12px; }
.row { display: flex; gap: 10px; justify-content: center; }
.pray-card .row .btn { margin-top: 0; }

/* ---------- Incense regen & claim ---------- */
.incense-count { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.regen-timer { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.buy-btn { text-decoration: none; }

/* ---------- Luck & auspicious day ---------- */
.luck-panel { margin-top: 26px; line-height: 1.6; }
.day-info { color: var(--muted); font-size: 0.9rem; }
.day-good { color: #8fdc8f; }
.day-normal { color: var(--gold); }
.day-bad { color: #ff8a7a; }
.luck-info { font-size: 1.1rem; margin-top: 4px; }
.luck-info b { color: var(--gold); }
.luck-bonus { color: var(--muted); font-size: 0.85rem; }
.luck-panel + .hint { margin-top: 10px; }

/* ---------- Merit box ---------- */
.merit-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: none;
  background: none;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
}
.merit-chest {
  position: relative;
  width: 64px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
  background: linear-gradient(180deg, #b3261a, #6e140c);
  border: 2px solid var(--gold-dark);
  border-radius: 6px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
  transition: box-shadow 0.2s, transform 0.2s;
}
.merit-slot {
  position: absolute;
  top: 6px;
  left: 50%;
  width: 26px;
  height: 4px;
  margin-left: -13px;
  border-radius: 2px;
  background: #2a0804;
}
.merit-coin { font-size: 22px; opacity: 0; transform: translateY(-10px); }
.merit-label { font-size: 0.75rem; color: var(--gold); text-align: center; line-height: 1.3; }
.merit-box:hover .merit-chest { box-shadow: 0 0 16px rgba(232, 198, 106, 0.6); transform: translateY(-2px); }
.merit-box.donated .merit-coin { animation: coin-drop 0.7s ease-in; }
@keyframes coin-drop {
  0% { opacity: 1; transform: translateY(-24px); }
  80% { opacity: 1; transform: translateY(14px); }
  100% { opacity: 0; transform: translateY(18px); }
}

/* Cushion centered. Merit box: desktop -> right of the altar table, mobile -> next to the cushion (moved by JS) */
.pray-row {
  position: relative;
  display: flex;
  justify-content: center;
  margin-top: 28px;
}
.pray-row .cushion { margin-top: 0; }
.altar { position: relative; }
.altar .merit-box {
  position: absolute;
  left: calc(100% + 50px); /* 50px from the table's right edge */
  top: calc(100% + 6px); /* box centered on the red line (table, 12px bottom border) */
  transform: translateY(-50%);
}
.pray-row .merit-box {
  position: absolute;
  bottom: 0;
  left: calc(50% + 140px); /* half of 220px cushion + 30px */
}
@media (max-width: 480px) {
  .pray-row .cushion { width: 170px; }
  .pray-row .merit-box { left: calc(50% + 115px); } /* half of 170px cushion + 30px */
}
.buy-btn.cooldown { opacity: 0.5; cursor: not-allowed; pointer-events: auto; font-variant-numeric: tabular-nums; }
.merit-box.cooldown { cursor: not-allowed; }
.merit-box.cooldown .merit-chest { opacity: 0.5; }
.merit-box.cooldown .merit-label { font-variant-numeric: tabular-nums; }

/* ---------- Wish & fortune log ---------- */
.wish-main { flex: 1; min-width: 0; }
.wish-fortune { margin-top: 6px; font-size: 0.9rem; }
.wish-fortune summary { cursor: pointer; color: var(--gold); font-style: italic; line-height: 1.5; }
.wish-fortune .f-meaning { margin-top: 6px; font-size: 0.85rem; color: var(--text); }
.f-level.small { font-size: 0.75rem; padding: 0 8px; margin: 0 4px 0 0; font-style: normal; }
.wish-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.wish-foot .wish-time { margin-top: 0; }
.wish-share {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--gold-dark);
  background: transparent;
  color: var(--gold);
  cursor: pointer;
}
.wish-share:hover { background: rgba(232, 198, 106, 0.12); }
.share-open { margin-top: 12px; }
.modal-actions { margin-top: 16px; }
.modal-actions .btn { margin-top: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--gold-dark);
  background: #2a0c06;
  color: var(--text);
  font-size: 0.9rem;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Pointing finger guiding players to the cushion (hidden when out of incense) */
.cushion-pointer {
  position: absolute;
  left: -46px;
  top: 14px;
  font-size: 34px;
  pointer-events: none;
  animation: point 1s ease-in-out infinite;
}
.cushion:disabled .cushion-pointer { display: none; }
@keyframes point {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(10px); }
}

/* ---------- Fortune image viewer ---------- */
#card-modal { background: rgba(0, 0, 0, 0.85); z-index: 15; }
.card-viewer { position: relative; background: #2a0c06; max-height: calc(100vh - 32px); overflow-y: auto; }
.card-img {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  margin-top: 18px;
  border-radius: 8px;
  -webkit-touch-callout: default; /* allow long-press "Save image" on iOS */
}
.card-hint { font-size: 0.85rem; color: var(--muted); margin: 12px 0; }
#card-download { display: inline-block; text-decoration: none; }

/* ---------- Rewarded ad opt-in ---------- */
#reward-modal { z-index: 16; }
.reward-icon { font-size: 44px; }
.reward-text { font-size: 1.05rem; line-height: 1.5; margin: 8px 0 16px; }

/* ---------- Temple gate: sweeping leaves ---------- */
.gate-btn { margin-top: 12px; }
#gate-screen.active { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.sweep-hud { font-size: 0.95rem; }
.sweep-hud b { color: var(--gold); font-size: 1.15rem; }
.sweep-progress { height: 6px; background: rgba(0, 0, 0, 0.4); }
.sweep-bar { height: 100%; width: 0; background: linear-gradient(90deg, #7f9a2e, var(--gold)); transition: width 0.2s; }
.gate-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.sweep-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: none; }
.sweep-tip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: rgba(246, 231, 193, 0.8);
  pointer-events: none;
}
.sweep-msg {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(320px, calc(100% - 32px));
  padding: 20px;
  border-radius: 14px;
  border: 1px solid var(--gold-dark);
  background: rgba(42, 12, 6, 0.95);
  text-align: center;
  line-height: 1.6;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.sweep-msg b { color: var(--gold); }
.sweep-msg .btn { margin-top: 12px; }
.sweep-wait { font-size: 1.6rem; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.sweep-msg .sweep-back { display: block; margin: 14px auto 0; }

/* ---------- Main hall background (assets/main.jpg) ----------
   The picture is pinned at a fixed height so its features line up with the items:
   the red wall sits behind the statue and the statue's lotus rests on the steps
   (steps at ~52% of the picture height). Lower down, a dark fade keeps the text readable. */
.altar-area {
  --hall-h: 720px; /* displayed height of the hall picture */
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  padding: 100px 16px 24px; /* statue top: steps (0.52 * 720) - lotus bottom (0.93 * 280) */
  background:
    /* fade sized to the picture: it ends fully opaque exactly where the picture ends, so there is no seam */
    linear-gradient(to bottom, rgba(42, 12, 6, 0) 55%, rgba(42, 12, 6, 0.55) 80%, #2a0c06 100%) center top / 100% var(--hall-h) no-repeat,
    url("assets/main.jpg") center top / auto var(--hall-h) no-repeat,
    #2a0c06;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.altar-title,
.cushion-label,
.merit-label,
.day-info,
.luck-info { text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9); }
@media (max-width: 600px) {
  .temple { padding: 12px 8px; }
  .altar-area {
    --hall-h: 560px;
    padding: 84px 8px 20px; /* (0.52 * 560) - (0.93 * 220) */
  }
}
/* Incense sticks may overlap the steps (they stand in front of them), so the altar can sit closer */
.altar-area .altar { margin-top: 64px; }
@media (max-width: 600px) {
  .altar-area .altar { margin-top: 56px; }
  .altar-area .pray-row { margin-top: 18px; }
  .altar-area .luck-panel { margin-top: 18px; }
  .altar-area .gate-btn { margin-top: 8px; }
}

/* ---------- Full-screen main hall ----------
   The hall picture spans the full width. --hall-h is its displayed height (it grows on wide screens);
   the statue scales with it so its lotus always rests on the steps (steps at 52% of the picture). */
.temple {
  display: block;
  max-width: none;
  margin: 0;
  padding: 0;
  position: relative;
}
.altar-area {
  --hall-h: max(720px, calc(100vw * 941 / 1672));
  border-radius: 0;
  box-shadow: none;
  /* statue top = steps (0.52) - lotus bottom (0.93 * statue height 0.39) */
  padding: calc(var(--hall-h) * 0.157) 16px 28px;
}
.altar-area .buddha { --statue-h: calc(var(--hall-h) * 0.39); }
.side { padding: 16px; max-width: 720px; margin: 0 auto; }
@media (min-width: 1352px) {
  /* Wide screens: fortune card + log float on the right, over the hall */
  .side {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 360px;
    max-width: none;
    margin: 0;
    padding: 0;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }
}
@media (max-width: 600px) {
  .temple { padding: 0; }
  .altar-area {
    --hall-h: 560px;
    padding: calc(var(--hall-h) * 0.157) 8px 20px;
  }
}

/* "Phật Pháp Vô Biên" on the wooden board above the red wall (board y 38–82 of 941 -> centre ~6.4%),
   i.e. above the Buddha's head. Relative to .buddha, whose top is at 15.7% of the picture. */
.altar-area .altar-title {
  position: absolute;
  left: 50%;
  top: calc(var(--hall-h) * -0.093);
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-size: calc(var(--hall-h) * 0.024);
  letter-spacing: 0.15em;
  color: #f3d27a;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 10px rgba(0, 0, 0, 0.6);
}
/* keep the old gap so the incense sticks stay in front of the steps */
.altar-area .buddha { margin-bottom: 28px; }

/* ---------- Altar table picture (assets/table.png) ----------
   Candles and the incense bowl stand on the table top (~24% down the picture). */
.altar {
  --table-w: 440px;
  --table-h: calc(var(--table-w) * 195 / 900);
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: calc(var(--table-h) * 0.76);
}
.altar-table {
  position: absolute;
  left: 50%;
  bottom: calc(var(--table-h) * -0.76);
  width: var(--table-w);
  transform: translateX(-50%);
  pointer-events: none;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.5));
}
.altar > .candle,
.altar > .burner { z-index: 1; }
.altar .merit-box {
  left: calc(50% + var(--table-w) / 2 + 30px); /* 30px right of the table */
  top: calc(100% + var(--table-h) * 0.25); /* level with the table body */
}

/* ---------- Prayer cushion picture (assets/cushion.png) ----------
   The picture is a top view; squashing it to ~52% height makes it lie on the floor, seen at an angle. */
.cushion { height: 118px; }
.cushion-top {
  height: 108px;
  border: none;
  border-radius: 0;
  background: url("assets/cushion.png") center / 100% 100% no-repeat;
  box-shadow: none;
  filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.55));
}
.cushion:hover:not(:disabled) .cushion-top { box-shadow: none; filter: drop-shadow(0 0 14px rgba(232, 198, 106, 0.7)); }
.cushion-pointer { top: 34px; }

@media (max-width: 600px) {
  .altar { --table-w: min(380px, calc(100vw - 24px)); }
  .pray-row .cushion { height: 96px; }
  .pray-row .cushion .cushion-top { height: 86px; }
  .cushion-pointer { top: 24px; }
}
@keyframes invite {
  0%, 100% { filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.55)) brightness(1); }
  50% { filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.55)) brightness(1.15); }
}
@media (max-width: 600px) {
  .altar-area .pray-row { margin-top: 4px; }
  .altar-area .luck-panel { margin-top: 12px; }
}

/* ---------- Censer picture (assets/censer.png) ----------
   Picture height = 0.649 x width. Sticks stand in the ash; their feet are hidden behind
   the front lip (lip lower edge ~70% up from the bottom of the picture). */
.burner { --bowl-w: 200px; width: var(--bowl-w); }
.bowl { width: var(--bowl-w); height: auto; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.45)); }
.sticks { bottom: calc(var(--bowl-w) * 0.649 * 0.66); }
@media (max-width: 600px) {
  .burner { --bowl-w: 170px; }
}
.sticks { bottom: calc(var(--bowl-w) * 0.649 * 0.72); }
@media (max-width: 600px) {
  .burner { --bowl-w: 150px; }
}

/* Censer in two layers so the sticks look planted in the ash:
   back layer (whole censer) < sticks < front layer (cut at the middle of the ash, 17.5% from the top) */
.bowl { position: relative; z-index: 0; }
.sticks { z-index: 1; bottom: calc(var(--bowl-w) * 0.649 * 0.80); }
.bowl-front {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  clip-path: inset(17.5% 0 0 0);
  filter: none;
}

/* ---------- Candle picture (assets/candle.png, height = 3.46 x width, wick at the top centre) ---------- */
.candle {
  --candle-w: 28px;
  width: var(--candle-w);
  height: calc(var(--candle-w) * 3.46);
  border-radius: 0;
  background: url("assets/candle.png") center / 100% 100% no-repeat;
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.45));
}
.candle .flame { left: 51.4%; top: -20px; width: 13px; height: 24px; }
@media (max-width: 600px) {
  .candle { --candle-w: 22px; }
}
@media (max-width: 600px) {
  .altar-area .luck-panel { margin-top: 6px; }
}

/* "▶ QC" badge: this button plays a rewarded ad (shown only when ads are on) */
.ad-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  background: #ffd23f;
  color: #3a120a;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.02em;
  vertical-align: middle;
  text-shadow: none;
}
.merit-box { position: relative; }
.merit-ad { display: none; position: absolute; top: -8px; right: -12px; z-index: 1; }
.ads-on .merit-ad { display: inline-block; }
.merit-box.cooldown .merit-ad { opacity: 0.5; }
.merit-ad { top: -9px; right: -18px; }
.merit-label { white-space: nowrap; }

/* ---------- Sound toggle ---------- */
.sound-btn {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 12;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--gold-dark);
  background: rgba(42, 12, 6, 0.85);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.sound-btn:hover { border-color: var(--gold); }

/* ---------- Merit box picture (assets/merit-box.png, height = 1.287 x width) ---------- */
.merit-chest {
  --chest-w: 72px;
  width: var(--chest-w);
  height: calc(var(--chest-w) * 1.287);
  padding: 0;
  border: none;
  border-radius: 0;
  background: url("assets/merit-box.png") center / 100% 100% no-repeat;
  box-shadow: none;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.5));
}
.merit-box:hover .merit-chest { box-shadow: none; filter: drop-shadow(0 0 12px rgba(232, 198, 106, 0.75)); }
.merit-box.cooldown .merit-chest { opacity: 0.6; }
.merit-ad { top: -6px; right: -16px; }
/* Desktop: stand on the floor next to the table (chest bottom level with the table feet) */
.altar .merit-box {
  top: auto;
  bottom: calc(var(--table-h) * -0.76 - 20px);
  transform: none;
}
@media (max-width: 600px) {
  .merit-chest { --chest-w: 58px; }
}
@media (max-width: 600px) {
  .pray-row .cushion-label { bottom: -2px; }
  .altar-area .luck-panel { margin-top: 14px; }
}

/* ---------- Incense stick pictures (assets/incense-body.png + incense-foot.png, cut from 11.png) ----------
   The red body is anchored at the bottom, so as its height shrinks the top burns away;
   the bamboo foot (chân hương) stays once the stick has burned out. */
.stick { width: 6px; margin-left: -3px; }
.stick-body {
  background: url("assets/incense-body.png") center bottom / 100% 63px no-repeat;
}
.stick-foot {
  background: url("assets/incense-foot.png") center top / 100% 100% no-repeat;
}
.stick.burnt .stick-foot { border-top: none; box-shadow: inset 0 3px 0 -1px #2a2a2a; }
.stick .ember { left: -1px; }
.stick .smoke { left: -5px; }

/* The statue picture is square: give it (and its wrapper) an explicit width so the wrapper is exactly
   as wide as the picture. iOS Safari mis-sizes "width: auto" with a calc() height, which made the
   wrapper narrower than the picture and pushed the centred halo to the left of the head. */
.altar-area .buddha { width: var(--statue-h); }
.altar-area .buddha-img { width: var(--statue-h); height: var(--statue-h); max-width: none; }

/* ---------- Language switcher: flag at the top right ---------- */
.lang-switch {
  position: absolute; /* scrolls away with the top bar */
  top: 9px;
  right: 12px;
  z-index: 15;
}
.topbar { padding-right: 84px; } /* keep the top bar's content clear of the flag */
.lang-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 7px;
  border-radius: 8px;
  border: 1px solid var(--gold-dark);
  background: rgba(42, 12, 6, 0.85);
  color: var(--gold);
  cursor: pointer;
  font: inherit;
}
.lang-btn:hover,
.lang-btn[aria-expanded="true"] { border-color: var(--gold); }
.lang-caret { font-size: 0.75rem; }
.flag {
  display: inline-block;
  width: 27px;
  height: 18px;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  flex: none;
}
.flag svg { display: block; width: 100%; height: 100%; }
.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--gold-dark);
  background: #2a0c06;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}
.lang-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.lang-opt:hover { background: rgba(232, 198, 106, 0.12); }
.lang-opt[aria-selected="true"] { color: var(--gold); font-weight: 700; }

/* ---------- Footer links (main page + info pages) ---------- */
.site-footer {
  padding: 20px 16px 72px; /* bottom room for the sound button */
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}
.site-footer nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; margin-bottom: 6px; }
.site-footer a { color: var(--gold); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.site-footer p { margin: 0; }

/* ---------- Info pages: about / contact / privacy / 404 ---------- */
.info-page .page-topbar { justify-content: flex-start; }
.info-page .page-topbar .btn { text-decoration: none; }
.page {
  max-width: 760px;
  margin: 24px auto 0;
  padding: 24px 28px;
  line-height: 1.7;
}
@media (max-width: 600px) {
  .page { margin: 12px 12px 0; padding: 18px 16px; }
}
.page h1 { font-size: 1.6rem; margin-bottom: 8px; }
.page h2 { font-size: 1.15rem; margin: 26px 0 8px; }
.page p, .page li { color: var(--text); }
.page ul { padding-left: 22px; }
.page li { margin-bottom: 6px; }
.page a:not(.btn) { color: var(--gold); }
.page-meta { color: var(--muted) !important; font-size: 0.9rem; margin-top: 0; }
/* Show only the block in the current language (i18n.js sets <html lang>) */
html:not([lang="en"]) .i18n-block[lang="en"],
html[lang="en"] .i18n-block[lang="vi"] { display: none; }

.contact-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 20px 0;
  padding: 20px;
  border: 1px solid var(--gold-dark);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
  text-align: center;
}
.contact-label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; }
.contact-email { font-size: 1.2rem; font-weight: 700; word-break: break-all; }
.contact-box .btn { text-decoration: none; }

.notfound { text-align: center; margin-top: 12vh; }
.notfound-icon { font-size: 64px; }
.notfound .btn { display: inline-block; margin-top: 12px; text-decoration: none; }
