:root {
  color-scheme: dark;
  --card-width: min(560px, calc(100vw - 32px));
  --card-height: min(500px, calc(100vh - 24px));
  --card-radius: 24px;
  --card-background: rgba(24, 20, 36, 0.76);
  --purple-border: rgba(164, 105, 255, 0.35);
  --purple-glow: rgba(139, 76, 255, 0.28);
  --muted: rgba(238, 238, 242, 0.56);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: transparent;
}

body {
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  color: #fff;
}

.page-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 12px;
}

.gift-card {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: var(--card-width);
  height: var(--card-height);
  min-height: 0;
  max-height: 500px;
  overflow: hidden;
  border-radius: var(--card-radius);
  background: var(--card-background);
  border: 1px solid var(--purple-border);
  box-shadow:
    0 0 18px var(--purple-glow),
    0 0 48px rgba(112, 50, 220, 0.16),
    inset 0 0 20px rgba(151, 90, 255, 0.06),
    0 12px 30px rgba(0, 0, 0, 0.22);
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 420ms ease, transform 420ms ease, visibility 420ms ease;
}

.gift-card:not(.is-hidden) {
  animation: gift-card-glow 900ms ease-out both;
}

.gift-card.is-hidden {
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  transform: translateY(12px) scale(0.985);
}

.animation-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 20px 24px 0;
}

.animation {
  width: min(380px, calc(100vw - 80px), calc(100vh - 150px));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
}

.animation > canvas,
.animation > svg {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.gift-copy {
  padding: 0 24px 15px;
  text-align: center;
}

.gift-copy h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 29px);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.02em;
}

.gift-model-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 17px;
  margin-top: 3px;
  line-height: 1.15;
}

.gift-model {
  color: rgba(249, 247, 255, 0.9);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.15;
}

.gift-rarity {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 36px;
  height: 24px;
  padding: 0 9px;
  box-sizing: border-box;
  border: 1px solid rgba(174, 122, 255, 0.55);
  border-radius: 999px;
  background: rgba(139, 76, 255, 0.22);
  color: #f2eaff;
  white-space: nowrap;
  overflow: visible;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.gift-rarity[hidden] {
  display: none;
}

.gift-collectible {
  display: inline-block;
  margin: 4px 0 0;
  padding: 4px 9px;
  border-radius: 9px;
  background: rgba(10, 8, 16, 0.56);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

@keyframes gift-card-glow {
  0% {
    box-shadow:
      0 0 30px rgba(164, 105, 255, 0.42),
      0 0 72px rgba(112, 50, 220, 0.24),
      inset 0 0 26px rgba(181, 125, 255, 0.1),
      0 12px 30px rgba(0, 0, 0, 0.22);
  }

  100% {
    box-shadow:
      0 0 18px var(--purple-glow),
      0 0 48px rgba(112, 50, 220, 0.16),
      inset 0 0 20px rgba(151, 90, 255, 0.06),
      0 12px 30px rgba(0, 0, 0, 0.22);
  }
}

.debug-ui {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  width: min(460px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 14px;
  background: rgba(7, 8, 12, 0.92);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
}

.debug-ui button {
  width: 100%;
  padding: 10px 13px;
  border: 0;
  border-radius: 9px;
  background: #2f9ef4;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.debug-ui button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.debug-log {
  max-height: 26vh;
  margin-top: 10px;
  overflow: auto;
  color: #d6f7dd;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

@media (max-width: 620px), (max-height: 520px) {
  :root {
    --card-width: calc(100vw - 20px);
    --card-height: min(500px, calc(100vh - 20px));
  }

  .page-shell {
    padding: 10px;
  }

  .gift-card {
    border-radius: 22px;
  }

  .animation-stage {
    padding: 16px 16px 0;
  }

  .animation {
    width: min(380px, calc(100vw - 52px), calc(100vh - 128px));
  }

  .gift-copy {
    padding: 0 16px 18px;
  }

  .gift-copy h1 {
    font-size: 26px;
  }

  .gift-model {
    font-size: 14px;
  }

  .gift-rarity {
    font-size: 13px;
  }

  .gift-collectible {
    margin-top: 6px;
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gift-card,
  .gift-card:not(.is-hidden) {
    animation: none;
    transition-duration: 1ms;
  }
}
