:root {
  --maple: #8a97a6;
  --rust: #9a8a82;
  --gold: #c5d0dc;
  --cream: #f6f1e8;
  --paper: #f7f3ec;
  --ink: #6b7684;
  --muted: #9aa5b2;
  --dusk: #a8b5c4;
  --mist: #d5dde6;
  --soft: #b8c3d0;
  --shadow: rgba(107, 118, 132, 0.07);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: "Cormorant Garamond", Georgia, serif;
  color: var(--ink);
  font-weight: 400;
  background:
    linear-gradient(90deg, rgba(197, 208, 220, 0.18), transparent 88px),
    linear-gradient(270deg, rgba(232, 214, 222, 0.16), transparent 88px),
    radial-gradient(ellipse at 18% 8%, rgba(232, 214, 222, 0.35), transparent 42%),
    radial-gradient(ellipse at 88% 78%, rgba(197, 208, 220, 0.28), transparent 44%),
    linear-gradient(165deg, #f6f1e8 0%, #f4efe8 48%, #eef2f6 100%);
  background-attachment: fixed;
}
.zh { font-family: "Ma Shan Zheng", "KaiTi", cursive, serif; letter-spacing: 0.04em; font-weight: 400; }
html[data-lang="zh"] body,
html[data-lang="zh"] button,
html[data-lang="zh"] input,
html[data-lang="zh"] .hint,
html[data-lang="zh"] .indicator,
html[data-lang="zh"] .say,
html[data-lang="zh"] .bday-text {
  font-family: "Ma Shan Zheng", "KaiTi", cursive, serif;
  font-weight: 400;
}
.en { font-style: italic; font-weight: 400; }

.bloom-field {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}
.bloom {
  position: absolute;
  opacity: 0.18;
  filter: saturate(0.55) brightness(1.12);
  mix-blend-mode: multiply;
  border-radius: 40% 60% 55% 45%;
  animation: bloom-drift 22s ease-in-out infinite alternate;
}
.bloom-a { width: min(280px, 42vw); left: -4%; top: 12%; transform: rotate(-12deg); }
.bloom-b { width: min(240px, 36vw); right: -3%; top: 48%; animation-delay: -7s; transform: rotate(18deg); }
.bloom-c { width: min(200px, 30vw); left: 28%; bottom: 4%; opacity: 0.14; animation-delay: -13s; }
@keyframes bloom-drift {
  from { transform: translate3d(0, 0, 0) rotate(var(--r, -8deg)); }
  to { transform: translate3d(12px, -18px, 0) rotate(calc(var(--r, -8deg) + 6deg)); }
}

.lace {
  pointer-events: none;
  position: fixed;
  left: 0; right: 0;
  height: 48px;
  z-index: 0;
  opacity: 0.28;
  background-image:
    radial-gradient(circle at 12px 24px, rgba(184, 195, 208, 0.55) 3px, transparent 4px),
    radial-gradient(circle at 36px 10px, rgba(232, 214, 222, 0.5) 2px, transparent 3px),
    repeating-linear-gradient(90deg, transparent 0 18px, rgba(197, 208, 220, 0.35) 18px 19px);
  background-size: 48px 48px, 48px 48px, 48px 2px;
}
.lace-top { top: 0; mask-image: linear-gradient(#000, transparent); }
.lace-bottom { bottom: 0; transform: scaleY(-1); mask-image: linear-gradient(#000, transparent); }

.edge-pattern {
  pointer-events: none;
  position: fixed;
  top: 8vh;
  bottom: 8vh;
  width: 1.4rem;
  z-index: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  font-size: 0.72rem;
  letter-spacing: 0.4em;
  writing-mode: vertical-rl;
  color: #a8b5c4;
  opacity: 0.2;
}
.edge-left { left: 0.35rem; }
.edge-right { right: 0.35rem; }

.motif-row {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.42rem;
  min-height: 1.6rem;
  margin: 0.15rem 0 0.55rem;
}
.motif {
  position: relative;
  width: 1.35rem;
  height: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.motif input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.motif .i {
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.55;
  display: inline-block;
  animation: motif-idle 3.6s ease-in-out infinite;
  transform-origin: center bottom;
}
.motif.m1 .i { animation-delay: 0s; }
.motif.m2 .i { animation-delay: 0.35s; }
.motif.m3 .i { animation-delay: 0.7s; }
.motif.m4 .i { animation-delay: 1.05s; }
.motif.m5 .i { animation-delay: 1.4s; }
.motif.m6 .i { animation-delay: 1.75s; }
.motif.m7 .i { animation-delay: 2.1s; }
@keyframes motif-idle {
  0%, 100% { transform: translateY(0) rotate(-4deg) scale(1); }
  50% { transform: translateY(-3px) rotate(5deg) scale(1.06); }
}
.motif .i.mist {
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #eef2f6, #a8b5c4);
  opacity: 0.5;
}
.motif .spark {
  pointer-events: none;
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  opacity: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(255, 214, 224, 0.9) 0 2px, transparent 3px),
    radial-gradient(circle at 80% 40%, rgba(197, 208, 220, 0.9) 0 2px, transparent 3px),
    radial-gradient(circle at 50% 85%, rgba(255, 236, 210, 0.9) 0 2px, transparent 3px);
}
.motif .say {
  pointer-events: none;
  display: none;
  position: absolute;
  left: 50%;
  top: 1.4rem;
  transform: translateX(-50%);
  font-size: 0.72rem;
  color: var(--soft);
  white-space: nowrap;
  letter-spacing: 0.08em;
  text-shadow: 0 1px 0 rgba(246, 241, 232, 0.9);
}
.motif input:checked ~ .i {
  opacity: 0.95;
  animation: motif-pop 0.55s ease;
}
.motif input:checked ~ .spark {
  opacity: 1;
  animation: sparkle 0.9s ease;
}
.motif input:checked ~ .say {
  display: block;
  animation: say-up 0.45s ease;
}
@keyframes motif-pop {
  0% { transform: scale(0.7) rotate(-12deg); }
  55% { transform: scale(1.28) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes sparkle {
  0% { opacity: 0; transform: scale(0.4); }
  40% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 0; transform: scale(1.4); }
}
@keyframes say-up {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

#leaves { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.leaf {
  position: absolute;
  top: -8%;
  font-size: 0.9rem;
  animation: fall linear infinite;
  opacity: 0.22;
}
@keyframes fall {
  to { transform: translate3d(var(--dx, 40px), 110vh, 0) rotate(220deg); }
}

.bday-wish {
  pointer-events: none;
  position: fixed;
  left: 50%;
  bottom: 18%;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  transform: translateX(-50%);
}
.bday-wish[hidden] { display: none !important; }
.bday-wish.is-on {
  display: flex;
  animation: wish-rise 3.2s ease forwards;
}
.bday-heart {
  font-size: 1.8rem;
  color: #d4a8b4;
  filter: drop-shadow(0 4px 10px rgba(212, 168, 180, 0.35));
  animation: heart-pulse 1.4s ease-in-out infinite;
}
.bday-text {
  font-size: 1.15rem;
  color: #b89aa6;
  letter-spacing: 0.18em;
  text-shadow: 0 1px 0 rgba(246, 241, 232, 0.95);
}
@keyframes wish-rise {
  0% { opacity: 0; transform: translate(-50%, 40px) scale(0.88); }
  18% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  72% { opacity: 1; transform: translate(-50%, -28px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -64px) scale(0.96); }
}
@keyframes heart-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

body.locked #app { display: none !important; }
#app { display: none; }
#app.is-on { display: block; position: relative; z-index: 1; max-width: 760px; margin: 0 auto; padding: 0.8rem 1.1rem 5.5rem; }

.gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
body.locked .gate { display: flex; }
.gate-card {
  width: min(100%, 420px);
  background: var(--paper);
  border: 1px solid rgba(138, 155, 176, 0.28);
  border-radius: 18px;
  padding: 2.2rem 1.6rem;
  text-align: center;
  box-shadow: 0 18px 48px var(--shadow);
}
.gate-card h1 { color: var(--ink); font-size: 2rem; margin: 0.3rem 0 0.4rem; }
.kicker, .sub { color: var(--dusk); letter-spacing: 0.16em; }
.gate-card form { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 1.2rem; }
.gate-card input {
  border: 1px solid #c5d0dc;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  background: #fff;
}
.error { color: var(--rust); margin-top: 0.7rem; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  position: sticky;
  top: 0;
  z-index: 8;
  padding: 0.4rem 0 0.7rem;
  background: linear-gradient(180deg, rgba(246, 241, 232, 0.96), transparent);
}
.brand-title { font-size: 1.25rem; color: var(--maple); }
.brand-sub { font-size: 0.82rem; color: var(--muted); }
.top-actions { display: flex; gap: 0.45rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.nav, .lang { display: flex; gap: 0.2rem; }
.nav button, .lang button, .btn, .ctrl {
  appearance: none;
  border: 1px solid rgba(138, 155, 176, 0.28);
  background: rgba(246, 241, 232, 0.92);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font: inherit;
}
.nav button.active, .lang button.active {
  background: #a8b5c4;
  color: #f6f1e8;
  border-color: #a8b5c4;
}
.btn {
  min-height: 48px;
  min-width: 12rem;
  padding: 0.7rem 1.6rem;
  color: var(--ink);
  background: linear-gradient(180deg, #fbf8f3, #f6f1e8);
  box-shadow: 0 6px 18px var(--shadow);
}

.view { display: none; }
.view.active { display: block; }

.cover {
  text-align: center;
  padding: 1.2rem 0.4rem 2rem;
  overflow: visible;
}
.cover-stage {
  perspective: 1600px;
  display: flex;
  justify-content: center;
  overflow: visible;
}
.cover-book {
  --cover-cream: #f7f3ec;
  --cover-paper: #f7f3ec;
  --cover-mist: #a8b5c4;
  --cover-fog: #d5dde6;
  --cover-ink: #6b7684;
  position: relative;
  width: min(340px, 78vw);
  height: min(480px, 68vh);
  transform: rotateY(-11deg) rotateX(5deg);
  transform-style: preserve-3d;
}
.cover-stack,
.cover-spine,
.cover-ornament,
.cover-face-back,
.cover .heart {
  pointer-events: none;
}
.cover-leaf {
  pointer-events: none;
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 1.05s cubic-bezier(0.4, 0.05, 0.2, 1);
  z-index: 2;
}
.cover-book.is-open .cover-leaf {
  transform: rotateY(-158deg);
}
.cover-stack {
  position: absolute;
  inset: 5px 0 5px 8px;
  background:
    linear-gradient(90deg, #d7dee7 0 10px, transparent 10px),
    linear-gradient(180deg, #eef2f6, var(--cover-cream));
  border-radius: 2px 10px 10px 2px;
  box-shadow:
    2px 0 0 #e8edf3,
    4px 0 0 #f4f1ea,
    6px 0 0 #dce3eb,
    8px 0 0 #f7f4ee,
    12px 16px 32px rgba(90, 108, 128, 0.16);
}
.cover-stack::after {
  content: "";
  position: absolute;
  top: 10px;
  right: -6px;
  bottom: 10px;
  width: 6px;
  background: repeating-linear-gradient(to right, #e8edf3 0 1px, #f7f4ee 1px 2px);
  pointer-events: none;
}
.cover-spine {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 13px;
  background: linear-gradient(90deg, #b7c2cf, #dce3eb 55%, #c5d0dc);
  border-radius: 3px 0 0 3px;
  z-index: 3;
}
.cover-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 2px 10px 10px 2px;
}
.cover-face-front {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.6rem 1.2rem 1.4rem 1.45rem;
  background:
    linear-gradient(180deg, rgba(197, 208, 220, 0.22), transparent 38%),
    var(--cover-paper);
  border: 1px solid rgba(138, 155, 176, 0.28);
  box-shadow: 0 16px 36px rgba(90, 108, 128, 0.14);
  color: var(--cover-ink);
}
.cover-face-front h1 {
  font-size: 2.1rem;
  color: #6b7684;
  margin: 0.35rem 0 0.15rem;
}
.cover-face-front .kicker,
.cover-face-front .cover-sub,
.cover-face-front .names,
.cover-face-front .date {
  color: var(--cover-mist);
}
.cover-ornament {
  width: 36px;
  height: 1px;
  margin: 0.75rem auto 0.95rem;
  background: var(--cover-fog);
}
.cover-face-back {
  transform: rotateY(180deg);
  background:
    linear-gradient(180deg, #eef2f6, #f3efe6);
  border: 1px solid rgba(138, 155, 176, 0.2);
}
.avatars { display: flex; justify-content: center; align-items: center; gap: 0.7rem; margin: 0.85rem 0; }
.avatars img { width: 68px; height: 68px; border-radius: 50%; object-fit: cover; border: 1px solid #c5d0dc; }
.heart { color: #8a9bb0; }
.names, .date { margin-bottom: 0.3rem; }
.btn-open {
  appearance: none;
  position: relative;
  z-index: 1;
  pointer-events: auto;
  margin-top: 1rem;
  min-height: 44px;
  padding: 0.55rem 1.45rem;
  border: 1px solid rgba(138, 155, 176, 0.4);
  border-radius: 999px;
  background: #f7f3ec;
  color: #6b7684;
  cursor: pointer;
  font: inherit;
  box-shadow: none;
}
.btn-open:disabled { opacity: 0.55; cursor: default; }

.letter {
  background: var(--paper);
  border: 1px solid rgba(138, 155, 176, 0.22);
  border-radius: 16px;
  padding: 1.8rem 1.3rem;
  box-shadow: 0 12px 32px var(--shadow);
}
.letter h2 { text-align: center; color: var(--maple); font-size: 1.8rem; }
.letter p { margin: 1rem 0; line-height: 1.85; font-size: 1.05rem; }
.dedication { text-align: center; color: var(--ink); border-top: 1px dashed #c5d0dc; padding-top: 1rem; }
.center { text-align: center; padding: 1.2rem 0 0.4rem; }

.chapter { text-align: center; margin: 0.3rem 0 1rem; }
.chapter h2 { color: var(--maple); font-size: 1.5rem; }
.chapter p { color: var(--muted); margin-top: 0.35rem; }
.page::before,
.page::after {
  pointer-events: none;
  position: absolute;
  top: 14px;
  bottom: 14px;
  width: 11px;
  font-size: 0.55rem;
  line-height: 2.1;
  color: #8a9bb0;
  opacity: 0.18;
  writing-mode: vertical-rl;
  letter-spacing: 0.55em;
}
.page::before { content: "🍅 🌸 🍁"; left: 5px; }
.page::after { content: "🐕 🌸 🍁"; right: 5px; }
.book-stage {
  position: relative;
  z-index: 1;
  perspective: 1400px;
  cursor: pointer;
}
.page {
  position: relative;
  background: var(--paper);
  border: 1px solid rgba(138, 155, 176, 0.22);
  border-radius: 4px 14px 14px 4px;
  padding: 1.2rem 1.35rem 1.4rem;
  box-shadow: 8px 14px 32px var(--shadow);
  min-height: 280px;
  transform-origin: center;
  transform-style: preserve-3d;
}
.page.is-turn-next { animation: turn-next 0.5s ease; }
.page.is-turn-prev { animation: turn-prev 0.5s ease; }
@keyframes turn-next {
  0% { transform: rotateY(0); }
  45% { transform: rotateY(-75deg); opacity: 0.4; }
  46% { transform: rotateY(75deg); opacity: 0.4; }
  100% { transform: rotateY(0); }
}
@keyframes turn-prev {
  0% { transform: rotateY(0); }
  45% { transform: rotateY(75deg); opacity: 0.4; }
  46% { transform: rotateY(-75deg); opacity: 0.4; }
  100% { transform: rotateY(0); }
}
.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.card { text-align: center; }
.card img {
  width: 100%;
  max-height: 52vh;
  object-fit: contain;
  border-radius: 8px;
  background: #f6f1e8;
  cursor: zoom-in;
}
.card h3 { margin-top: 0.55rem; font-size: 1.15rem; }
.card p { color: var(--muted); font-size: 0.95rem; line-height: 1.65; padding: 0.2rem 0.4rem 0; }
.hint { text-align: center; color: var(--muted); font-size: 0.78rem; margin: 0.7rem 0; }
.controls {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 1rem calc(0.8rem + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(246, 241, 232, 0.96) 62%, transparent);
  z-index: 9;
}
html:not([data-screen="album"]) .controls { display: none; }
.ctrl { min-width: 5.2rem; height: 2.6rem; padding: 0.35rem 0.9rem; font-size: 0.95rem; color: var(--maple); }
.ctrl:disabled { opacity: 0.35; cursor: not-allowed; }
.indicator { min-width: 8rem; text-align: center; color: var(--muted); font-size: 0.85rem; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(42, 32, 28, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
}
.lightbox[hidden] { display: none !important; }
.lightbox img { max-width: 100%; max-height: 78vh; object-fit: contain; }
.lightbox-close {
  position: absolute;
  top: 12px; right: 16px;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
}
#lightbox-caption { color: #f3e6da; margin-top: 0.7rem; text-align: center; }
