*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --blue:       #003087;
  --blue-mid:   #1A4FAA;
  --blue-light: #3A72CC;
  --gold:       #C89A18;
  --gold-light: #F0C040;
  --orange:     #E07820;
  --orange-dk:  #B85808;
  --cream:      #FEF7E8;
  --brick:      #C87040;
  --brick-dk:   #9A5028;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Be Vietnam Pro', sans-serif;
  background: var(--cream);
  color: #333;
  overflow-x: hidden;
}

.enter-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #FFF6DE, var(--cream) 48%, #F2D9A8);
}
.enter-screen.hide { display: none; }
.enter-card {
  width: min(100%, 360px);
  padding: 28px 22px;
  text-align: center;
  border: 2px solid var(--gold);
  border-radius: 18px;
  background: rgba(255,255,255,0.82);
  box-shadow: 0 18px 60px rgba(0,48,135,0.22);
}
.enter-mark { font-size: 42px; margin-bottom: 8px; }
.enter-card h1 {
  font-family: 'Baloo 2', cursive;
  font-size: 38px;
  color: var(--blue);
  line-height: 1;
}
.enter-card p { margin: 8px 0 20px; color: #87662A; font-weight: 600; }
.enter-btn { margin-top: 4px; }

/* ══ TOP TICKER (sticky, full-width) ══════════════ */
.ticker-top {
  position: sticky;
  top: 0;
  z-index: 80;
  width: 100%;
  overflow: hidden;
  background: var(--blue);
  padding: 9px 0;
  border-bottom: 2px solid var(--gold);
}

.ticker-track {
  display: flex;
  gap: 48px;
  white-space: nowrap;
  animation: tickerScroll 30s linear infinite;
}

.t-item {
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
  opacity: 0.92;
}
.t-item::before { content: '🙏  '; }

@keyframes tickerScroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

/* ══ CANVAS ═══════════════════════════════════════ */
#pcanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 70;
}

/* ══ PAGE ═════════════════════════════════════════ */
.page {
  position: relative;
  z-index: 2;
  max-width: 600px;
  margin: 0 auto;
  padding: 28px 16px 80px;
}

/* ══ ROOF ══════════════════════════════════════════ */
.roof-outer {
  position: relative;
  height: 72px;
  margin: 0 36px;
  overflow: visible;
}
.roof-body {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, var(--blue-mid), var(--blue));
  clip-path: polygon(0% 100%, 4% 70%, 12% 38%, 24% 16%, 50% 0%, 76% 16%, 88% 38%, 96% 70%, 100% 100%);
}
.roof-tiles {
  position: absolute; inset: 0;
  clip-path: polygon(0% 100%, 4% 70%, 12% 38%, 24% 16%, 50% 0%, 76% 16%, 88% 38%, 96% 70%, 100% 100%);
  background: repeating-linear-gradient(180deg, transparent 0px, transparent 7px, rgba(255,255,255,0.07) 7px, rgba(255,255,255,0.07) 10px);
}
.roof-ridge {
  position: absolute;
  top: -6px; left: 50%; transform: translateX(-50%);
  width: 72px; height: 14px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  border-radius: 7px 7px 2px 2px;
  z-index: 3;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.roof-ridge::before, .roof-ridge::after {
  content: '';
  position: absolute;
  top: 2px;
  width: 8px; height: 8px;
  background: var(--gold-light);
  border-radius: 50%;
}
.roof-ridge::before { left: 6px; }
.roof-ridge::after  { right: 6px; }

.eave {
  position: absolute;
  bottom: 0;
  width: 30px; height: 30px;
  border-radius: 0 50% 0 50%;
  background: var(--gold);
}
.eave-l { left: -15px; transform: rotate(90deg); }
.eave-r { right: -15px; }

.passed {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  background: linear-gradient(135deg, #F5A623, var(--orange-dk));
  color: #fff;
  font-family: 'Baloo 2', cursive;
  font-size: 30px; font-weight: 800;
  letter-spacing: 3px;
  padding: 2px 22px 4px;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  text-shadow: 1px 2px 4px rgba(0,0,0,0.3);
}

/* ══ GATE BODY ════════════════════════════════════ */
.gate-body { display: flex; height: 150px; }

.col {
  width: 38px;
  background: linear-gradient(180deg, var(--blue-mid), var(--blue));
  border-top: 5px solid var(--gold);
  position: relative; flex-shrink: 0;
}
.col::after {
  content: '';
  position: absolute;
  top: 16px; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 3px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
}

.lantern { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; }
.lan-hook { width: 2px; height: 6px; background: var(--gold); }
.lan-cap  { width: 18px; height: 5px; background: var(--gold); border-radius: 3px 3px 0 0; }
.lan-body {
  width: 16px; height: 22px;
  background: radial-gradient(ellipse at 35% 35%, #FF7044, #AA2200);
  border-radius: 3px 3px 5px 5px;
}
.lan-tassel { width: 2px; height: 8px; background: var(--gold); }

.gate-center {
  flex: 1;
  background: linear-gradient(180deg, #FFFCF3, #FFF6DE);
  border-top: 5px solid var(--gold);
  border-bottom: 4px solid var(--gold);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px; padding: 10px 8px;
}

.school-logo { height: 50px; width: auto; object-fit: contain; }
.logo-fallback {
  width: 52px; height: 52px;
  background: var(--blue); color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Baloo 2', cursive; font-size: 15px; font-weight: 800;
}

/* ══ ALTAR TABLE ══════════════════════════════════ */
.altar-table { position: relative; margin: 0 4px; padding-bottom: 205px; }
.table-img {
  position: absolute;
  left: 50%; bottom: 0;
  width: min(100%, 430px); height: auto;
  transform: translateX(-50%);
  z-index: 0;
}

.shelf {
  position: relative;
  z-index: 1;
  padding: 14px 24px 10px;
  display: flex; align-items: flex-end;
  justify-content: center; gap: 24px;
}

.vase { display: flex; flex-direction: column; align-items: center; }
.vase-bloom { font-size: 30px; line-height: 1; margin-bottom: 2px; }
.vase-neck  { width: 14px; height: 12px; background: linear-gradient(135deg, #D0C0F0, #A890D0); border-radius: 2px 2px 0 0; }
.vase-belly { width: 22px; height: 26px; background: linear-gradient(135deg, #E0D0FF, #C0A8E8); border-radius: 4px 4px 8px 8px; }
.vase-foot  { width: 24px; height: 5px;  background: #A890D0; border-radius: 0 0 4px 4px; }

/* ── Incense burner ─────────────────────────────── */
.burner {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  transition: transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: bottom center;
}

/* PNG burner crop wrapper
   Scale=0.301 (width 120/399px burner). No top crop (top=0) so sticks in
   bat-huong-khan.png (tips at y≈50) are visible. Crop bottom at y≈700.
   Rendered image: 411×231px (768×0.301=231). Crop from y=30 → top: -9px. */
.burner-wrap {
  width: 120px;
  height: 200px;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}
.burner-img {
  position: absolute;
  width: 411px;
  height: auto;
  left: -145px;
  top: -9px;
}

/* Smoke reference container (invisible, for canvas getBoundingClientRect)
   Bowl rim at y=395 original → (395-30)×0.301=110px from container top
   placed-wrap bottom: 200-110=90px from burner bottom */
.placed-wrap {
  position: absolute;
  bottom: 90px;
  left: 50%; transform: translateX(-50%);
  width: 72px;
  pointer-events: none;
  z-index: 6;
}

.bur-rim {
  position: absolute;
  top: 110px; left: 50%; transform: translateX(-50%);
  width: 60px; height: 2px; opacity: 0;
  pointer-events: none; z-index: 0;
}

/* ══ ALTAR WRAP ════════════════════════════════════ */
.altar-wrap {
  width: 100%; max-width: 460px;
  margin: 0 auto 28px;
  user-select: none;
  filter: drop-shadow(0 8px 32px rgba(0,48,135,0.18));
}

/* ══ STATS ════════════════════════════════════════ */
.stats { text-align: center; margin-bottom: 20px; color: #888; font-size: 15px; }
.stats b { font-family: 'Baloo 2', cursive; font-size: 28px; color: var(--blue); font-weight: 800; }

/* ══ FORM ═════════════════════════════════════════ */
.form-wrap { max-width: 460px; margin: 0 auto 20px; }
.field { margin-bottom: 12px; }
.field input, .field textarea {
  width: 100%; padding: 14px 16px;
  border: 2px solid #E0CFA8; border-radius: 10px;
  background: #fff;
  font-family: 'Be Vietnam Pro', sans-serif; font-size: 15px; color: #333;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input::placeholder, .field textarea::placeholder { color: #C0B090; }
.field input:focus, .field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(0,48,135,0.1);
}
.field textarea { min-height: 100px; resize: vertical; }

.turn-info {
  text-align: center; font-size: 13px; color: #999;
  margin-bottom: 8px; min-height: 18px;
}

.btn-pray {
  display: block; width: 100%; padding: 16px;
  background: linear-gradient(135deg, var(--orange), var(--orange-dk));
  color: #fff; border: none; border-radius: 10px;
  font-family: 'Baloo 2', cursive; font-size: 20px; font-weight: 700;
  letter-spacing: 3px; cursor: pointer;
  box-shadow: 0 5px 20px rgba(224,120,32,0.45);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-pray:hover:not(:disabled)  { transform: translateY(-3px); box-shadow: 0 8px 28px rgba(224,120,32,0.55); }
.btn-pray:disabled { opacity: 0.7; cursor: default; }

.upsell-btn {
  display: none;
  width: 100%; margin-top: 10px; padding: 14px;
  background: linear-gradient(135deg, var(--blue-mid), var(--blue));
  color: #fff; border: none; border-radius: 10px;
  font-family: 'Baloo 2', cursive; font-size: 16px; font-weight: 700;
  letter-spacing: 1px; cursor: pointer;
  box-shadow: 0 5px 20px rgba(0,48,135,0.35);
  transition: transform 0.15s;
  align-items: center; justify-content: center; gap: 8px;
}
.upsell-btn.visible { display: flex; }
.upsell-btn:hover { transform: translateY(-2px); }

/* ══ FLYING STICK OVERLAY ═════════════════════════ */
.huong-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 400; }

/* cay-nhang.png as flying element (1366×768 transparent PNG, sticks in center)
   Display at height:140px → width=1366×(140/768)=249px
   Sticks center x in image ≈ 50% → ~125px from left
   Stick base at y≈670 → 670/768×140≈122px from top */
.h-stick {
  position: fixed;
  height: 140px;
  width: auto;
  opacity: 0; pointer-events: none;
  --travel: 260px;
}
.h-stick.go { animation: stickFly 1.8s cubic-bezier(0.33,1,0.68,1) forwards; }
@keyframes stickFly {
  0%   { opacity: 0;   transform: translateY(0); }
  12%  { opacity: 1; }
  80%  { opacity: 1;   transform: translateY(var(--travel)); }
  95%  { opacity: 0.4; transform: translateY(var(--travel)); }
  100% { opacity: 0;   transform: translateY(var(--travel)); }
}

/* ══ MUSIC BUTTON ═════════════════════════════════ */
.music-btn {
  position: fixed; bottom: 24px; right: 20px;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--blue); color: white;
  border: 2px solid var(--gold); font-size: 22px;
  cursor: pointer; z-index: 200;
  box-shadow: 0 4px 18px rgba(0,48,135,0.4);
  transition: transform 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.music-btn:hover { transform: scale(1.12); }
.music-btn.on {
  background: linear-gradient(135deg, var(--blue-mid), var(--blue));
  animation: mPulse 2s ease-in-out infinite;
}
@keyframes mPulse {
  0%,100% { box-shadow: 0 4px 18px rgba(0,48,135,0.4); }
  50%     { box-shadow: 0 4px 28px rgba(200,154,24,0.7); }
}

/* ══ TOAST ════════════════════════════════════════ */
.toast {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-120px);
  background: linear-gradient(135deg, #1A6B40, #2E9960);
  color: #fff; padding: 14px 28px; border-radius: 50px;
  font-weight: 600; font-size: 15px; z-index: 999;
  white-space: nowrap;
  box-shadow: 0 8px 28px rgba(0,0,0,0.25);
  transition: transform 0.45s cubic-bezier(0.34,1.56,0.64,1);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: linear-gradient(135deg, #A02020, #CC4444); }

@keyframes shake {
  0%,100%{transform:translateX(0)}
  20%,60%{transform:translateX(-6px)}
  40%,80%{transform:translateX(6px)}
}

/* ══ RESPONSIVE ═══════════════════════════════════ */
@media (max-width: 480px) {
  .passed { font-size: 22px; letter-spacing: 2px; padding: 2px 16px 3px; }
  .gate-body { height: 130px; }
  .school-logo { height: 42px; }
  .music-btn { bottom: 16px; right: 14px; width: 48px; height: 48px; font-size: 20px; }
}
