:root, .theme-lantern {
  --field: rgba(255, 255, 255, .06);
  --field-focus: rgba(255, 255, 255, .1);
  --hover: rgba(255, 255, 255, .08);
  --dlg: #161a30;
  --toast: #242944;
  --on-primary: #2a1a06;
  --list-bg: radial-gradient(ellipse at top, #1c2142, #0b0f20 70%);
  --topbar: linear-gradient(to bottom, rgba(8, 11, 24, .85), rgba(8, 11, 24, 0));
  --card: linear-gradient(#2a2f45, #1d2134);
  --msg: rgba(255, 255, 255, .05);
  --bg: #0d1226;
  --glass: rgba(14, 18, 36, 0.84);
  --glass-2: rgba(26, 31, 56, 0.9);
  --line: rgba(255, 255, 255, 0.1);
  --text: #ece7dc;
  --muted: #a9a8b8;
  --amber: #f2b766;
  --amber-2: #ffcf8a;
  --danger: #ff8f80;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
#scene { position: fixed; inset: 0; }
#scene canvas { display: block; touch-action: none; }

/* ---------- top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--topbar);
}
.brand { display: flex; align-items: center; gap: 8px; font: 600 22px/1 var(--serif); letter-spacing: .3px; white-space: nowrap; color: var(--amber-2); }
.brand-ico { width: 22px; height: 22px; }
.search { position: relative; flex: 1; max-width: 360px; margin-left: auto; }
.search input {
  width: 100%; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--field); outline: none;
}
.search input:focus { border-color: var(--amber); background: var(--field-focus); }
.actions { display: flex; gap: 8px; align-items: center; }
.dd { position: relative; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .06); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:hover { background: rgba(255, 255, 255, .12); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--amber); color: var(--on-primary); border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: var(--amber-2); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .55; pointer-events: none; }

.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; max-height: 60vh; overflow: auto;
  background: var(--glass-2); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
}
.search .menu { left: 0; right: 0; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-decoration: none; }
.menu button:hover, .menu button.on { background: var(--hover); }
.menu .menu-head { padding: 8px 10px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu img, .menu .mini { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none; background: rgba(255, 255, 255, .08); display: grid; place-items: center; color: var(--amber); }
.menu .nm { font-weight: 500; }
.menu .yr { color: var(--muted); font-size: 12px; display: block; }
.menu .empty { padding: 10px; color: var(--muted); }

#hint {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 5;
  padding: 8px 16px; border-radius: 999px; background: rgba(8, 11, 24, .6); color: var(--muted); font-size: 13px;
  transition: opacity 1s; pointer-events: none; text-align: center; max-width: calc(100% - 24px);
}
#hint.gone { opacity: 0; }

#tooltip {
  position: fixed; z-index: 15; pointer-events: none; padding: 6px 12px; border-radius: 8px;
  background: var(--dlg); border: 1px solid var(--line); font: 600 17px var(--serif); color: var(--amber-2); transform: translate(-50%, -140%);
}

/* ---------- memorial panel ---------- */
#panel {
  position: fixed; z-index: 25; top: 72px; right: 16px; bottom: 16px; width: 400px; max-width: calc(100vw - 32px);
  background: var(--glass); border: 1px solid var(--line); border-radius: 18px; overflow: auto;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  animation: slideIn .35s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } }
.close {
  position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%; border: 0; z-index: 2;
  background: rgba(255, 255, 255, .08); font-size: 22px; line-height: 1; cursor: pointer;
}
.close:hover { background: rgba(255, 255, 255, .16); }
.p-hero { padding: 28px 24px 18px; text-align: center; border-bottom: 1px solid var(--line); }
.p-photo { width: 150px; height: 186px; margin: 0 auto 14px; border-radius: 50% / 50%; overflow: hidden; border: 3px solid rgba(242, 183, 102, .55); box-shadow: 0 0 40px rgba(242, 183, 102, .18); }
.p-photo img { width: 100%; height: 100%; object-fit: cover; }
.p-name { font: 700 32px/1.1 var(--serif); margin: 0; }
.p-years { color: var(--amber-2); font: 600 20px var(--serif); margin: 6px 0 0; letter-spacing: 1px; }
.p-epitaph { font: italic 500 20px/1.35 var(--serif); margin: 14px 0 0; color: #ddd6c8; white-space: pre-line; }
.p-meta { color: var(--muted); font-size: 13px; margin-top: 14px; }
.p-tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, .1); color: var(--muted); margin-left: 6px; vertical-align: middle; }
.badge.warn { background: rgba(242, 183, 102, .18); color: var(--amber-2); }

.p-section { padding: 18px 22px 24px; }
.p-section h3 { font: 600 22px var(--serif); margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.compose textarea { width: 100%; min-height: 84px; resize: vertical; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--field); outline: none; }
.compose textarea:focus { border-color: rgba(242, 183, 102, .6); }
.compose .row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 10px; }
.compose .note { color: var(--muted); font-size: 12px; }
.login-prompt { padding: 14px; border-radius: 12px; background: var(--msg); color: var(--muted); text-align: center; }
.login-prompt button { margin-top: 8px; }

.msgs { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 12px 14px; border-radius: 12px; background: var(--msg); border: 1px solid transparent; }
.msg.pending { border-color: rgba(242, 183, 102, .35); }
.msg.hidden { opacity: .6; border-style: dashed; border-color: var(--line); }
.msg.owner { background: rgba(242, 183, 102, .08); }
.msg-body { white-space: pre-wrap; word-wrap: break-word; }
.msg-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.msg-foot .who { font-weight: 600; color: var(--text); opacity: .85; }
.msg-foot .spacer { flex: 1; }
.link { background: none; border: 0; padding: 2px 4px; color: var(--muted); cursor: pointer; font-size: 12px; text-decoration: underline; text-underline-offset: 2px; }
.link:hover { color: var(--text); }
.link.ok { color: var(--amber-2); }
.link.bad { color: var(--danger); }
.empty-msgs { color: var(--muted); font-style: italic; margin-top: 14px; }
.spinner { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- list view ---------- */
#listview { position: fixed; inset: 0; z-index: 10; overflow: auto; padding: 84px 20px 40px; background: var(--list-bg); }
.list-inner { max-width: 1100px; margin: 0 auto; }
.list-head h2 { font: 600 34px var(--serif); margin: 0; }
.list-head p { color: var(--muted); margin: 4px 0 22px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 18px 12px 16px;
  border-radius: 90px 90px 14px 14px; border: 1px solid var(--line); background: var(--card);
  cursor: pointer; transition: transform .15s, border-color .15s;
}
.card:hover { transform: translateY(-3px); border-color: rgba(242, 183, 102, .5); }
.card.marble { background: linear-gradient(#e9e5dd, #cfc9be); color: #3d3934; }
.card.sandstone { background: linear-gradient(#cdb18a, #a88b65); color: #3e2c1b; }
.card.slate { background: linear-gradient(#3a4350, #272d36); }
.card img, .card .noimg { width: 92px; height: 112px; border-radius: 50%; object-fit: cover; margin-bottom: 8px; border: 2px solid rgba(242, 183, 102, .5); }
.card .noimg { display: grid; place-items: center; font-size: 34px; color: var(--amber); background: rgba(0, 0, 0, .15); }
.card .nm { font: 700 20px/1.15 var(--serif); }
.card .yr { font: 600 15px var(--serif); opacity: .8; }
.card .cd { font-size: 12px; opacity: .75; margin-top: 4px; }
.grid .empty { color: var(--muted); grid-column: 1 / -1; }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; background: transparent; color: var(--text); max-width: calc(100vw - 24px); }
dialog::backdrop { background: rgba(4, 6, 14, .65); backdrop-filter: blur(3px); }
.dlg { position: relative; width: 380px; max-width: 100%; padding: 26px 24px 22px; border-radius: 18px; background: var(--dlg); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
.wide-dlg { width: 620px; max-height: calc(100vh - 40px); overflow: auto; }
.dlg h2 { font: 600 28px var(--serif); margin: 0 0 16px; }
.dlg label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.dlg input:not([type=radio]):not([type=checkbox]):not([type=file]), .dlg select, .dlg textarea {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--field); outline: none; color: var(--text);
}
.dlg select option { background: var(--dlg); }
.dlg input:focus, .dlg select:focus, .dlg textarea:focus { border-color: rgba(242, 183, 102, .6); }
.dlg textarea { resize: vertical; }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: rgba(255, 255, 255, .06); margin-bottom: 14px; width: calc(100% - 40px); }
.tabs button { flex: 1; padding: 8px; border: 0; border-radius: 999px; background: none; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--amber); color: var(--on-primary); font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.err { color: var(--danger); background: rgba(255, 143, 128, .1); padding: 8px 12px; border-radius: 10px; font-size: 13px; }
.reg-only { display: none !important; }
.registering .reg-only { display: block !important; }
.count { float: right; font-size: 12px; }
.mem-grid { display: grid; grid-template-columns: 150px 1fr; gap: 20px; }
.photo-pick { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.photo-prev { width: 140px; height: 172px; border-radius: 50%; border: 2px dashed rgba(242, 183, 102, .5); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 13px; background-size: cover; background-position: center; }
.photo-prev.has { border-style: solid; }
.photo-prev.has span { display: none; }
.file-btn { margin: 0 !important; color: var(--text) !important; }
.dlg label.check { display: flex; align-items: center; gap: 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stones { border: 0; padding: 0; margin: 4px 0 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.stones legend { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.stones label { display: flex; align-items: center; gap: 8px; margin: 0; padding: 7px 12px 7px 8px; border-radius: 999px; border: 1px solid var(--line); cursor: pointer; color: var(--text); }
.stones input { position: absolute; opacity: 0; pointer-events: none; }
.stones label:has(input:checked) { border-color: var(--amber); background: rgba(242, 183, 102, .12); }
.sw { width: 22px; height: 22px; border-radius: 50% 50% 4px 4px; display: inline-block; }
.sw.granite { background: #555a61; } .sw.marble { background: #e8e4dc; } .sw.slate { background: #343c48; } .sw.sandstone { background: #c2a47c; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- toast / loading ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 60; transform: translate(-50%, 20px);
  padding: 11px 18px; border-radius: 12px; background: var(--toast); border: 1px solid var(--line); box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
  opacity: 0; pointer-events: none; transition: .25s; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#loading { position: fixed; inset: 0; z-index: 80; display: grid; place-content: center; justify-items: center; background: var(--bg); transition: opacity .8s; }
#loading p { font: italic 500 22px var(--serif); color: var(--muted); }
#loading.done { opacity: 0; pointer-events: none; }
.flame { width: 22px; height: 34px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: radial-gradient(circle at 50% 70%, #fff6d8, #ffc163 45%, #ff8a2a 75%, transparent 76%); filter: drop-shadow(0 0 18px #ffab47); animation: flick 1.2s infinite alternate ease-in-out; }
@keyframes flick { 0% { transform: scale(1) rotate(-2deg); } 100% { transform: scale(1.08, 1.15) rotate(2deg); } }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  #topbar { flex-wrap: wrap; gap: 8px; padding-left: 10px; padding-right: 10px; }
  .brand { font-size: 19px; }
  .actions { margin-left: auto; gap: 6px; }
  .btn .lbl { display: none; }
  .btn { padding: 9px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-width: none; max-height: 62vh; border-radius: 20px 20px 0 0; animation: rise .35s ease; padding-bottom: env(safe-area-inset-bottom); }
  @keyframes rise { from { transform: translateY(40px); opacity: 0; } }
  .p-photo { width: 120px; height: 148px; }
  .p-name { font-size: 28px; }
  #listview { padding-top: 120px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .mem-grid { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; gap: 0; }
  #hint { font-size: 12px; }
}

/* ---------- gift picker ---------- */
.gift-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.gift-lbl { font-size: 12px; color: var(--muted); flex-basis: 100%; }
.gift-pick label { cursor: pointer; }
.gift-pick input { position: absolute; opacity: 0; pointer-events: none; }
.gift-pick label span { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; font-size: 19px; border: 1px solid var(--line); background: var(--field); transition: transform .12s, border-color .12s, background .12s; }
.gift-pick label:hover span { transform: scale(1.08); }
.gift-pick input:checked + span { border-color: var(--amber); background: rgba(242, 183, 102, .2); transform: scale(1.1); }
.gift-pick input:focus-visible + span { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---------- Heavenly theme (light, pastel) ---------- */
.theme-heaven {
  --bg: #ffe4d8;
  --glass: rgba(255, 250, 247, 0.86);
  --glass-2: rgba(255, 249, 246, 0.95);
  --line: rgba(150, 90, 100, 0.16);
  --text: #4d3a42;
  --muted: #957f87;
  --amber: #e9866f;
  --amber-2: #c9664f;
  --danger: #c84a4a;
  --field: rgba(255, 255, 255, .7);
  --field-focus: #fff;
  --hover: rgba(233, 134, 111, .1);
  --dlg: #fffaf7;
  --toast: #fffaf7;
  --on-primary: #fff;
  --list-bg: linear-gradient(#f6b3c9, #ffd2bd 45%, #fff1e8);
  --topbar: linear-gradient(to bottom, rgba(255, 236, 232, .9), rgba(255, 236, 232, 0));
  --card: linear-gradient(#ffffff, #f6ece8);
  --msg: rgba(255, 255, 255, .75);
}
.theme-heaven .brand { color: #c9664f; }
.theme-heaven .btn { background: rgba(255, 255, 255, .55); }
.theme-heaven .btn:hover { background: rgba(255, 255, 255, .85); }
.theme-heaven .btn.primary { background: var(--amber); }
.theme-heaven .btn.primary:hover { background: #f09a84; }
.theme-heaven .close { background: rgba(120, 70, 80, .08); }
.theme-heaven .p-photo { border-color: #e8b86a; box-shadow: 0 0 50px rgba(255, 200, 150, .6); }
.theme-heaven .p-epitaph { color: #6d5560; }
.theme-heaven .p-years { color: #c08a3e; }
.theme-heaven .msg.owner { background: rgba(255, 226, 214, .8); }
.theme-heaven .badge { background: rgba(120, 70, 80, .08); }
.theme-heaven #hint { background: rgba(255, 250, 247, .75); color: #8a6f78; }
.theme-heaven .card { color: var(--text); border-radius: 18px 18px 10px 10px; }
.theme-heaven .card img, .theme-heaven .card .noimg { border-radius: 50% 50% 8px 8px / 40% 40% 8px 8px; border-color: #e8b86a; }
.theme-heaven .card.granite { background: linear-gradient(#f6f4f8, #e2dee8); }
.theme-heaven .card.marble { background: linear-gradient(#ffffff, #f2ebe6); color: var(--text); }
.theme-heaven .card.slate { background: linear-gradient(#f2f7fc, #d9e5f2); }
.theme-heaven .card.sandstone { background: linear-gradient(#fff3f0, #f5d9d2); color: var(--text); }
.theme-heaven .card .noimg { color: #e0a54e; background: rgba(255, 220, 200, .4); }
.theme-heaven dialog::backdrop { background: rgba(120, 70, 80, .3); }
.theme-heaven .dlg, .theme-heaven .menu, .theme-heaven #panel { box-shadow: 0 24px 60px rgba(160, 90, 90, .25); }
.theme-heaven #loading { background: linear-gradient(#f6b3c9, #ffd2bd 55%, #fff1e8); }
.theme-heaven #loading p { color: #a26f74; }
.theme-heaven .stones label:has(input:checked) { background: rgba(233, 134, 111, .12); }
.theme-heaven .gift-pick input:checked + span { background: rgba(233, 134, 111, .18); }

/* ---------- realms, password reset ---------- */
.sw.lantern { background: linear-gradient(#141a38, #2a3a26); border-radius: 50%; }
.sw.heaven { background: linear-gradient(#ee9cc0, #ffe2cf); border-radius: 50%; }
.sw.both { background: linear-gradient(90deg, #141a38 50%, #f3b0c6 50%); border-radius: 50%; }
.realm-tag { font-size: 11px; opacity: .75; margin-top: 2px; }
.forgot-link, .back-link { display: block; margin: -4px 0 12px; padding: 0; font-size: 13px; }
.back-link { display: none; margin: 12px auto 0; }
.forgetting .pw-row, .forgetting .forgot-link, .forgetting .tabs, .forgetting .reg-only { display: none !important; }
.forgetting .back-link { display: block; }
.registering .forgot-link { display: none; }
.ok-msg { color: var(--text); background: rgba(120, 200, 140, .14); border: 1px solid rgba(120, 200, 140, .35); padding: 10px 12px; border-radius: 10px; font-size: 13px; }
.dlg h2 + label { margin-top: 4px; }
.forgetting #authIntro { padding-right: 40px; }
