:root {
  color-scheme: light;
  --cream: #fff8e9;
  --paper: #fffdf7;
  --pink: #f4a8b7;
  --pink-soft: #ffd8df;
  --red: #ef5261;
  --red-dark: #c93646;
  --yellow: #ffd66b;
  --brown: #483232;
  --brown-soft: #765c56;
  --white: #fffef9;
  --line: rgba(72, 50, 50, 0.2);
  --hand: "STKaiti", "KaiTi", "FangSong", serif;
  --sans: "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
  background: var(--cream);
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 1px 1px, rgba(72, 50, 50, 0.07) 1px, transparent 1.2px) 0 0 / 18px 18px,
    var(--cream);
  color: var(--brown);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.8;
}

body.sealed { overflow: hidden; }

button { font: inherit; }

button:focus-visible {
  outline: 3px solid var(--brown);
  outline-offset: 4px;
}

#confettiCanvas {
  position: fixed;
  inset: 0;
  z-index: 300;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.gift-cover {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  min-height: 100svh;
  place-items: center;
  overflow: hidden;
  padding: 2rem;
  background: var(--pink);
  transition: visibility 0s linear 850ms;
}

.cover-pattern {
  position: absolute;
  inset: 0;
  opacity: 0.28;
  background:
    linear-gradient(45deg, var(--red) 25%, transparent 25%, transparent 75%, var(--red) 75%),
    linear-gradient(45deg, var(--red) 25%, transparent 25%, transparent 75%, var(--red) 75%);
  background-position: 0 0, 24px 24px;
  background-size: 48px 48px;
}

.cover-card {
  position: relative;
  z-index: 2;
  width: min(42rem, 100%);
  padding: clamp(2rem, 6vw, 4.2rem);
  border: 2px solid var(--brown);
  background:
    linear-gradient(rgba(239, 82, 97, 0.08) 1px, transparent 1px) 0 5.2rem / 100% 2rem,
    var(--paper);
  box-shadow: 1rem 1rem 0 rgba(72, 50, 50, 0.2);
  transform: rotate(-1deg);
  transition: opacity 380ms ease, transform 700ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.cover-tape {
  position: absolute;
  top: -1.25rem;
  left: 50%;
  width: 7rem;
  height: 2.2rem;
  background: rgba(255, 214, 107, 0.84);
  transform: translateX(-50%) rotate(2deg);
}

.address-row {
  display: grid;
  grid-template-columns: 4rem 1fr;
  align-items: baseline;
  gap: 1rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--line);
}

.address-row span {
  color: var(--red);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.15em;
}

.address-row strong {
  font-family: var(--hand);
  font-size: 1.35rem;
  font-weight: 700;
}

.cover-date {
  width: fit-content;
  margin: 2.2rem 0 1rem;
  padding: 0.2rem 0.7rem;
  border: 2px solid var(--red);
  border-radius: 999px;
  color: var(--red);
  font-weight: 800;
  letter-spacing: 0.12em;
}

.cover-card h1 {
  margin: 0;
  font-family: var(--hand);
  font-size: clamp(2.7rem, 6vw, 5.2rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.24;
}

.countdown {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  margin-top: 1.7rem;
  color: var(--brown-soft);
  font-size: 0.82rem;
}

.countdown b {
  color: var(--red-dark);
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.unwrap-button {
  display: flex;
  min-width: 15rem;
  min-height: 3.8rem;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  margin-top: 2rem;
  padding: 0.45rem 0.55rem 0.45rem 1.35rem;
  border: 2px solid var(--brown);
  border-radius: 999px;
  background: var(--red);
  box-shadow: 4px 5px 0 var(--brown);
  color: white;
  cursor: pointer;
  font-weight: 800;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.unwrap-button:hover {
  box-shadow: 2px 3px 0 var(--brown);
  transform: translate(2px, 2px);
}

.unwrap-button i {
  display: grid;
  width: 2.65rem;
  height: 2.65rem;
  place-items: center;
  border-radius: 50%;
  background: var(--cream);
  font-size: 1.2rem;
  font-style: normal;
}

.cover-card small {
  display: block;
  margin: 0.9rem 0 0 0.7rem;
  color: var(--brown-soft);
}

.cover-corner {
  position: absolute;
  right: 1.5rem;
  bottom: 1rem;
  z-index: 2;
  margin: 0;
  color: rgba(72, 50, 50, 0.68);
  font-family: var(--hand);
  transform: rotate(-3deg);
}

.gift-cover.opening .cover-card {
  opacity: 0;
  transform: translateY(-3rem) rotate(4deg) scale(0.94);
}

.gift-cover.opening .cover-pattern {
  animation: pattern-out 850ms ease forwards;
}

.gift-cover.done { visibility: hidden; }

.topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 100;
  display: grid;
  min-height: 4.2rem;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.4rem;
  border-bottom: 2px solid var(--brown);
  background: rgba(255, 248, 233, 0.92);
  opacity: 0;
  transform: translateY(-100%);
  transition: opacity 400ms ease 450ms, transform 400ms ease 450ms;
  backdrop-filter: blur(0.7rem);
}

body.opened .topbar {
  opacity: 1;
  transform: translateY(0);
}

.bow-mark, .sound-toggle {
  border: 0;
  background: transparent;
  color: var(--brown);
  cursor: pointer;
}

.bow-mark {
  padding: 0.25rem;
  font-size: 1.35rem;
}

.topbar > span {
  font-family: var(--hand);
  font-size: 0.98rem;
  font-weight: 700;
}

.sound-toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem;
  font-size: 0.75rem;
}

.sound-toggle > span { color: var(--red); font-size: 1rem; }

.hero {
  position: relative;
  display: grid;
  min-height: 100svh;
  grid-template-columns: minmax(0, 1.15fr) minmax(18rem, 0.55fr);
  align-items: center;
  gap: clamp(2rem, 7vw, 8rem);
  overflow: hidden;
  padding: 7rem clamp(1.4rem, 7vw, 8rem) 5rem;
  background:
    linear-gradient(90deg, rgba(239, 82, 97, 0.08) 1px, transparent 1px) 0 0 / 5rem 100%,
    var(--cream);
}

.hero::before,
.hero::after {
  position: absolute;
  content: "";
  border: 2px solid var(--brown);
  background: var(--yellow);
}

.hero::before {
  top: 8rem;
  right: 8%;
  width: 2.5rem;
  height: 2.5rem;
  transform: rotate(18deg);
}

.hero::after {
  bottom: 6rem;
  left: 4%;
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  background: var(--pink);
}

.hero-date {
  position: absolute;
  right: -0.03em;
  bottom: -0.23em;
  color: rgba(239, 82, 97, 0.09);
  font-size: clamp(12rem, 28vw, 28rem);
  font-weight: 900;
  letter-spacing: -0.1em;
  line-height: 1;
  pointer-events: none;
}

.hero-copy, .today-note { position: relative; z-index: 2; }

.scribble {
  width: fit-content;
  margin: 0 0 1rem;
  padding-bottom: 0.15rem;
  border-bottom: 3px solid var(--red);
  font-family: var(--hand);
  font-size: 1.15rem;
  font-weight: 700;
  transform: rotate(-2deg);
}

.hero h1 {
  margin: 0;
  font-family: var(--hand);
  font-size: clamp(4rem, 8vw, 8rem);
  font-weight: 700;
  letter-spacing: -0.065em;
  line-height: 1.03;
}

.hero h1 span { color: var(--red); }

.hero-note {
  margin: 2rem 0 0;
  color: var(--brown-soft);
  font-family: var(--hand);
  font-size: clamp(1.05rem, 1.6vw, 1.35rem);
  line-height: 2;
}

.today-note {
  padding: 2rem;
  border: 2px solid var(--brown);
  background: var(--pink-soft);
  box-shadow: 0.75rem 0.75rem 0 var(--red);
  transform: rotate(2.5deg);
}

.tiny-stars {
  color: var(--red);
  font-size: 1.2rem;
  letter-spacing: 0.25em;
}

.today-note p {
  margin: 1rem 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 800;
}

.today-note strong {
  display: block;
  font-family: var(--hand);
  font-size: clamp(1.9rem, 3.2vw, 3rem);
  line-height: 1.5;
}

.today-note > span {
  display: block;
  margin-top: 1.2rem;
  color: var(--red-dark);
  font-family: var(--hand);
}

.scroll-note {
  position: absolute;
  bottom: 1.7rem;
  left: 50%;
  z-index: 3;
  font-family: var(--hand);
  font-size: 0.9rem;
  transform: translateX(-50%) rotate(-2deg);
}

.chat-section,
.lucky-section,
.letter-section,
.finale {
  position: relative;
  padding: clamp(5rem, 10vw, 9rem) clamp(1.4rem, 7vw, 8rem);
}

.chat-section {
  overflow: hidden;
  background: var(--red);
  color: var(--white);
}

.chat-section::before {
  position: absolute;
  top: -7rem;
  right: -5rem;
  width: 18rem;
  height: 18rem;
  border: 3px solid rgba(255, 255, 255, 0.34);
  border-radius: 50%;
  content: "";
}

.section-tag {
  width: fit-content;
  margin: 0 0 1.5rem;
  padding: 0.35rem 0.8rem;
  border: 2px solid currentColor;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
}

.chat-section h2,
.lucky-section h2,
.letter-section h2,
.finale h2 {
  margin: 0;
  font-family: var(--hand);
  font-size: clamp(2.7rem, 5.6vw, 5.8rem);
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1.25;
}

.chat-stack {
  max-width: 62rem;
  margin: clamp(3rem, 7vw, 6rem) auto 0;
}

.chat-card {
  position: relative;
  width: min(38rem, 76%);
  margin: 1rem 0;
  padding: 1.4rem 1.6rem;
  border: 2px solid var(--brown);
  border-radius: 1.4rem 1.4rem 1.4rem 0.25rem;
  background: var(--paper);
  box-shadow: 0.45rem 0.45rem 0 rgba(72, 50, 50, 0.25);
  color: var(--brown);
}

.chat-card.right {
  margin-left: auto;
  border-radius: 1.4rem 1.4rem 0.25rem 1.4rem;
}

.chat-card.pink { background: var(--pink-soft); }
.chat-card.yellow { background: var(--yellow); }
.chat-card.red { background: var(--brown); color: white; }

.chat-card span {
  position: absolute;
  top: 0.8rem;
  right: 1rem;
  color: var(--red);
  font-size: 0.7rem;
  font-weight: 800;
}

.chat-card.red span { color: var(--yellow); }

.chat-card p {
  margin: 0;
  font-family: var(--hand);
  font-size: clamp(1.2rem, 2vw, 1.65rem);
  line-height: 1.75;
}

.chat-afterword {
  max-width: 42rem;
  margin: clamp(3rem, 7vw, 6rem) 0 0 auto;
  padding-top: 1.4rem;
  border-top: 2px dashed rgba(255, 255, 255, 0.5);
  font-family: var(--hand);
  font-size: clamp(1rem, 1.5vw, 1.25rem);
}

.lucky-section {
  display: grid;
  min-height: 88vh;
  grid-template-columns: 0.85fr 1.15fr;
  align-items: center;
  gap: clamp(3rem, 8vw, 9rem);
  background:
    linear-gradient(rgba(244, 168, 183, 0.22) 2px, transparent 2px) 0 0 / 100% 2.2rem,
    var(--paper);
}

.lucky-copy > p:last-child {
  color: var(--brown-soft);
  font-family: var(--hand);
  font-size: 1.1rem;
}

.lucky-machine {
  width: min(34rem, 100%);
  justify-self: center;
}

.ticket {
  position: relative;
  min-height: 30rem;
  padding: 2rem;
  border: 2px solid var(--brown);
  background: var(--yellow);
  box-shadow: 1rem 1rem 0 var(--pink);
  transform: rotate(1.5deg);
  transition: transform 300ms ease, opacity 180ms ease;
}

.ticket::before,
.ticket::after {
  position: absolute;
  top: 50%;
  width: 1.5rem;
  height: 3rem;
  content: "";
  background: var(--paper);
  border: 2px solid var(--brown);
  border-radius: 50%;
  transform: translateY(-50%);
}

.ticket::before { left: -0.9rem; border-left-color: transparent; }
.ticket::after { right: -0.9rem; border-right-color: transparent; }

.ticket.changing {
  opacity: 0;
  transform: rotate(-3deg) translateY(-1rem);
}

.ticket-top {
  display: flex;
  justify-content: space-between;
  padding-bottom: 1rem;
  border-bottom: 2px dashed rgba(72, 50, 50, 0.35);
  font-size: 0.75rem;
  font-weight: 800;
}

.ticket-icon {
  margin-top: 2rem;
  color: var(--red);
  font-size: 4.5rem;
  line-height: 1;
}

.ticket > p {
  margin: 1.5rem 0 0;
  font-family: var(--hand);
  font-size: clamp(2rem, 4vw, 3.7rem);
  font-weight: 700;
  line-height: 1.5;
}

.ticket small {
  position: absolute;
  right: 2rem;
  bottom: 1.7rem;
  left: 2rem;
  padding-top: 0.8rem;
  border-top: 2px dashed rgba(72, 50, 50, 0.35);
  color: var(--brown-soft);
}

.draw-button,
.confetti-button {
  display: flex;
  min-height: 3.6rem;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  margin: 2.2rem auto 0;
  padding: 0.45rem 0.5rem 0.45rem 1.25rem;
  border: 2px solid var(--brown);
  border-radius: 999px;
  background: var(--red);
  box-shadow: 4px 4px 0 var(--brown);
  color: white;
  cursor: pointer;
  font-weight: 800;
}

.draw-button i {
  display: grid;
  width: 2.55rem;
  height: 2.55rem;
  place-items: center;
  border-radius: 50%;
  background: var(--cream);
  color: var(--red);
  font-size: 1.2rem;
  font-style: normal;
}

.letter-section {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 0.68fr 1.32fr;
  align-items: center;
  gap: clamp(3rem, 8vw, 9rem);
  background:
    radial-gradient(circle at 1px 1px, rgba(72, 50, 50, 0.08) 1px, transparent 1.2px) 0 0 / 16px 16px,
    var(--pink-soft);
}

.letter-intro > p:last-child {
  color: var(--brown-soft);
  font-family: var(--hand);
  font-size: 1.05rem;
}

.scratch-wrap {
  position: relative;
  width: min(47rem, 100%);
  justify-self: center;
}

.letter-paper {
  min-height: 38rem;
  padding: clamp(2rem, 5vw, 4rem);
  border: 2px solid var(--brown);
  background:
    linear-gradient(rgba(239, 82, 97, 0.12) 1px, transparent 1px) 0 6rem / 100% 2rem,
    var(--paper);
  box-shadow: 1rem 1rem 0 var(--red);
  transform: rotate(-1deg);
}

.letter-heading {
  display: flex;
  justify-content: space-between;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--brown);
  font-family: var(--hand);
  font-size: 1.15rem;
}

.letter-heading b { color: var(--red); }

.letter-paper h3 {
  margin: 1.5rem 0 1rem;
  color: var(--red);
  font-family: var(--hand);
  font-size: clamp(2.7rem, 5vw, 5rem);
  line-height: 1;
}

.letter-body {
  font-family: var(--hand);
  font-size: clamp(1.05rem, 1.45vw, 1.25rem);
  line-height: 2;
}

.letter-body p { margin: 0 0 0.9rem; }

.signature {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  margin-top: 1.7rem;
  padding-top: 1rem;
  border-top: 2px dashed rgba(72, 50, 50, 0.3);
  font-family: var(--hand);
}

.signature strong {
  color: var(--red);
  font-size: 1.8rem;
}

#scratchCanvas {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  transition: opacity 500ms ease, transform 500ms ease;
}

#scratchCanvas.cleared {
  opacity: 0;
  pointer-events: none;
  transform: rotate(2deg) scale(1.03);
}

.scratch-fallback {
  position: absolute;
  right: 0;
  bottom: -3.2rem;
  border: 0;
  background: transparent;
  color: var(--brown-soft);
  cursor: pointer;
  font-family: var(--hand);
  text-decoration: underline;
  text-underline-offset: 0.25rem;
}

.finale {
  display: grid;
  min-height: 88vh;
  place-content: center;
  overflow: hidden;
  background: var(--yellow);
  text-align: center;
}

.finale::before,
.finale::after {
  position: absolute;
  width: 17rem;
  height: 17rem;
  border: 3px solid var(--red);
  border-radius: 50%;
  content: "";
}

.finale::before { top: -8rem; left: -6rem; }
.finale::after { right: -7rem; bottom: -7rem; }

.finale-sticker {
  margin-bottom: 1rem;
  font-size: 3.5rem;
}

.finale > p:first-of-type {
  margin: 0 0 0.7rem;
  font-family: var(--hand);
  font-size: 1.1rem;
}

.finale h2 { color: var(--red); font-size: clamp(4rem, 10vw, 9.5rem); line-height: 1.02; }

.finale-note {
  margin: 1.5rem 0 0;
  font-family: var(--hand);
  font-size: clamp(1.25rem, 2vw, 1.75rem);
}

.final-sign {
  margin-top: 1.3rem;
  font-family: var(--hand);
  font-size: 1.5rem;
  font-weight: 700;
}

.confetti-button { background: var(--paper); color: var(--brown); }

.toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 350;
  max-width: min(24rem, calc(100vw - 2.5rem));
  padding: 0.9rem 1.2rem;
  border: 2px solid var(--brown);
  border-radius: 0.8rem;
  background: var(--paper);
  box-shadow: 5px 5px 0 var(--red);
  color: var(--brown);
  opacity: 0;
  pointer-events: none;
  transform: translateY(1rem) rotate(1deg);
  transition: opacity 200ms ease, transform 200ms ease;
}

.toast.show { opacity: 1; transform: translateY(0) rotate(1deg); }

footer {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  padding: 1.5rem clamp(1.4rem, 5vw, 5rem);
  border-top: 2px solid var(--brown);
  background: var(--paper);
  font-family: var(--hand);
  font-size: 0.9rem;
}

.reveal {
  opacity: 0;
  transform: translateY(2.5rem) rotate(0.35deg);
  transition: opacity 700ms ease, transform 700ms cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal.in-view { opacity: 1; transform: translateY(0) rotate(0); }

@keyframes pattern-out {
  to { opacity: 0; transform: scale(1.15); }
}

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .today-note { width: min(28rem, 100%); margin-left: auto; }
  .lucky-section, .letter-section { grid-template-columns: 1fr; }
  .lucky-machine { margin-top: 1rem; }
  .scratch-wrap { margin: 1rem auto 0; }
}

@media (max-width: 600px) {
  .gift-cover { padding: 1.1rem; }
  .cover-card {
    padding: 2.3rem 1.4rem 1.7rem;
    box-shadow: 0.6rem 0.6rem 0 rgba(72, 50, 50, 0.2);
  }
  .cover-card h1 { font-size: clamp(2.6rem, 13vw, 4rem); }
  .countdown { align-items: flex-start; flex-direction: column; gap: 0; }
  .unwrap-button { width: 100%; min-width: 0; }
  .cover-corner { display: none; }
  .topbar { padding: 0 0.8rem; }
  .hero {
    min-height: 58rem;
    align-content: center;
    padding-top: 6.5rem;
  }
  .hero-date { right: -0.12em; bottom: -0.05em; font-size: 10rem; }
  .hero h1 { font-size: clamp(4rem, 19vw, 5.5rem); }
  .hero-note br { display: none; }
  .today-note { margin-top: 1rem; padding: 1.5rem; }
  .scroll-note { display: none; }
  .chat-card { width: 92%; padding: 1.2rem; }
  .chat-card p { font-size: 1.2rem; }
  .ticket { min-height: 28rem; padding: 1.5rem; box-shadow: 0.65rem 0.65rem 0 var(--pink); }
  .ticket > p { font-size: 2.15rem; }
  .letter-section { padding-bottom: 7rem; }
  .letter-paper {
    min-height: 46rem;
    padding: 2rem 1.3rem;
    box-shadow: 0.65rem 0.65rem 0 var(--red);
  }
  .signature { align-items: flex-start; flex-direction: column; gap: 0.4rem; }
  .scratch-fallback { right: 0; left: 0; width: 100%; text-align: center; }
  .finale h2 { font-size: clamp(4.2rem, 20vw, 6.5rem); }
  footer { flex-direction: column; gap: 0.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .reveal { opacity: 1; transform: none; }
}
