: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; }

/* ---------- Login ---------- */
#login-screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.login-card { max-width: 420px; width: 100%; text-align: center; padding: 32px 24px; }
.lotus { font-size: 64px; }
.intro { color: var(--text); margin: 0 0 10px; line-height: 1.5; }
.sub { color: var(--muted); margin-bottom: 24px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }

/* ---------- 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 { position: relative; margin-bottom: 8px; }
.halo {
  /* --halo-size, --halo-alpha are set by JS from the luck % */
  position: absolute;
  left: 50%;
  top: 58px; /* level with the statue's head */
  width: var(--halo-size, 200px);
  height: var(--halo-size, 200px);
  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: 340px;
  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; }

.tube { font-size: 72px; animation: shake 0.3s infinite; display: inline-block; }
@keyframes shake {
  0%, 100% { transform: rotate(-12deg); }
  50% { transform: rotate(12deg); }
}

/* ---------- 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;
}
.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;
  text-decoration: none;
  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; }
