:root {
  --ink: #24304f;
  --muted: #68728c;
  --rose: #f47f9d;
  --rose-deep: #d8436d;
  --sky: #8bc8ec;
  --mint: #9fd9bf;
  --gold: #e9bd63;
  --paper: rgba(255, 255, 255, 0.76);
  --card-shadow: 0 24px 70px rgba(78, 71, 126, 0.24);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #fff6f8;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  overflow-x: hidden;
  background:
    linear-gradient(115deg, rgba(255, 214, 224, 0.58), transparent 34%),
    linear-gradient(245deg, rgba(167, 219, 247, 0.64), transparent 40%),
    linear-gradient(0deg, rgba(244, 213, 141, 0.28), transparent 52%),
    linear-gradient(135deg, #fff7f5 0%, #f5fbff 48%, #fffaf0 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -3;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.45) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.36) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.65), transparent 82%);
}

button {
  font: inherit;
}

.page-shell {
  width: min(1080px, calc(100% - 28px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.hero {
  min-height: 23vh;
  display: grid;
  align-content: end;
  gap: 12px;
  padding: 24px 2px 18px;
}

.eyebrow {
  margin: 0;
  color: var(--rose-deep);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero h1 {
  max-width: 12ch;
  margin: 0;
  font-size: 2.55rem;
  line-height: 0.96;
  letter-spacing: 0;
  color: #202848;
  text-wrap: balance;
}

.hero-copy {
  max-width: 34rem;
  margin: 0;
  color: #5b637d;
  font-size: 1rem;
  line-height: 1.8;
}

.control-panel {
  position: sticky;
  top: 12px;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  margin: 10px 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
  box-shadow: 0 16px 50px rgba(92, 87, 130, 0.14);
  backdrop-filter: blur(18px);
}

.progress-card {
  display: grid;
  place-items: center;
  min-width: 78px;
  min-height: 54px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.75);
}

.progress-label {
  color: var(--muted);
  font-size: 0.72rem;
}

.progress-card strong {
  color: #24304f;
  font-size: 1.2rem;
}

.draw-button,
.accept-button {
  position: relative;
  isolation: isolate;
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  font-weight: 900;
  letter-spacing: 0;
  cursor: pointer;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.2), transparent 22%),
    linear-gradient(135deg, #e64a73, #f29b78 48%, #77bce6);
  box-shadow: 0 16px 34px rgba(226, 74, 114, 0.28);
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    opacity 180ms ease;
}

.draw-button:hover,
.accept-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 44px rgba(226, 74, 114, 0.32);
}

.draw-button:disabled,
.accept-button:disabled {
  cursor: wait;
  opacity: 0.68;
  transform: none;
}

.button-glow {
  position: absolute;
  inset: -45% auto -45% -35%;
  z-index: -1;
  width: 46%;
  transform: rotate(16deg);
  background: rgba(255, 255, 255, 0.42);
  filter: blur(6px);
  animation: buttonSweep 2.7s ease-in-out infinite;
}

.reset-button,
.close-button {
  border: 0;
  color: #69718d;
  cursor: pointer;
  background: transparent;
}

.reset-button {
  min-height: 44px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.reset-button:hover {
  background: rgba(255, 255, 255, 0.72);
}

.board-section {
  padding: 8px 0 22px;
}

.gift-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}

.gift-card {
  position: relative;
  min-width: 0;
  aspect-ratio: 0.72;
  border: 0;
  border-radius: 8px;
  cursor: default;
  perspective: 1100px;
  background: transparent;
  padding: 0;
}

.gift-card.is-hidden {
  cursor: pointer;
}

.gift-card.is-hidden:hover .gift-inner {
  transform: translateY(-4px) rotateX(2deg) rotateY(-3deg);
}

.gift-card:disabled {
  opacity: 1;
}

.gift-card.is-open .gift-inner {
  transform: rotateY(180deg);
}

.gift-card.is-new .gift-inner {
  animation: gridReveal 850ms cubic-bezier(0.2, 0.8, 0.16, 1);
}

.gift-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  border-radius: 8px;
  transition: transform 720ms cubic-bezier(0.2, 0.8, 0.18, 1);
  box-shadow: var(--card-shadow);
}

.gift-face {
  position: absolute;
  inset: 0;
  display: grid;
  overflow: hidden;
  border-radius: 8px;
  backface-visibility: hidden;
}

.gift-front {
  transform: rotateY(180deg);
  background: #ffffff;
}

.gift-front img,
.reveal-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gift-front::after,
.reveal-front::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  background:
    linear-gradient(to top, rgba(21, 25, 48, 0.74), rgba(21, 25, 48, 0.08) 48%, transparent 70%),
    radial-gradient(circle at 20% 12%, rgba(255, 255, 255, 0.6), transparent 24%);
}

.gift-caption,
.reveal-caption {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 2;
  color: #ffffff;
  text-align: left;
}

.gift-caption span,
.reveal-caption span {
  display: inline-grid;
  place-items: center;
  min-width: 42px;
  height: 24px;
  margin-bottom: 8px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  backdrop-filter: blur(10px);
}

.gift-caption h3,
.reveal-caption h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.18;
  letter-spacing: 0;
}

.gift-caption p,
.reveal-caption p {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.78rem;
  line-height: 1.45;
}

.gift-back,
.reveal-back {
  display: grid;
  place-items: center;
  padding: 14px;
  color: #ffffff;
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 255, 255, 0.26), transparent 21%),
    linear-gradient(145deg, rgba(247, 136, 163, 0.96), rgba(125, 184, 226, 0.94) 48%, rgba(239, 191, 103, 0.92));
}

.gift-back::before,
.reveal-back::before {
  position: absolute;
  inset: 0;
  content: "";
  background-image:
    radial-gradient(circle, rgba(255, 255, 255, 0.62) 0 1px, transparent 2px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 44%);
  background-size:
    28px 28px,
    100% 100%;
  opacity: 0.58;
}

.gift-back::after,
.reveal-back::after {
  position: absolute;
  inset: 8px;
  content: "";
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  pointer-events: none;
}

.back-content {
  position: relative;
  z-index: 2;
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-rows: 1fr auto auto;
  gap: 10px;
  align-items: center;
}

.shadow-collage,
.card-back-pattern {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 14rem);
  margin: 0 auto;
}

.shadow-collage span,
.card-back-pattern span {
  display: block;
  aspect-ratio: 1.1;
  border-radius: 8px;
  opacity: 0.74;
  filter: blur(0.45px);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.46), rgba(255, 255, 255, 0.08)),
    radial-gradient(circle at 52% 42%, var(--tone), transparent 52%);
  box-shadow:
    inset 0 0 18px rgba(255, 255, 255, 0.22),
    0 10px 24px rgba(54, 58, 94, 0.16);
}

.back-title {
  position: relative;
  z-index: 2;
  align-self: end;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 900;
  text-shadow: 0 2px 12px rgba(67, 52, 100, 0.25);
}

.back-subtitle {
  position: relative;
  z-index: 2;
  align-self: start;
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.24), transparent 18rem),
    rgba(32, 36, 68, 0.62);
  backdrop-filter: blur(18px);
  transition:
    opacity 260ms ease,
    visibility 260ms ease;
}

.overlay.is-active {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.reveal-wrap {
  position: relative;
  display: grid;
  gap: 22px;
  justify-items: center;
}

.reveal-card {
  width: min(78vw, 390px);
  aspect-ratio: 0.72;
  perspective: 1400px;
  filter: drop-shadow(0 30px 72px rgba(0, 0, 0, 0.28));
}

.reveal-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  border-radius: 8px;
}

.overlay.is-active .reveal-inner {
  animation:
    revealFlight 2.6s cubic-bezier(0.16, 0.78, 0.16, 1) forwards,
    slowTurn 7s 2.6s ease-in-out infinite;
}

.reveal-face {
  position: absolute;
  inset: 0;
  display: grid;
  overflow: hidden;
  border-radius: 8px;
  backface-visibility: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.48),
    0 26px 70px rgba(20, 24, 48, 0.28);
}

.reveal-front {
  transform: rotateY(180deg);
  background: #ffffff;
}

.reveal-caption {
  right: 18px;
  bottom: 18px;
  left: 18px;
}

.reveal-caption h2 {
  font-size: 1.55rem;
}

.card-back-pattern {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 72%;
}

.spark-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.spark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--size);
  height: var(--size);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: var(--spark);
  box-shadow: 0 0 18px var(--spark);
  animation: sparkBurst var(--duration) ease-out forwards;
}

.accept-button {
  min-width: min(72vw, 280px);
  padding: 0 28px;
}

.finale-overlay {
  overflow-y: auto;
  align-items: start;
}

.finale-panel {
  position: relative;
  width: min(980px, 100%);
  margin: 28px 0;
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 28px 90px rgba(20, 24, 48, 0.25);
  backdrop-filter: blur(22px);
}

.finale-panel h2 {
  margin: 8px 42px 8px 0;
  font-size: 1.9rem;
  line-height: 1.05;
  letter-spacing: 0;
}

.finale-panel p {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.7;
}

.close-button {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  color: #46506b;
  font-size: 1.45rem;
  line-height: 1;
}

.close-button:hover {
  background: #ffffff;
}

.finale-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.finale-item {
  position: relative;
  min-height: 220px;
  overflow: hidden;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 44px rgba(58, 65, 105, 0.16);
}

.finale-item img {
  width: 100%;
  height: 100%;
  min-height: 220px;
  object-fit: cover;
}

.finale-item div {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  padding: 12px;
  border-radius: 8px;
  color: #ffffff;
  background: linear-gradient(to top, rgba(29, 34, 63, 0.72), rgba(29, 34, 63, 0.18));
  backdrop-filter: blur(8px);
}

.finale-item strong {
  display: block;
  font-size: 1rem;
}

.finale-item span {
  display: block;
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.8rem;
}

@media (min-width: 720px) {
  .page-shell {
    padding-top: 46px;
  }

  .hero {
    min-height: 26vh;
    padding-bottom: 26px;
  }

  .hero h1 {
    max-width: 16ch;
    font-size: 5.2rem;
  }

  .hero-copy {
    font-size: 1.15rem;
  }

  .gift-caption h3 {
    font-size: 1.25rem;
  }

  .gift-caption p {
    font-size: 0.9rem;
  }

  .back-title {
    font-size: 1.36rem;
  }

  .reveal-caption h2 {
    font-size: 2.2rem;
  }

  .reveal-caption p {
    font-size: 0.95rem;
  }

  .finale-panel h2 {
    font-size: 3.1rem;
  }

  .gift-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
  }

  .control-panel {
    grid-template-columns: 120px minmax(220px, 360px) auto;
    justify-content: center;
    width: max-content;
    max-width: 100%;
    margin-right: auto;
    margin-left: auto;
    padding: 12px;
  }

  .finale-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
  }
}

@media (max-width: 430px) {
  .page-shell {
    width: min(100% - 18px, 1080px);
    padding-bottom: 38px;
  }

  .control-panel {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
  }

  .reset-button {
    grid-column: 1 / -1;
    justify-self: center;
    min-height: 32px;
  }

  .gift-grid {
    gap: 9px;
  }

  .shadow-collage {
    gap: 6px;
  }

  .gift-back {
    padding: 10px;
  }

  .gift-caption {
    right: 9px;
    bottom: 9px;
    left: 9px;
  }

  .overlay {
    padding: 14px;
  }

  .finale-panel {
    padding: 20px 14px 16px;
    border-radius: 8px;
  }
}

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

@keyframes buttonSweep {
  0% {
    transform: translateX(0) rotate(16deg);
  }

  62%,
  100% {
    transform: translateX(360%) rotate(16deg);
  }
}

@keyframes revealFlight {
  0% {
    transform: translate3d(0, 34vh, 0) scale(0.35) rotateY(0deg) rotateZ(-16deg);
  }

  38% {
    transform: translate3d(0, -4vh, 0) scale(0.86) rotateY(540deg) rotateZ(8deg);
  }

  68% {
    transform: translate3d(0, 0, 0) scale(1.04) rotateY(900deg) rotateZ(-2deg);
  }

  100% {
    transform: translate3d(0, 0, 0) scale(1) rotateY(900deg) rotateZ(0deg);
  }
}

@keyframes slowTurn {
  0%,
  100% {
    transform: rotateY(900deg) rotateX(0deg) rotateZ(0deg);
  }

  50% {
    transform: rotateY(916deg) rotateX(2deg) rotateZ(0.4deg);
  }
}

@keyframes sparkBurst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.2);
  }

  16% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1);
  }
}

@keyframes gridReveal {
  0% {
    transform: rotateY(180deg) scale(0.92);
    filter: brightness(1.8);
  }

  100% {
    transform: rotateY(180deg) scale(1);
    filter: brightness(1);
  }
}
