:root {
    --bg: #0c0b09;
    --bg-2: #14110e;
    --card: rgba(24, 20, 16, 0.92);
    --gold: #c4a35a;
    --gold-2: #e6d3a3;
    --text: #efe6d6;
    --muted: #9a8f7c;
    --line: rgba(196, 163, 90, 0.28);
    --danger: #c46a5a;
    --ok: #8aa36a;
    --tab: 56px;
    --serif: "Noto Serif SC", "Songti SC", "SimSun", serif;
    --sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); }
body {
    font-family: var(--sans);
    color: var(--text);
    background:
        linear-gradient(180deg, rgba(12, 11, 9, 0.72), rgba(12, 11, 9, 0.94)),
        url("../img/altar-bg.png") center top / cover no-repeat fixed;
    min-height: 100%;
    -webkit-tap-highlight-color: transparent;
}

.app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    padding: calc(12px + env(safe-area-inset-top)) 16px calc(var(--tab) + 20px + env(safe-area-inset-bottom));
}

.topbar {
    text-align: center;
    padding: 18px 8px 8px;
}
.eyebrow {
    margin: 0;
    letter-spacing: 0.6em;
    font-size: 12px;
    color: var(--gold);
    font-family: var(--serif);
}
.topbar h1 {
    margin: 10px 0 6px;
    font-family: var(--serif);
    font-size: 22px;
    font-weight: 700;
    line-height: 1.4;
}
.sub { margin: 0; color: var(--muted); font-size: 13px; }

.music-btn {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    right: 12px;
    z-index: 28;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--gold);
    background: #100e0c;
    color: var(--gold-2);
    font-family: var(--serif);
    font-size: 16px;
    letter-spacing: 0;
    text-indent: 0;
    border-radius: 50%;
}
.music-btn.is-on {
    color: var(--gold);
}

.flash {
    margin: 12px 0;
    padding: 10px 12px;
    border: 1px solid var(--line);
    font-size: 14px;
    line-height: 1.5;
}
.flash-ok { border-color: var(--ok); color: var(--ok); }
.flash-error { border-color: var(--danger); color: #e8b4aa; }

.altar {
    position: relative;
    text-align: center;
    padding: 8px 8px 20px;
}
.tablet {
    font-family: var(--serif);
    letter-spacing: 0.35em;
    color: var(--gold-2);
    margin: 0 0 14px;
    font-size: 14px;
}
.portrait-wrap {
    width: 168px;
    height: 210px;
    margin: 0 auto 14px;
    border: 1px solid var(--gold);
    padding: 6px;
    background: #0a0908;
    box-shadow: 0 0 40px rgba(196, 163, 90, 0.12);
}
.portrait-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    filter: saturate(0.85) contrast(1.05);
}
.honoree {
    font-family: var(--serif);
    font-size: 28px;
    margin: 0 0 8px;
    letter-spacing: 0.25em;
}
.honoree span {
    font-size: 16px;
    margin-left: 6px;
    letter-spacing: 0.15em;
    color: var(--gold);
}
.dates {
    list-style: none;
    padding: 0;
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.8;
}
.bio {
    margin: 0;
    font-size: 14px;
    line-height: 1.9;
    color: var(--gold-2);
    text-align: justify;
}

.counts, .stat-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 0 0 16px;
}
.counts div, .stat-row div {
    border: 1px solid var(--line);
    background: var(--card);
    text-align: center;
    padding: 10px 4px;
}
.counts strong, .stat-row strong {
    display: block;
    font-family: var(--serif);
    color: var(--gold);
    font-size: 18px;
}
.counts span, .stat-row span {
    color: var(--muted);
    font-size: 12px;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    padding: 16px;
    margin-bottom: 16px;
}
.card h3 {
    margin: 0 0 8px;
    font-family: var(--serif);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.2em;
    color: var(--gold-2);
}
.hint, .muted {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.7;
}
.hint { margin: 0 0 14px; }

.tribute-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}
.tribute-opt { display: block; }
.tribute-opt input { position: absolute; opacity: 0; pointer-events: none; }
.tribute-face {
    display: block;
    border: 1px solid var(--line);
    background: #0f0d0b;
    text-align: center;
    padding: 8px 6px 10px;
    min-height: 132px;
}
.tribute-face img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    margin-bottom: 6px;
}
.tribute-face em {
    font-style: normal;
    font-family: var(--serif);
    font-size: 14px;
    letter-spacing: 0.2em;
    color: var(--gold-2);
}
.tribute-opt input:checked + .tribute-face,
.tribute-opt input:focus-visible + .tribute-face {
    border-color: var(--gold);
    box-shadow: inset 0 0 0 1px var(--gold);
}

.check-plain {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 14px;
    font-size: 14px;
    color: var(--muted);
}
.check-plain input { accent-color: var(--gold); width: 18px; height: 18px; }

.field { display: block; margin-bottom: 12px; }
.field span {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--gold-2);
}
.field i, legend i { color: var(--danger); font-style: normal; }
.field input, .field textarea, .choice {
    width: 100%;
    font-size: 16px;
    font-family: inherit;
    color: var(--text);
    background: #0a0908;
    border: 1px solid var(--line);
    padding: 12px;
    border-radius: 0;
}
.field textarea { resize: vertical; min-height: 96px; line-height: 1.6; }
.field input:focus, .field textarea:focus {
    outline: none;
    border-color: var(--gold);
}

.choice {
    display: flex;
    gap: 18px;
    align-items: center;
    margin-bottom: 12px;
    padding: 10px 12px;
}
.choice legend {
    padding: 0 6px;
    color: var(--gold-2);
    font-size: 13px;
}
.choice label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 15px;
}
.choice input { accent-color: var(--gold); width: 18px; height: 18px; }

.btn-gold {
    width: 100%;
    height: 48px;
    border: 1px solid var(--gold);
    background: linear-gradient(180deg, #3a2f1c, #1d170f);
    color: var(--gold-2);
    font-family: var(--serif);
    font-size: 18px;
    letter-spacing: 0.6em;
    text-indent: 0.6em;
    margin-top: 4px;
}
.btn-gold:active { opacity: 0.85; }
.btn-gold[disabled] { opacity: 0.5; }
.form-msg { margin: 10px 0 0; font-size: 13px; color: var(--gold); }
.form-msg.is-error { color: #e8b4aa; }

.hp {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.stack { margin-top: 8px; }

.feed { display: flex; flex-direction: column; gap: 12px; }
.feed-item {
    display: flex;
    gap: 10px;
    border-top: 1px solid rgba(196, 163, 90, 0.14);
    padding-top: 12px;
}
.feed-item:first-child { border-top: 0; padding-top: 0; }
.mini-rite {
    width: 44px;
    height: 44px;
    object-fit: cover;
    flex: 0 0 44px;
    border: 1px solid var(--line);
}
.who {
    margin: 0 0 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    font-size: 13px;
    color: var(--muted);
}
.who strong { color: var(--gold-2); font-weight: 500; }
.say { margin: 0; font-size: 15px; line-height: 1.7; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.list-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.list-table th, .list-table td {
    border-bottom: 1px solid rgba(196, 163, 90, 0.16);
    padding: 10px 6px;
    text-align: left;
    vertical-align: top;
}
.list-table th { color: var(--gold); font-weight: 500; }
.list-table small {
    display: block;
    color: var(--muted);
    margin-top: 2px;
}

.album-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.album-item {
    padding: 0;
    border: 1px solid var(--line);
    background: #0a0908;
    color: inherit;
    text-align: left;
}
.album-item img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    display: block;
}
.album-item span {
    display: block;
    padding: 6px 8px 8px;
    font-size: 12px;
    color: var(--muted);
}

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 480px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    height: calc(var(--tab) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: #100e0c;
    border-top: 1px solid var(--line);
    z-index: 20;
}
.tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--muted);
    font-size: 11px;
    gap: 2px;
}
.tabbar a.active { color: var(--gold); }
.tabbar .ico {
    font-family: var(--serif);
    font-size: 16px;
}

.rite-overlay, .lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 24px;
}
.rite-overlay[hidden],
.lightbox[hidden] {
    display: none !important;
}
.rite-stage { text-align: center; }
.rite-stage img {
    width: 180px;
    height: 180px;
    object-fit: cover;
    animation: rise 1.4s ease;
}
.rite-stage p {
    font-family: var(--serif);
    color: var(--gold-2);
    letter-spacing: 0.4em;
    margin: 16px 0 0;
}
@keyframes rise {
    from { transform: translateY(24px) scale(0.92); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.lightbox img {
    max-width: 100%;
    max-height: 72vh;
    object-fit: contain;
}
.lightbox p { color: var(--gold-2); margin: 10px 0 0; }
.lightbox-close, .admin a, .admin-side a {
    color: var(--gold-2);
}

.lightbox-close {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top));
    right: 16px;
    background: none;
    border: 1px solid var(--line);
    color: var(--gold-2);
    padding: 8px 12px;
    font-size: 14px;
}

.admin-body {
    background: var(--bg);
    background-image: none;
}
.admin {
    display: block;
    min-height: 100vh;
}
.admin-side {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: calc(12px + env(safe-area-inset-top)) 12px 8px;
    border-bottom: 1px solid var(--line);
    background: #100e0c;
}
.admin-brand {
    width: 100%;
    margin: 0 0 6px;
    font-family: var(--serif);
    color: var(--gold);
    letter-spacing: 0.3em;
}
.admin-side a {
    text-decoration: none;
    border: 1px solid var(--line);
    padding: 8px 10px;
    font-size: 13px;
}
.admin-side a.active {
    border-color: var(--gold);
    color: var(--gold);
}
.admin-main {
    padding: 16px 16px 40px;
    max-width: 960px;
}
.admin-main h1 {
    font-family: var(--serif);
    font-size: 20px;
    margin: 0 0 16px;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td {
    border-bottom: 1px solid rgba(196, 163, 90, 0.16);
    padding: 8px 6px;
    text-align: left;
    vertical-align: top;
}
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.admin-actions button, .admin-actions a, .mini-btn {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--gold-2);
    padding: 6px 8px;
    font-size: 12px;
    text-decoration: none;
    cursor: pointer;
}
.login-box {
    max-width: 360px;
    margin: 12vh auto 0;
    padding: 24px 16px;
}

@media (min-width: 860px) {
    .admin {
        display: grid;
        grid-template-columns: 200px 1fr;
    }
    .admin-side {
        flex-direction: column;
        flex-wrap: nowrap;
        border-bottom: 0;
        border-right: 1px solid var(--line);
        min-height: 100vh;
        position: sticky;
        top: 0;
    }
    .album-grid { grid-template-columns: repeat(3, 1fr); }
}
