/* 给我先生的信 —— 一封信，落在桌上 */

:root {
  color-scheme: light;
  --table-hi: #efe2da;
  --table-mid: #e4d2c7;
  --table-lo: #d3baae;
  --paper: #fcf7ef;
  --paper-deep: #f4ead9;
  --ink: #3a302a;
  --ink-soft: #6e615a;
  --ink-faint: #9c8e84;
  --rose: #a8544c;
  --rose-deep: #8d4038;
  --sage: #7e8c74;
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", Georgia, serif;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "Kaiti TC", "Songti SC", "Noto Serif SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

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

body {
  min-height: 100svh;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(255, 250, 244, 0.85) 0%, rgba(255, 250, 244, 0) 55%),
    radial-gradient(150% 110% at 50% 40%, var(--table-mid) 0%, var(--table-lo) 100%);
  background-color: var(--table-lo);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* 桌面上的细颗粒，让底色像布 / 木 */
.grain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.16'/%3E%3C/svg%3E");
}

main {
  position: relative;
  z-index: 1;
  padding: 0 18px;
}

/* ---------- 信封 ---------- */

.env-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100svh;
  padding: calc(30px + env(safe-area-inset-top)) 0 calc(40px + env(safe-area-inset-bottom));
  transition: opacity 0.6s ease;
}

.env-wrap.is-opening { opacity: 0; }

.envelope {
  position: relative;
  width: min(84vw, 350px);
  aspect-ratio: 1.58 / 1;
  perspective: 900px;
  cursor: pointer;
  filter: drop-shadow(0 16px 22px rgba(104, 66, 53, 0.22)) drop-shadow(0 2px 3px rgba(104, 66, 53, 0.18));
  -webkit-tap-highlight-color: transparent;
}

.envelope:focus-visible { outline: 2px solid var(--rose); outline-offset: 10px; }

.env-pocket {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 13%;
  background: linear-gradient(168deg, #fdf8f0 0%, #f6ecdd 62%, #f1e4d2 100%);
  border-radius: 3px;
  overflow: hidden;
  z-index: 2;
}

.env-to {
  font-family: var(--kai);
  font-size: 1.06rem;
  letter-spacing: 0.42em;
  color: #6d6058;
  padding-left: 0.42em;
}

/* 露出的信纸一角 */
.env-paper {
  position: absolute;
  left: 8%;
  right: 8%;
  top: -15%;
  bottom: 10%;
  background: linear-gradient(180deg, #fffdf8, #f8f0e2);
  border-radius: 2px;
  opacity: 0;
  transform: translateY(0);
  transition: transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0.5s ease 0.12s;
  z-index: 1;
  box-shadow: 0 2px 6px rgba(120, 85, 60, 0.12);
}

.env-fold {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  border-radius: 3px;
}

.env-fold--left {
  clip-path: polygon(0 0, 50% 52%, 0 100%);
  background: linear-gradient(100deg, #f7edde, #f2e5d3);
}

.env-fold--right {
  clip-path: polygon(100% 0, 50% 52%, 100% 100%);
  background: linear-gradient(260deg, #f7edde, #f2e5d3);
}

.env-fold--bottom {
  clip-path: polygon(0 100%, 50% 46%, 100% 100%);
  background: linear-gradient(180deg, #f8efe1, #f0e2cf);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.env-flap {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 62%;
  z-index: 4;
  transform-origin: top center;
  transform: rotateX(0deg);
  transition: transform 0.85s cubic-bezier(0.4, 0.1, 0.2, 1);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(175deg, #fdf8ef, #f4e8d7 78%, #f0e1cd);
  box-shadow: 0 3px 8px rgba(120, 85, 60, 0.14);
  backface-visibility: hidden;
}

.seal {
  position: absolute;
  left: 50%;
  top: 60%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  z-index: 5;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b8605a, #9b463f 55%, #84362f 100%);
  box-shadow: 0 3px 7px rgba(97, 48, 41, 0.35), inset 0 -2px 5px rgba(82, 33, 27, 0.35), inset 0 2px 3px rgba(255, 214, 200, 0.35);
  display: grid;
  place-items: center;
  transition: opacity 0.45s ease, transform 0.6s cubic-bezier(0.4, 0.1, 0.2, 1);
}

.seal svg { width: 64%; height: 64%; display: block; }

.envelope.open .env-flap { transform: rotateX(178deg); }
.envelope.open .env-paper { opacity: 1; transform: translateY(-24px); }
.envelope.open .seal { opacity: 0; transform: scale(0.82) rotate(-10deg); }

.tap-hint {
  margin: 30px 0 0;
  font-family: var(--kai);
  font-size: 0.95rem;
  letter-spacing: 0.24em;
  color: #7c675c;
  transition: opacity 0.4s ease;
}

.env-wrap.is-opening .tap-hint { opacity: 0; }

/* ---------- 信纸 ---------- */

.letter {
  position: relative;
  width: min(100%, 560px);
  margin: calc(30px + env(safe-area-inset-top)) auto calc(48px + env(safe-area-inset-bottom));
  padding: 46px 26px 40px;
  background-color: var(--paper);
  background-image:
    radial-gradient(150% 100% at 50% 0%, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23p)' opacity='0.05'/%3E%3C/svg%3E");
  border-radius: 2px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 1px 2px rgba(120, 80, 60, 0.12),
    0 26px 48px -22px rgba(102, 64, 48, 0.45);
  opacity: 0;
  transform: translateY(18px) scaleY(0.985);
  transform-origin: top center;
  transition: opacity 0.9s ease, transform 1s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.letter.is-open { opacity: 1; transform: none; }

.letter:focus { outline: none; }

.tape {
  position: absolute;
  top: -13px;
  left: 50%;
  width: 122px;
  height: 28px;
  margin-left: -61px;
  transform: rotate(-2.2deg);
  background: linear-gradient(180deg, rgba(226, 205, 173, 0.82), rgba(213, 187, 150, 0.78));
  box-shadow: 0 2px 5px rgba(120, 85, 60, 0.16);
  border-left: 1px dashed rgba(255, 255, 255, 0.7);
  border-right: 1px dashed rgba(255, 255, 255, 0.7);
}

.letter-to {
  margin: 6px 0 26px;
  font-family: var(--kai);
  font-size: 1.3rem;
  letter-spacing: 0.1em;
  color: var(--ink);
}

.letter-body { font-family: var(--kai); }

.line {
  margin: 0 0 0.98em;
  font-size: clamp(1.02rem, 4.3vw, 1.14rem);
  line-height: 2.05;
  letter-spacing: 0.035em;
  color: var(--ink);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1.1s ease, transform 1.1s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.line.is-in { opacity: 1; transform: none; }

.line--strong {
  color: #2f2621;
  position: relative;
  isolation: isolate;
}

.line--strong::after {
  content: "";
  position: absolute;
  left: 0.1em;
  right: 62%;
  bottom: 0.35em;
  height: 0.42em;
  background: linear-gradient(90deg, rgba(168, 84, 76, 0.22), rgba(168, 84, 76, 0.04));
  z-index: -1;
  border-radius: 2px;
}

.letter-more {
  margin: 34px 0 0;
  font-family: var(--kai);
  font-size: 0.92rem;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
  text-align: right;
}

@media (max-width: 380px) {
  .letter { padding: 40px 20px 34px; }
  .letter-to { font-size: 1.18rem; }
}

@media (prefers-reduced-motion: reduce) {
  .envelope.open .env-flap,
  .envelope.open .env-paper,
  .seal,
  .letter,
  .line,
  .env-wrap { transition-duration: 0.01ms !important; }
  .line { opacity: 1; transform: none; }
}
