:root {
  --cream: #fffaf3; --cream2: #fff6ea; --sand: #f0dcc2; --line: #eadccb;
  --brown: #4a3226; --brown2: #6b4428; --ink: #3c1e0a;
  --orange: #e8834a; --orange2: #d9733b;
  --glass: rgba(40, 28, 22, .55);
  font-family: Nunito, system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #15100d; color: var(--brown); -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; border: 0; }
h2, h3, .serif { font-family: Fraunces, Georgia, serif; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* intro */
#intro { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 22px;
  background: radial-gradient(circle at 50% 40%, #2a201b, #120d0b 70%); transition: opacity .9s; text-align: center; padding: 16px; }
#intro.out { opacity: 0; pointer-events: none; }
.quote { font-family: Fraunces, serif; font-style: italic; font-size: clamp(20px, 3.4vw, 30px); color: #f4e6d4; line-height: 1.35; margin: 0; }
.ghost { background: rgba(255,255,255,.04); color: #f4e6d4; border: 1px solid rgba(244,200,150,.35); padding: 12px 22px; border-radius: 999px;
  font-weight: 800; box-shadow: 0 0 24px rgba(232,131,74,.25); }
.ghost:disabled { opacity: .6; cursor: default; }
.flame { width: 18px; height: 34px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(ellipse at 50% 70%, #fff7d6 0 25%, #ffc062 45%, #e8834a 80%);
  box-shadow: 0 0 30px 12px rgba(255,170,80,.35), 0 0 120px 50px rgba(255,140,60,.12); animation: flick 2.4s infinite ease-in-out; }
.flame.big { width: 22px; height: 40px; }
@keyframes flick { 0%,100% { transform: scale(1) rotate(-1deg); } 30% { transform: scale(1.04, .96) rotate(2deg); } 60% { transform: scale(.97, 1.05) rotate(-2deg); } }

/* HUD */
#hud { position: fixed; top: 0; left: 0; right: 0; z-index: 10; padding: max(10px, env(safe-area-inset-top)) 12px 0; pointer-events: none; }
#hud .row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
#hud .row > * { pointer-events: auto; }
.spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: 6px; color: #fff6ea; text-decoration: none; font-family: Fraunces, serif; font-weight: 600; font-size: 20px; text-shadow: 0 1px 6px rgba(0,0,0,.5); }
.brand img { width: 26px; height: 26px; }
.primary { background: var(--orange); color: #fff; font-weight: 800; padding: 10px 18px; border-radius: 999px; box-shadow: 0 4px 14px rgba(232,131,74,.35); }
.primary:hover { background: var(--orange2); }
.pill, .chip { border-radius: 999px; font-weight: 700; font-size: 14px; padding: 8px 12px; display: inline-flex; align-items: center; gap: 4px; }
.dark { background: var(--glass); color: #fff6ea; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #5fd36a; box-shadow: 0 0 6px #5fd36a; margin-right: 4px; }
.avatar { width: 22px; height: 22px; border-radius: 50%; background: var(--orange); display: inline-grid; place-items: center; font-size: 12px; margin-right: 4px; }
.anniv { background: rgba(255,246,234,.85); color: var(--ink); display: block; max-width: min(520px,100%); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; margin-bottom: 8px; pointer-events: auto; }
.ticker { max-width: min(520px, 100%); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; animation: fade .6s; }
@keyframes fade { from { opacity: 0; transform: translateY(-4px); } }
#hint { position: fixed; bottom: max(14px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 9; color: #fff6ea;
  background: var(--glass); padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap; pointer-events: none; }

/* modal */
.backdrop { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(20,12,8,.35); padding: 16px; animation: fade .25s; }
.card { position: relative; width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--cream); border-radius: 22px;
  padding: 22px 20px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.35); border: 1px solid var(--line); }
.card h2 { margin: 0 0 4px; font-size: 24px; text-align: center; color: var(--ink); }
.card .sub { text-align: center; margin: 0 0 16px; color: var(--brown2); }
.close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border-radius: 50%; background: var(--cream2); color: var(--brown); font-size: 16px; border: 1px solid var(--line); }
.step { display: flex; gap: 12px; align-items: center; background: var(--sand); background: #f6e7d3; border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; font-weight: 700; }
.step span:first-child { font-size: 20px; }
.btn-block { display: block; width: 100%; margin-top: 10px; padding: 13px; border-radius: 14px; font-weight: 800; }
.btn-soft { background: var(--cream2); color: var(--brown); border: 1px solid var(--line); }
.btn-soft:hover { background: #fbeedd; }
label { display: block; font-weight: 700; font-size: 14px; margin: 10px 0 4px; }
input, textarea { width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font: inherit; color: var(--ink); }
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid rgba(232,131,74,.45); border-color: var(--orange); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-pick { display: grid; place-items: center; height: 170px; border: 2px dashed var(--sand); border-radius: 16px; background: var(--cream2) center/cover no-repeat; cursor: pointer; color: var(--brown2); font-weight: 700; }
.err { color: #c0392b; font-weight: 700; font-size: 14px; min-height: 18px; margin-top: 6px; }

/* memorial view */
.portrait { width: 100%; aspect-ratio: 4/5; max-height: 300px; object-fit: cover; border-radius: 14px; border: 6px solid #fff; box-shadow: 0 6px 20px rgba(0,0,0,.15); background: #efe2d0; }
.mname { font-family: Fraunces, serif; font-size: 26px; text-align: center; margin: 12px 0 0; color: var(--ink); }
.dates { text-align: center; color: var(--brown2); font-weight: 700; }
.msg { font-family: Fraunces, serif; font-style: italic; text-align: center; margin: 10px 0; }
.by { text-align: center; font-size: 13px; color: var(--brown2); }
.stats { display: flex; justify-content: center; gap: 16px; margin: 12px 0; font-weight: 800; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .primary, .actions .btn-soft { border-radius: 14px; padding: 12px; }
.offer-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; }
.offer { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; font-weight: 700; font-size: 14px; }
.offer:hover { background: var(--cream2); }
.gb { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.gb h3 { margin: 0 0 8px; font-size: 18px; }
.entry { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 8px; }
.entry b { color: var(--ink); } .entry small { color: #9a7b63; float: right; }
.list-item { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 12px; cursor: pointer; }
.list-item:hover { background: var(--cream2); }
.list-item img, .list-item .ph { width: 44px; height: 54px; object-fit: cover; border-radius: 6px; background: #efe2d0; display: grid; place-items: center; }

#toast { position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%); z-index: 40; background: var(--brown); color: #fff6ea; padding: 10px 16px; border-radius: 999px; font-weight: 700; animation: fade .3s; max-width: calc(100% - 32px); text-align: center; }
@media (max-width: 520px) { #soundBtn { display: none; } .brand { font-size: 17px; } .primary { padding: 9px 14px; font-size: 14px; } }

.frames { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.frame-opt { padding: 10px 4px; border-radius: 10px; font-weight: 800; font-size: 13px; border: 3px solid transparent; }
.frame-opt.on { outline: 2px solid var(--orange); outline-offset: 2px; }
.f-go { background: #8a5a36; color: #fff; } .f-vang { background: linear-gradient(135deg, #f0d78a, #b8862e); color: #3c1e0a; }
.f-da { background: #9a948c; color: #fff; } .f-trang { background: #f3e6d2; color: #3c1e0a; border-color: var(--line); }
