/* Noto Serif SC 首页字集，400–500 可变字重；授权见 FONT-LICENSE.txt。 */
@font-face {
    font-family: "Shuguang Serif";
    src: url("shuguang-serif.woff2?v=20261106a") format("woff2");
    font-style: normal;
    font-weight: 400 500;
    font-display: swap;
}

:root {
    color-scheme: light;
    --serif: "Shuguang Serif", "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
    --paper: #f3ecdf;
    --ink: #2a2620;
    --muted: #57514a;
    --rule: rgba(160, 58, 38, 0.13);
    --seal: #a6382a;
    --seal-ink: #f6eee1;
    --accent: #8a6b3e;
    --selection: #e6dac6;
    --fold-light: #fbf6ec;
    --fold-shade: #ddd1bc;
    --fold-under: #c8bba3;
    --fold-shadow: rgba(65, 47, 24, 0.18);
    --passing-light: rgba(255, 252, 238, 0.7);
    --passing-shade: rgba(103, 78, 40, 0.07);
    --vignette: rgba(72, 54, 30, 0.08);
}

:root[data-theme="night"] {
    color-scheme: dark;
    --paper: #1f2320;
    --ink: #e4ddca;
    --muted: #aaa595;
    --rule: rgba(214, 120, 96, 0.13);
    --seal: #b0493a;
    --seal-ink: #f1e6d4;
    --accent: #d1ba87;
    --selection: #41463c;
    --fold-light: #464b40;
    --fold-shade: #2d322a;
    --fold-under: #141814;
    --fold-shadow: rgba(0, 0, 0, 0.34);
    --passing-light: rgba(205, 216, 178, 0.09);
    --passing-shade: rgba(0, 0, 0, 0.16);
    --vignette: rgba(0, 0, 0, 0.34);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); }

body {
    position: relative;
    isolation: isolate;
    margin: 0;
    min-height: 100vh;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--serif);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* 纸纹单独移动，正文保持静止。 */
.paper-texture {
    position: fixed;
    z-index: -2;
    inset: -24px;
    pointer-events: none;
    background: url("paper-grain.png?v=20261022e") repeat;
    background-size: 256px 256px;
    mix-blend-mode: multiply;
    opacity: 0.85;
}

:root[data-theme="night"] .paper-texture {
    mix-blend-mode: soft-light;
    opacity: 0.2;
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(ellipse at 50% 45%, transparent 38%, var(--vignette) 100%);
}

::selection { color: var(--ink); background: var(--selection); }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible { outline: 1px solid var(--accent); outline-offset: 8px; }

/* ---------- 信笺：竖排，从右往左读 ---------- */

.letter {
    position: relative;
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: clamp(56px, 9vh, 104px) clamp(24px, 6vw, 72px);
}

.letter-sheet {
    position: relative;
    display: flex;
    flex-direction: row-reverse;
    align-items: stretch;
    gap: clamp(2.4rem, 5vw, 4.25rem);
    --col: clamp(1.0625rem, 0.82rem + 0.62vw, 1.25rem);
}

.letter-title,
.letter-body { align-self: flex-start; }

.letter-title {
    margin: 0;
    color: var(--ink);
    writing-mode: vertical-rl;
    font-size: clamp(2rem, 1.3rem + 2.4vw, 3.125rem);
    font-weight: 500;
    line-height: 1;
    letter-spacing: 0.3em;
}

.title-breeze {
    display: block;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    writing-mode: inherit;
    cursor: pointer;
    /* 颜色只跟随 h1，不在按钮上另设过渡：两层过渡叠加会在日夜切换时反复重启、闪烁。 */
}

.title-breeze:disabled { cursor: default; }

/* 朱丝栏：列与列之间的淡红竖线。 */
.letter-body {
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-start;
    gap: clamp(1.75rem, 3.6vw, 2.75rem);
    padding-top: 2.6em;
    color: var(--muted);
    font-size: var(--col);
    font-weight: 400;
}

.letter-body p {
    display: flex;
    flex-direction: row-reverse;
    margin: 0;
    border-right: 1px solid var(--rule);
}

.copy-line {
    display: block;
    writing-mode: vertical-rl;
    padding: 0 0.95em;
    border-left: 1px solid var(--rule);
    line-height: 1;
    letter-spacing: 0.32em;
    line-break: strict;
}

/* 落款：右列写日期节气（顶部起笔），左列写“距天明”，朱印压在左列下方。 */
.letter-sign {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: 1fr auto;
    column-gap: 0.85rem;
    margin-left: calc(-1 * clamp(0.4rem, 1.2vw, 1.1rem));
    padding-top: 3.2em;
    color: var(--muted);
    font-size: clamp(0.75rem, 0.66rem + 0.22vw, 0.8125rem);
}

/* 竖排容器里 flex 的“行”方向就是从上往下。 */
.sign-line {
    display: flex;
    flex-direction: row;
    align-items: center;
    margin: 0;
    writing-mode: vertical-rl;
    line-height: 1;
    letter-spacing: 0.22em;
}

.sign-almanac { grid-column: 2; grid-row: 1 / span 2; align-self: start; opacity: 0.8; }
.sign-dawn { grid-column: 1; grid-row: 1; align-self: end; margin-bottom: 0.8rem; opacity: 0.62; }

/* 竖排时各段之间用一个空点隔开，不额外占用字体子集。 */
.sign-part { display: flex; flex-direction: row; align-items: center; }

.sign-part + .sign-part::before {
    content: "";
    display: block;
    flex: 0 0 auto;
    width: 3px;
    height: 3px;
    margin: 0.6em 0;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.5;
}

/* 落款朱印：整页唯一的颜色。 */
.seal {
    grid-column: 1;
    grid-row: 2;
    justify-self: center;
    margin-bottom: 0.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 2.05rem;
    padding: 0.38rem 0 0.32rem;
    border-radius: 2px;
    background: var(--seal);
    color: var(--seal-ink);
    font-size: 0.98rem;
    font-weight: 500;
    line-height: 1.12;
    box-shadow: inset 0 0 0 2px var(--seal), inset 0 0 0 3px var(--seal-ink);
    transform: rotate(-3deg);
}

:root[data-theme="night"] .seal { opacity: 0.88; }

/* ---------- 入场：右起依次晕开，最后落印 ---------- */

@keyframes ink-in {
    from { opacity: 0; filter: blur(7px); transform: translateY(-0.6em); }
    to { opacity: 1; filter: blur(0); transform: none; }
}

@keyframes seal-in {
    0% { opacity: 0; transform: rotate(-3deg) scale(1.5); }
    60% { opacity: 1; transform: rotate(-3deg) scale(0.94); }
    100% { opacity: 1; transform: rotate(-3deg) scale(1); }
}

.letter-title,
.copy-line { animation: ink-in 1200ms cubic-bezier(0.22, 0.6, 0.25, 1) both; }
.letter-title { animation-delay: 150ms; }
.letter-body p:first-child .copy-line:nth-child(1) { animation-delay: 650ms; }
.letter-body p:first-child .copy-line:nth-child(2) { animation-delay: 850ms; }
.letter-body p:nth-child(2) .copy-line:nth-child(1) { animation-delay: 1100ms; }
.letter-body p:nth-child(2) .copy-line:nth-child(2) { animation-delay: 1300ms; }
.letter-body p:nth-child(2) .copy-line:nth-child(3) { animation-delay: 1500ms; }
.sign-line { animation: ink-in 1200ms cubic-bezier(0.22, 0.6, 0.25, 1) 1750ms both; }
.sign-dawn { animation-delay: 1950ms; }
.seal { animation: seal-in 520ms cubic-bezier(0.3, 0.7, 0.3, 1) 2300ms both; }

/* ---------- 点标题：掠光 ---------- */

.paper-light { position: fixed; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.light-passage {
    position: absolute;
    top: -20%;
    left: 0;
    width: 85vw;
    height: 140%;
    opacity: 0;
    background: linear-gradient(90deg, transparent 5%, var(--passing-light) 43%, var(--passing-light) 48%, var(--passing-shade) 62%, transparent 87%);
    transform: translate3d(140vw, 0, 0) skewX(18deg);
}

.is-breezing .light-passage { animation: light-passage 1900ms cubic-bezier(0.25, 0.45, 0.3, 1) both; }
.is-breezing .title-breeze { animation: title-glow 1700ms ease both; }

@keyframes light-passage {
    0% { transform: translate3d(140vw, 0, 0) skewX(18deg); opacity: 0; }
    20% { opacity: 1; }
    75% { opacity: 1; }
    100% { transform: translate3d(-110vw, 0, 0) skewX(18deg); opacity: 0; }
}

@keyframes title-glow {
    0%, 100% { color: var(--ink); }
    40% { color: var(--accent); }
}

/* ---------- 右下折角：日夜 ---------- */

.page-corner {
    position: fixed;
    z-index: 4;
    right: 0;
    bottom: 0;
    width: 76px;
    height: 76px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    cursor: pointer;
}

.page-corner:focus-visible { outline-offset: -6px; }

.corner-art {
    position: absolute;
    inset: 0;
    transform-origin: 100% 100%;
    transition: transform 650ms cubic-bezier(0.2, 0.65, 0.2, 1);
}

.corner-under {
    position: absolute;
    inset: 0;
    clip-path: polygon(100% 0, 0 100%, 100% 100%);
    background: linear-gradient(135deg, var(--fold-shadow), transparent 78%), var(--fold-under);
}

.corner-fold {
    position: absolute;
    inset: 0;
    filter: drop-shadow(-3px -3px 5px var(--fold-shadow));
}

.corner-fold::before {
    content: "";
    position: absolute;
    inset: 0;
    clip-path: polygon(0 0, 100% 0, 0 100%);
    background: linear-gradient(135deg, var(--fold-light) 32%, var(--fold-shade) 49%, var(--fold-light) 51%);
    border-radius: 3px 0 0;
}

.corner-icon { position: absolute; top: 11px; left: 11px; width: 17px; height: 17px; opacity: 0.72; }
.icon-sun { display: none; }
:root[data-theme="night"] .icon-moon { display: none; }
:root[data-theme="night"] .icon-sun { display: block; }
.page-corner:active .corner-art { transform: scale(0.95); }

/* ---------- 主题过渡 ---------- */

:root[data-ready] body { transition: background-color 1000ms ease, color 1000ms ease; }
:root[data-ready] .letter-body,
:root[data-ready] .letter-sign { transition: color 1000ms ease; }
.letter-title { transition: color 500ms ease; }
:root[data-ready] .letter-title { transition: color 1000ms ease; }
:root[data-ready] .paper-texture { transition: opacity 1000ms ease; }

/* ---------- 翻页：新纸色从右下角斜着翻过整页 ---------- */

/* 翻页期间关掉渐变，新页面直接以最终纸色被截取。 */
:root[data-turning] *,
:root[data-turning] *::before,
:root[data-turning] *::after { transition: none !important; }

::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) {
    z-index: 2;
    animation: page-turn 900ms cubic-bezier(0.55, 0.05, 0.25, 1) both;
    filter: drop-shadow(-10px -6px 18px rgba(40, 28, 12, 0.28));
}

/* 斜向擦除：翻页线从右下角扫向左上角。 */
@keyframes page-turn {
    from { clip-path: polygon(100% 100%, 100% 100%, 100% 100%); }
    55% { clip-path: polygon(110% -10%, 110% 110%, -10% 110%); }
    to { clip-path: polygon(220% -120%, 220% 220%, -120% 220%); }
}

/* ---------- 备案号：页底居中，系统字体，不占用宋体子集 ---------- */

/* 压到页底边缘、降低存在感，但保持可读：备案号须在首页可见，不能隐藏。 */
.site-record {
    position: fixed;
    z-index: 3;
    left: 0;
    right: 0;
    bottom: max(8px, env(safe-area-inset-bottom));
    text-align: center;
    pointer-events: none;
}

.site-record a {
    pointer-events: auto;
    color: var(--muted);
    font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    font-size: 11px;
    letter-spacing: 0.04em;
    text-decoration: none;
    opacity: 0.62;
    transition: opacity 300ms ease, color 300ms ease;
}

.site-record a:hover,
.site-record a:focus-visible { opacity: 1; color: var(--accent); }
.site-record a:focus-visible { outline: 1px solid var(--accent); outline-offset: 4px; }

@media (hover: hover) and (pointer: fine) {
    .letter-title:has(.title-breeze:hover) { color: var(--accent); transition-duration: 500ms; }
    .page-corner:hover .corner-art { transform: scale(1.14); }
}

/* ---------- 窄屏：字号随宽度收 ---------- */

@media (max-width: 600px) {
    .letter { padding: 64px 16px 88px; }
    .letter-sheet { gap: 1.6rem; --col: clamp(0.95rem, 4.1vw, 1.0625rem); }
    .letter-title { font-size: clamp(1.75rem, 8vw, 2.25rem); letter-spacing: 0.22em; }
    .letter-body { gap: 1.1rem; padding-top: 2.2em; }
    .copy-line { padding: 0 0.62em; letter-spacing: 0.18em; }
    .letter-sign { column-gap: 0.5rem; margin-left: -0.45rem; padding-top: 2.6em; font-size: 0.6875rem; }
    .sign-line { letter-spacing: 0.12em; }
    .sign-dawn { margin-bottom: 0.6rem; }
    .seal { width: 1.65rem; font-size: 0.8rem; }
    .page-corner { width: 64px; height: 64px; }
    .corner-icon { top: 9px; left: 9px; width: 15px; height: 15px; }
}

/* 最窄的手机：再收一点列距与字距，落款不出屏。 */
@media (max-width: 360px) {
    .letter-sheet { gap: 1.1rem; }
    .letter-body { gap: 0.8rem; }
    .copy-line { padding: 0 0.5em; letter-spacing: 0.14em; }
    .letter-sign { margin-left: 0; column-gap: 0.4rem; }
}

/* ---------- 矮屏（横屏手机等）：退回横排 ---------- */

/* 内容可能高于一屏：备案号改为跟在内容后面，不再固定压在底部。 */
@media (max-height: 560px) {
    .letter { min-height: auto; padding: 36px 32px 20px; }
    .site-record { position: static; padding: 0 0 max(14px, env(safe-area-inset-bottom)); }
    .letter-sheet {
        flex-direction: column;
        align-items: center;
        gap: 1.6rem;
        padding-left: 0;
        text-align: center;
    }
    .letter-title,
    .title-breeze,
    .copy-line { writing-mode: horizontal-tb; }
    .letter-title { font-size: 1.85rem; line-height: 1.4; letter-spacing: 0.12em; text-indent: 0.12em; }
    .letter-body { flex-direction: column; align-items: center; gap: 1em; padding-top: 0; font-size: 1rem; }
    .letter-body p { flex-direction: column; align-items: center; border-right: 0; }
    .copy-line { padding: 0; border-left: 0; line-height: 2; letter-spacing: 0.03em; text-indent: 0.03em; }
    .letter-sign { display: flex; flex-direction: column; align-items: center; gap: 0.45rem; margin-left: 0; padding-top: 0; font-size: 0.75rem; }
    .sign-line { flex-direction: row; writing-mode: horizontal-tb; letter-spacing: 0.08em; }
    .sign-dawn { margin-bottom: 0; }
    .sign-part + .sign-part::before { display: inline-block; margin: 0 0.6em; vertical-align: middle; }
    .seal { flex-direction: row; width: auto; margin: 0.3rem 0 0; padding: 0.22rem 0.42rem; gap: 0.08em; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
    ::view-transition-old(root),
    ::view-transition-new(root) { animation: none !important; }
    .is-breezing .title-breeze { color: var(--accent); }
    .page-corner:hover .corner-art,
    .page-corner:active .corner-art { transform: none; }
}
