/* ==========================================================================
   网上纪念堂 · 样式
   --------------------------------------------------------------------------
   基调不是"灵堂"，是"一本旧相册"。
   所以底色用旧纸的暖白，字用暖黑，点缀用墨绿和枯褐 —— 像纸放久了的那种黄。

   一页里有六节：传、大事记、影、言、忆、灯。
   每一节用同样的标题结构（回目数字 + 章节名），读起来才有"书"的感觉。
   ========================================================================== */

:root {
    --paper:      #f7f2e8;
    --paper-2:    #f0e9db;
    --paper-3:    #e8dfcd;
    --ink:        #2e2820;
    --ink-soft:   #5c5346;
    --ink-faint:  #96897a;
    --line:       #ddd2be;
    --line-soft:  #e9e0cf;
    --accent:     #6b7a58;     /* 墨绿 */
    --accent-2:   #9a7245;     /* 枯褐 */
    --lamp-bg:    #12140f;
    --radius:     6px;
    --serif:      "Songti SC", "Source Han Serif SC", "Noto Serif SC", "STSong", Georgia, serif;
}

/* 深色：像夜里开灯看相册 */
[data-theme="dark"] {
    --paper:      #1a1815;
    --paper-2:    #221f1a;
    --paper-3:    #2a2620;
    --ink:        #e6ded0;
    --ink-soft:   #a89e8d;
    --ink-faint:  #746a5b;
    --line:       #332e26;
    --line-soft:  #2a251f;
    --accent:     #8a9a76;
    --accent-2:   #b98d5c;
}

/* 素白：如果想要更干净 */
[data-theme="light"] {
    --paper:      #fcfcfa;
    --paper-2:    #f5f5f2;
    --paper-3:    #ececea;
    --ink:        #2a2a28;
    --ink-soft:   #5e5e5a;
    --ink-faint:  #9a9a95;
    --line:       #e2e2de;
    --line-soft:  #eeeeea;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 17px;
    line-height: 2;
    letter-spacing: .01em;
    -webkit-font-smoothing: antialiased;
    transition: background-color .5s ease, color .5s ease;
}

/* 极淡的纸纹，只有一点点，让纯色不那么"塑料" */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: .55;
    background-image:
        radial-gradient(circle at 18% 26%, rgb(154 114 69 / 4%) 0, transparent 40%),
        radial-gradient(circle at 82% 72%, rgb(107 122 88 / 3.5%) 0, transparent 44%);
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { color: var(--ink); }

img { max-width: 100%; display: block; }

.wrap {
    position: relative;
    z-index: 1;
    max-width: 720px;
    margin: 0 auto;
    padding: clamp(44px, 9vh, 100px) 26px 90px;
}

/* ==========================================================================
   首：照片 · 姓名 · 生卒 · 一句话
   ========================================================================== */

.hero {
    text-align: center;
    padding-bottom: 12px;
}

.portrait {
    width: clamp(136px, 34vw, 172px);
    margin: 0 auto 28px;
}

/* 相册感：白色内衬 + 极细边 + 很轻的阴影 */
.portrait img,
.portrait .placeholder {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 3px;
    background: var(--paper-2);
    border: 1px solid var(--line);
    padding: 6px;                       /* 内衬 */
    box-shadow: 0 2px 10px rgb(46 40 32 / 7%);
    filter: saturate(.9) contrast(.98);
}

.portrait img {
    background: #fff;
}

.portrait .placeholder {
    display: grid;
    place-items: center;
    font-size: 2.6rem;
    color: var(--ink-faint);
}

.name {
    margin: 0 0 12px;
    font-size: clamp(1.9rem, 5.4vw, 2.3rem);
    font-weight: 500;
    letter-spacing: .16em;
    text-indent: .16em;
    line-height: 1.5;
}

.dates {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin: 0 0 22px;
    font-size: .9rem;
    letter-spacing: .04em;
    color: var(--ink-soft);
    font-variant-numeric: tabular-nums;
}

.dates i {
    display: block;
    width: 26px;
    height: 1px;
    background: var(--line);
}

.headline {
    margin: 0 auto;
    max-width: 26em;
    font-size: 1.04rem;
    line-height: 2.1;
    color: var(--ink-soft);
    letter-spacing: .02em;
}

/* ==========================================================================
   章节：一 传 / 二 大事记 …
   ========================================================================== */

.chapter {
    margin-top: clamp(52px, 9vh, 82px);
}

.chapter_title {
    display: flex;
    align-items: baseline;
    gap: 14px;
    margin: 0 0 26px;
    padding-bottom: 14px;
    font-size: 1.28rem;
    font-weight: 500;
    letter-spacing: .3em;
    text-indent: .3em;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
}

/* 回目数字：小、细、像古籍的"卷一" */
.chapter_title span {
    font-size: .72rem;
    letter-spacing: 0;
    text-indent: 0;
    color: var(--accent-2);
    border: 1px solid var(--line);
    border-radius: 2px;
    padding: 0 6px;
    line-height: 1.6;
}

.prose {
    font-size: 1.04rem;
    line-height: 1.95;
    color: var(--ink-soft);
    text-align: justify;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* 首行缩进 —— 中文正文的规矩 */
.prose p {
    margin: 0 0 1.05em;
    text-indent: 2em;
}

.prose p:last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   大事记：编年
   ========================================================================== */

.timeline {
    list-style: none;
    margin: 0;
    padding: 0;
}

.timeline li {
    display: grid;
    grid-template-columns: 88px 1fr;
    gap: 34px;
    padding: 0 0 24px;
}

.timeline li:last-child {
    padding-bottom: 0;
}

.tl_year {
    text-align: left;
    font-size: 1.02rem;
    line-height: 1.9;
    color: var(--accent-2);
    font-variant-numeric: tabular-nums;
    letter-spacing: .02em;
    padding-top: 1px;
}

.tl_year em {
    display: block;
    font-style: normal;
    font-size: .74rem;
    color: var(--ink-faint);
    letter-spacing: .04em;
    line-height: 1.6;
    margin-top: 2px;
}

.tl_text {
    font-size: 1rem;
    line-height: 1.95;
    color: var(--ink-soft);
}

/* ==========================================================================
   影：照片墙
   ========================================================================== */

.era_title {
    margin: 34px 0 18px;
    font-size: .82rem;
    font-weight: 400;
    letter-spacing: .28em;
    color: var(--ink-faint);
}

.era_title:first-of-type {
    margin-top: 0;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 176px), 1fr));
    gap: 16px;
}

.gallery figure {
    margin: 0;
}

/* 照片贴相册：白边 + 细线 */
.gallery img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    background: var(--paper-2);
    border: 1px solid var(--line);
    padding: 5px;
    border-radius: 2px;
    transition: transform .35s ease, box-shadow .35s ease;
}

.gallery figure:hover img {
    transform: translateY(-3px);
    box-shadow: 0 8px 22px rgb(46 40 32 / 10%);
}

.gallery figcaption {
    margin-top: 8px;
    font-size: .8rem;
    line-height: 1.75;
    color: var(--ink-faint);
    letter-spacing: .02em;
}

/* ==========================================================================
   言：语录
   ========================================================================== */

.quotes {
    display: grid;
    gap: 20px;
}

.quotes blockquote {
    margin: 0;
    padding: 20px 24px;
    font-size: 1.02rem;
    line-height: 2.1;
    color: var(--ink-soft);
    border-left: 2px solid var(--line);
    background: linear-gradient(to right, rgb(154 114 69 / 4%), transparent 70%);
}

.quotes cite {
    display: block;
    margin-top: 10px;
    font-style: normal;
    font-size: .78rem;
    color: var(--ink-faint);
    letter-spacing: .06em;
}

/* ==========================================================================
   忆：家人写的片段
   ========================================================================== */

.memories {
    list-style: none;
    margin: 0 0 34px;
    padding: 0;
}

.memories li {
    padding: 22px 0;
    border-bottom: 1px solid var(--line-soft);
}

.memories li:last-child {
    border-bottom: none;
}

.m_text {
    margin: 0 0 10px;
    font-size: 1rem;
    line-height: 1.95;
    color: var(--ink-soft);
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.m_meta {
    margin: 0;
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-size: .78rem;
    color: var(--ink-faint);
}

.m_meta em {
    font-style: normal;
    padding: 0 7px;
    border: 1px solid var(--line);
    border-radius: 2px;
    line-height: 1.7;
}

.m_meta time {
    margin-left: auto;
}

/* ==========================================================================
   表单
   ========================================================================== */

.field { margin-bottom: 12px; }

.field input,
.field textarea {
    width: 100%;
    padding: 11px 14px;
    font-family: inherit;
    font-size: .95rem;
    line-height: 1.8;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    transition: border-color .2s ease, box-shadow .2s ease;
}

.field textarea { min-height: 104px; resize: vertical; }

.field input:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--accent-2);
    box-shadow: 0 0 0 3px rgb(154 114 69 / 9%);
}

.field input::placeholder,
.field textarea::placeholder { color: var(--ink-faint); }

.btn {
    display: inline-block;
    padding: 10px 28px;
    font-family: inherit;
    font-size: .92rem;
    letter-spacing: .14em;
    text-indent: .14em;
    color: var(--paper);
    background: var(--ink);
    border: 1px solid var(--ink);
    border-radius: 999px;
    cursor: pointer;
    transition: background-color .25s ease, border-color .25s ease, color .25s ease;
}

.btn:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn:disabled { opacity: .5; cursor: default; }

.btn.ghost {
    background: transparent;
    color: var(--ink-soft);
    border-color: var(--line);
}

.btn.ghost:hover { color: var(--accent-2); border-color: var(--accent-2); background: transparent; }

.hint {
    margin: 12px 0 0;
    font-size: .76rem;
    color: var(--ink-faint);
}

/* ==========================================================================
   空状态 / 提示
   ========================================================================== */

.empty,
.placeholder_text {
    padding: 30px 0;
    text-align: center;
    font-size: .92rem;
    line-height: 2.1;
    color: var(--ink-faint);
    letter-spacing: .03em;
}

.placeholder_text {
    text-align: left;
    padding: 8px 0;
}

.notice {
    margin: 0 0 22px;
    padding: 12px 16px;
    font-size: .87rem;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--paper-2);
    color: var(--ink-soft);
}

.notice.error {
    border-color: #c4a08e;
    background: rgb(196 160 142 / 12%);
}

/* ==========================================================================
   六 · 灯
   ========================================================================== */

.lamp_section {
    margin-top: clamp(60px, 11vh, 96px);
    padding: 40px 24px 36px;
    text-align: center;
    background: var(--lamp-bg);
    border-radius: var(--radius);
    overflow: hidden;
}

.lamp {
    position: relative;
    width: clamp(180px, 52vw, 240px);
    margin: 0 auto 6px;
}

.lamp img {
    width: 100%;
    height: auto;
    display: block;
    filter: brightness(.93);
    /* 让照片边缘融进深色底，不留方形边界 */
    -webkit-mask-image: radial-gradient(ellipse 72% 72% at 50% 52%, #000 55%, transparent 100%);
    mask-image: radial-gradient(ellipse 72% 72% at 50% 52%, #000 55%, transparent 100%);
}

/* ---------- 焰心：真正在动的那个 ---------------------------------------- */

.lamp_flame {
    position: absolute;
    left: 50%;
    top: 42.5%;
    width: 5.2%;
    height: 12%;
    transform: translateX(-50%);
    transform-origin: 50% 100%;
    border-radius: 50% 50% 44% 44% / 74% 74% 26% 26%;
    background: radial-gradient(ellipse 58% 68% at 50% 76%,
        #fffdf4 0%, #fff0b8 20%, #ffcd63 44%, #ff9226 68%, rgb(255 110 20 / 0%) 86%);
    filter: blur(.55px) saturate(1.05);
    mix-blend-mode: screen;
    animation: flameSway 3.4s ease-in-out infinite;
    pointer-events: none;
}

/* 内焰：更亮的小芯，频率比外焰快，看着才不是整体缩放 */
.lamp_flame::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 8%;
    width: 42%;
    height: 44%;
    transform: translateX(-50%);
    border-radius: 50%;
    background: #fffdf6;
    filter: blur(1.3px);
    opacity: .8;
    animation: coreFlicker 2.1s ease-in-out infinite;
}

@keyframes flameSway {
    0%, 100% { transform: translateX(-50%) rotate(-1.4deg) scaleY(1); }
    24%      { transform: translateX(-50%) rotate(1.1deg)  scaleY(1.07); }
    52%      { transform: translateX(-50%) rotate(-.7deg)  scaleY(.95); }
    76%      { transform: translateX(-50%) rotate(1.5deg)  scaleY(1.04); }
}

@keyframes coreFlicker {
    0%, 100% { opacity: .68; transform: translateX(-50%) scale(.94); }
    50%      { opacity: 1;   transform: translateX(-50%) scale(1.1); }
}

/* 火焰周围的暖光：比焰心慢，呼吸感 */
.lamp_glow {
    position: absolute;
    left: 50%;
    top: 32%;
    width: 52%;
    height: 52%;
    margin-left: -26%;
    border-radius: 50%;
    background: radial-gradient(circle, rgb(255 208 120 / 30%) 0%, rgb(255 170 70 / 12%) 42%, transparent 70%);
    filter: blur(9px);
    animation: lampBreath 4.2s ease-in-out infinite;
    pointer-events: none;
    mix-blend-mode: screen;
}

@keyframes lampBreath {
    0%, 100% { opacity: .62; transform: scale(1); }
    38%      { opacity: 1;   transform: scale(1.09); }
    62%      { opacity: .82; transform: scale(1.03); }
}

.lamp_section.is_lit .lamp_glow {
    animation: lampFlash 1.4s ease-out;
}

@keyframes lampFlash {
    0%   { opacity: .6; transform: scale(1); }
    22%  { opacity: 1;  transform: scale(1.5); }
    100% { opacity: .7; transform: scale(1); }
}

.lamp_text {
    margin: 6px 0 6px;
    font-size: .98rem;
    letter-spacing: .22em;
    text-indent: .22em;
    color: #cdbfa6;
}

.lamp_count {
    margin: 0 0 20px;
    font-size: .76rem;
    letter-spacing: .12em;
    color: #7d7361;
    font-variant-numeric: tabular-nums;
}

.lamp_section .btn.ghost {
    color: #cdbfa6;
    border-color: rgb(205 191 166 / 32%);
}

.lamp_section .btn.ghost:hover {
    color: #fff;
    border-color: rgb(255 255 255 / 60%);
}

/* ==========================================================================
   页脚
   ========================================================================== */

.footer {
    margin-top: clamp(56px, 10vh, 84px);
    padding-top: 22px;
    border-top: 1px solid var(--line-soft);
    text-align: center;
    font-size: .76rem;
    letter-spacing: .16em;
    color: var(--ink-faint);
}

/* ==========================================================================
   交互补充
   ========================================================================== */

.fade_in {
    opacity: 0;
    transform: translateY(12px);
    animation: fadeUp .9s cubic-bezier(.22, .61, .36, 1) forwards;
}

@keyframes fadeUp {
    to { opacity: 1; transform: none; }
}

.memorial_toast {
    position: fixed;
    left: 50%;
    bottom: 34px;
    z-index: 50;
    padding: 11px 22px;
    border-radius: 999px;
    background: var(--ink);
    color: var(--paper);
    font-size: .84rem;
    letter-spacing: .04em;
    box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
    opacity: 0;
    transform: translate(-50%, 16px);
    transition: opacity .3s ease, transform .3s ease;
    pointer-events: none;
}

.memorial_toast.on { opacity: 1; transform: translate(-50%, 0); }

.btn:focus-visible,
.field input:focus-visible,
.field textarea:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 3px;
}

::selection {
    background: rgb(154 114 69 / 20%);
    color: var(--ink);
}

/* 减少动态 */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .lamp_glow,
    .lamp_flame,
    .lamp_flame::after,
    .lamp_section.is_lit .lamp_glow { animation: none !important; }
    .fade_in { animation: none; opacity: 1; transform: none; }
    .gallery img { transition: none; }
}

/* 触控 */
@media (hover: none) {
    .btn { min-height: 44px; }
    .field input, .field textarea { font-size: 16px; }
}

/* 手机 */
@media (max-width: 560px) {
    body { font-size: 16px; }

    .timeline li {
        grid-template-columns: 62px 1fr;
        gap: 18px;
    }

    .tl_year { font-size: .92rem; }
    .tl_text { font-size: .96rem; }

    .gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .gallery figcaption { font-size: .74rem; }

    .chapter_title { font-size: 1.15rem; }

    .lamp_section { padding: 32px 18px 30px; }
}

/* 打印：有人会把这一页打出来 */
@media print {
    body { background: #fff; color: #000; font-size: 11pt; }
    body::before, .memorial_toast, .memory_form, .lamp_form, .notice { display: none !important; }

    .wrap { max-width: none; padding: 0; }

    .chapter { page-break-inside: avoid; }
    .memories li { page-break-inside: avoid; }

    .chapter_title { border-bottom-color: #ccc; }

    .lamp_section {
        background: #fff;
        border: 1px solid #ddd;
        padding: 16px;
    }
    .lamp img { -webkit-mask-image: none; mask-image: none; }
    .lamp_glow { display: none; }
    .lamp_text { color: #000; }
    .lamp_count { color: #666; }

    a { color: #000; text-decoration: underline; }
}

/* ==========================================================================
   口令页
   --------------------------------------------------------------------------
   独立于正文的一屏：垂直居中，手机上不顶到边、键盘弹起来也不挤。
   （这一节之前漏掉了，口令页一度是全无样式的裸表单。）
   ========================================================================== */

body.gate_page {
    /* dvh 跟着地址栏收起展开走，比 100vh 准 —— iOS 上差得尤其明显 */
    min-height: 100vh;
    min-height: 100dvh;
    /*
     * 用 flex 而不是 grid：
     * grid 里子元素的 width:100% 和「列宽由内容决定」会互相拉扯，
     * 标题一长列就被撑开，输入框跟着溢出屏幕（手机上右边被切掉）。
     * flex 下 width:100% 直接按容器内容宽算，不会出这个问题。
     */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    padding-bottom: max(32px, env(safe-area-inset-bottom));
    overflow-x: hidden;
}

.gate {
    width: 100%;
    max-width: 344px;
    margin: 0;
    box-sizing: border-box;
    padding: 38px 28px 34px;
    text-align: center;
    background: var(--paper-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 2px 24px rgb(46 40 32 / 6%);
}

.gate h1 {
    margin: 0 0 10px;
    font-size: 1.12rem;
    font-weight: 500;
    letter-spacing: .16em;
    text-indent: .16em;
    line-height: 1.6;
}

.gate p {
    margin: 0 0 24px;
    font-size: .84rem;
    line-height: 1.9;
    color: var(--ink-faint);
}

.gate .notice {
    margin: 0 0 18px;
    text-align: left;
    font-size: .8rem;
}

/* ---------- 小屏：去掉卡片外框，整屏就是一张纸 -------------------------- */

@media (max-width: 520px) {
    body.gate_page {
        padding: 30px 22px;
    }

    .gate {
        max-width: 100%;
        padding: 30px 20px 26px;
        background: transparent;
        border-color: transparent;
        box-shadow: none;          /* 小屏上阴影只剩噪点 */
        box-sizing: border-box;
    }

    .gate h1 {
        font-size: 1.2rem;
        margin-bottom: 12px;
    }

    .gate p {
        margin-bottom: 26px;
        font-size: .86rem;
    }

    .gate .field input {
        font-size: 16px;           /* 低于 16px 时 iOS 会自动放大整页 */
        padding: 14px 16px;
        text-align: center;        /* 口令居中，像在输密码 */
        letter-spacing: .12em;
    }

    .gate .btn {
        width: 100%;
        min-height: 48px;
        margin-top: 6px;
    }
}

/* 横屏手机：高度很矮，别让内容上下顶满 */
@media (max-height: 480px) and (orientation: landscape) {
    body.gate_page {
        padding: 16px 24px;
        place-items: start center;
    }

    .gate {
        padding: 24px 22px 22px;
    }

    .gate p {
        margin-bottom: 16px;
    }
}
