@font-face {
  font-family: 'Instrument Serif';
  src: url('assets/InstrumentSerif-Regular.ttf') format('truetype');
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Instrument Serif';
  src: url('assets/InstrumentSerif-Italic.ttf') format('truetype');
  font-style: italic;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #f9f4e9;
  --ink: #35271f;
  --red: #a63733;
  --blue: #4c6596;
  --rule: #d6c6ac;
  --serif: 'Instrument Serif', 'Times New Roman', serif;
  --sans: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: #f2ebdd;
  color: var(--ink);
  font-family: var(--sans);
}

.stationery {
  width: min(100% - 64px, 1232px);
  margin: clamp(20px, 4vw, 60px) auto;
  padding: 0 clamp(26px, 5.05vw, 74px);
  border: 1px solid #e2d5be;
  background-color: var(--paper);
  background-image: radial-gradient(ellipse at 45% 40%, #fffcf2 0%, transparent 74%);
  box-shadow: 0 12px 44px #60432313, 0 1px 2px #60432312;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 95px;
  border-bottom: 1px solid var(--rule);
}

.card-label {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: #5f4e40;
  font-size: 13px;
  letter-spacing: .05em;
}

.card-label > span { color: var(--red); font-size: 21px; line-height: 1; }

.header-controls { display: flex; align-items: center; gap: 19px; }

.music-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--blue);
  font: 500 .875rem/1.25 var(--sans);
  white-space: nowrap;
  cursor: pointer;
}

.music-toggle:hover { background: #ede7dc; }
.music-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.music-toggle > span[aria-hidden] { font-size: 1.15rem; }

.postmark {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 4px 11px 5px;
  border: 1px solid #a6373380;
  border-radius: 49% 46% 48% 43% / 47% 48% 46% 49%;
  color: var(--red);
  font: 24px/1 var(--serif);
  transform: rotate(8deg);
}

.postmark > span { margin-left: 2px; font-size: 11px; }

.birthday {
  display: grid;
  grid-template-columns: minmax(0, 0.91fr) minmax(0, 1.09fr);
  align-items: center;
  gap: clamp(22px, 4vw, 60px);
  padding: clamp(58px, 6.3vw, 90px) 0 clamp(44px, 5.6vw, 78px);
}

.birthday h1 {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin: 0;
  font: 400 clamp(72px, 10.2vw, 152px)/.76 var(--serif);
  letter-spacing: -.032em;
}

.birthday h1 em {
  margin: .065em 0 0 -.025em;
  color: var(--red);
  font-weight: 400;
}

.birthday h1 small {
  position: relative;
  margin-top: .33em;
  color: var(--blue);
  font-size: .47em;
  font-style: italic;
  font-weight: 400;
  letter-spacing: -.016em;
  line-height: .9;
}

.birthday h1 small::after {
  position: absolute;
  right: -.07em;
  bottom: -.13em;
  left: .05em;
  height: .15em;
  border-top: 2px solid #7389b9;
  border-radius: 46%;
  transform: rotate(-5deg);
  content: '';
}

.birthday-action { margin-top: clamp(28px, 4vw, 53px); }

.birthday-action p { margin: 0 0 13px; color: #645245; font-size: 15px; }

.wish {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 136px;
  min-height: 47px;
  padding: 9px 18px;
  border: 1px solid #8e2e2b;
  border-radius: 6px 9px 7px 8px;
  background: var(--red);
  box-shadow: 3px 3px 0 #eabf9d;
  color: #fff9ea;
  font: 600 14px/1.4 var(--sans);
  cursor: pointer;
  transition: background 180ms, transform 180ms, box-shadow 180ms;
}

.wish:hover { background: #8e2e2b; transform: translateY(-2px); box-shadow: 3px 5px 0 #eabf9d; }
.wish:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #eabf9d; }
.wish:focus-visible { outline: 2px solid var(--blue); outline-offset: 5px; }
.wish-spark { font-size: 20px; font-weight: 400; line-height: 1; }

.illustration { min-width: 0; margin: 0; }

.illustration-paper {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  border: 1px solid #e8cd8c;
  border-radius: 4px 7px 5px 4px;
  background-color: #fae7b6;
  background-image: radial-gradient(circle at 48% 45%, #fff0cacc, transparent 80%), repeating-linear-gradient(0deg, #6c502e0b 0 1px, transparent 1px 4px);
  box-shadow: 5px 8px 0 #dec59d41, 0 2px 5px #7452291c;
  transform: rotate(2.5deg);
}

.tape {
  position: absolute;
  z-index: 1;
  top: -15px;
  left: 41%;
  width: 22%;
  height: 28px;
  clip-path: polygon(0 5%, 100% 0, 97% 21%, 100% 49%, 97% 69%, 100% 94%, 0 100%, 2% 74%, 0 53%, 3% 26%);
  background-color: #efb6a4d1;
  background-image: repeating-linear-gradient(90deg, transparent 0 4px, #bf6a6e12 4px 6px);
  transform: rotate(-8deg);
}

.art { position: relative; width: 100%; }
.art img { display: block; width: 100%; height: auto; }

.blown-out .art img {
  clip-path: polygon(0 0, 27% 0, 27% 31.9%, 35.45% 31.9%, 35.45% 29.4%, 36.05% 29.4%, 36.05% 31.9%, 45.6% 31.9%, 45.6% 0, 100% 0, 100% 100%, 0 100%);
}

.candle-smoke {
  position: absolute;
  top: 29.4%;
  left: 35.7%;
  pointer-events: none;
  width: 4%;
  height: 9%;
  border-left: 2px solid #807061;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-20%, -100%) rotate(18deg);
}

.blown-out .candle-smoke { animation: smoke 900ms ease-out both; }

.margin-star { position: absolute; line-height: 1; pointer-events: none; }
.margin-star-top { top: 12%; left: 8.5%; color: #ad493d; font-size: clamp(22px, 3vw, 40px); transform: rotate(12deg); }
.margin-star-bottom { right: 7%; bottom: 11%; color: #5a70a9; font-size: clamp(17px, 2.4vw, 29px); transform: rotate(-11deg); }

.keepsake {
  position: relative;
  width: min(100%, 530px);
  margin: 0 auto 44px;
  padding: 23px 28px;
  border: 1px solid #ebd2af;
  border-radius: 5px 8px 5px 7px;
  background: #fff8e7;
  color: #57382d;
  text-align: center;
  animation: unfold 320ms ease-out both;
}

.keepsake p { margin: 0; font-size: clamp(15px, 2.5vw, 19px); line-height: 1.8; }

.memory-portrait {
  position: relative;
  width: min(92%, 390px);
  margin: 0 auto clamp(35px, 6vw, 70px);
  padding: clamp(8px, 1.35vw, 16px);
  border: 1px solid #e4d5bc;
  border-radius: 4px 7px 5px 5px;
  background: #fffaf1;
  box-shadow: 3px 5px 0 #dec59d45;
  animation: unfold 620ms ease-out 660ms both;
}

.memory-portrait img { display: block; width: 100%; height: auto; border: 1px solid #e9deca; }

.memory-portrait.reveal-on-view:not(.in-view) {
  opacity: 0;
  animation: none;
}

.memory-portrait::before {
  position: absolute;
  top: -9px;
  left: calc(50% - 32px);
  width: 64px;
  height: 18px;
  background: #efb6a4cf;
  transform: rotate(-8deg);
  content: '';
}

.card-end {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 26px;
  color: #a63733;
  font: 23px/1 var(--serif);
}

.card-end::before, .card-end::after { flex: 1; height: 1px; background: var(--rule); content: ''; }

.confetti { position: fixed; z-index: 2; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute;
  top: -28px;
  left: var(--x);
  font: 21px/1 serif;
  animation: fall var(--duration) var(--delay) cubic-bezier(.25,.15,.65,.95) both;
}

@keyframes smoke { 10% { opacity: .57; } to { opacity: 0; transform: translate(90%, -190%) rotate(-25deg); } }
@keyframes unfold { from { opacity: 0; transform: translateY(9px); } }
@keyframes fall { to { opacity: .18; transform: translate(var(--drift), 105dvh) rotate(320deg); } }

@media (max-width: 760px) {
  .stationery { width: min(100% - 28px, 510px); margin: 14px auto; padding: 0 clamp(19px, 6vw, 34px); }
  .card-header { min-height: 68px; gap: 8px; }
  .card-label { gap: 7px; }
  .music-toggle { padding-inline: 4px; }
  .card-header .postmark { display: none; }
  .birthday { display: flex; flex-direction: column; align-items: stretch; gap: 31px; padding: 33px 0 33px; }
  .birthday-copy { display: contents; }
  .birthday h1 { font-size: clamp(69px, 16.5vw, 105px); }
  .birthday-action { order: 1; margin-top: 0; }
  .illustration { width: calc(100% - 8px); margin: 3px auto 0; }
  .tape { top: -10px; height: 22px; }
  .keepsake { margin-bottom: 28px; }
  .card-end { padding-bottom: 16px; }
}

@media (max-width: 360px) {
  .birthday h1 { font-size: clamp(55px, 19vw, 69px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .memory-portrait.reveal-on-view:not(.in-view) { opacity: 1; }
}
