:root {
  --bg: #060508;
  --bg-raised: #120e16;
  --ink: #dcd0b8;
  --ink-dim: #8c8170;
  --ink-faint: #3d372f;
  --gold: #b8935a;
  --gold-faint: rgba(184, 147, 90, 0.28);
  --key: #a6e6e8;
  --key-glow: rgba(120, 215, 225, 0.55);
  --blood: #8f3b33;
  --serif: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --display: 'Cinzel', 'Trajan Pro', Georgia, serif;
  --radius: 10px;
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 120% 70% at 50% -10%, #1b1422 0%, transparent 60%),
    radial-gradient(ellipse 80% 50% at 50% 110%, #0f0b13 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.fog {
  position: fixed;
  inset: -30%;
  pointer-events: none;
  z-index: 0;
}

.fog::before,
.fog::after {
  content: '';
  position: absolute;
  inset: 0;
  filter: blur(60px);
}

.fog::before {
  background:
    radial-gradient(circle at 30% 40%, rgba(90, 62, 110, 0.16) 0%, transparent 35%),
    radial-gradient(circle at 70% 65%, rgba(60, 40, 70, 0.14) 0%, transparent 30%);
  animation: drift 70s ease-in-out infinite alternate;
}

.fog::after {
  background:
    radial-gradient(circle at 60% 30%, rgba(120, 80, 50, 0.08) 0%, transparent 30%),
    radial-gradient(circle at 25% 75%, rgba(70, 50, 90, 0.1) 0%, transparent 35%);
  animation: drift 95s ease-in-out infinite alternate-reverse;
}

main {
  position: relative;
  z-index: 1;
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(56px, 12vh, 128px) 16px 120px;
}

header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  margin-bottom: clamp(56px, 11vh, 112px);
  text-align: center;
}

.count {
  font-family: var(--display);
  font-size: clamp(72px, 16vw, 132px);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-shadow:
    0 0 48px rgba(227, 162, 82, 0.22),
    0 0 2px rgba(255, 235, 205, 0.35);
  opacity: 0;
  animation: rise 2.2s 0.2s cubic-bezier(0.2, 0.7, 0.1, 1) forwards;
}

.count:has(#hidden:empty) {
  visibility: hidden;
}

.count-label {
  font-family: var(--serif);
  font-size: clamp(20px, 3vw, 26px);
  font-style: italic;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
  text-shadow: none;
  white-space: pre;
}

.hints {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 36ch;
  font-size: clamp(19px, 2.6vw, 23px);
  font-style: italic;
  line-height: 1.35;
  color: var(--ink-dim);
}

.hints:empty {
  display: none;
}

.hints li {
  opacity: 0;
  animation: rise 1.6s cubic-bezier(0.2, 0.7, 0.1, 1) forwards;
  animation-delay: calc(var(--i, 0) * 140ms + 500ms);
}

#redeem {
  opacity: 0;
  animation: rise 1.6s 0.9s ease-out forwards;
}

#code {
  width: min(300px, 78vw);
  padding: 12px 0 12px 0.5em;
  border: 0;
  border-bottom: 1px solid var(--ink-faint);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 0.5em;
  text-align: center;
  text-transform: uppercase;
  caret-color: var(--key);
  outline: none;
  transition: border-color 0.5s, box-shadow 0.5s, color 0.5s;
  -webkit-appearance: none;
  appearance: none;
}

#code::placeholder {
  color: var(--ink-faint);
}

#code:focus {
  border-color: var(--gold);
  box-shadow: 0 12px 24px -16px var(--gold);
}

#code:focus::placeholder {
  color: transparent;
}

#redeem.rejected #code {
  border-color: var(--blood);
  color: #c98a80;
  animation: shake 0.5s;
}

#redeem.accepted #code {
  border-color: var(--key);
  box-shadow: 0 14px 34px -12px var(--key);
}

.keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  min-height: 10px;
  max-width: 320px;
}

.key {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle, #f0ffff 0%, var(--key) 45%, rgba(166, 230, 232, 0) 75%);
  box-shadow: 0 0 14px 3px var(--key-glow);
  animation: flicker 3.2s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * -0.73s);
}

.key.kindled {
  animation:
    kindle 1.6s cubic-bezier(0.2, 0.7, 0.1, 1),
    flicker 3.2s 1.6s ease-in-out infinite;
}

.key.fading {
  animation: fade 0.9s ease-in forwards;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(190px, calc(50% - 10px)), 1fr));
  gap: clamp(18px, 3.4vw, 40px);
  perspective: 1800px;
}

.vow {
  margin-top: clamp(64px, 12vh, 120px);
  text-align: center;
  font-size: clamp(18px, 2.4vw, 22px);
  font-style: italic;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
  opacity: 0;
  animation: rise 1.6s 2s ease-out forwards;
}

.card {
  position: relative;
  aspect-ratio: 672 / 1184;
  cursor: pointer;
  outline: none;
  opacity: 0;
  animation: rise 1.6s cubic-bezier(0.2, 0.7, 0.1, 1) forwards;
  animation-delay: calc(var(--i, 0) * 90ms + 1s);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 1.2s cubic-bezier(0.25, 0.8, 0.15, 1);
}

.card.flipped .inner {
  transform: rotateY(180deg);
}

.card.denied .inner {
  animation: shake 0.5s;
}

.side {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--gold-faint);
  background: var(--bg-raised);
  box-shadow: 0 24px 48px -24px #000, 0 0 0 1px #000;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: box-shadow 0.6s, border-color 0.6s;
}

.side::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow:
    inset 0 0 0 7px rgba(6, 5, 8, 0.55),
    inset 0 0 0 8px var(--gold-faint),
    inset 0 0 60px rgba(0, 0, 0, 0.6);
}

.veil img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(0.55) saturate(0.6) contrast(1.08);
  transition: filter 0.9s, transform 1.4s cubic-bezier(0.2, 0.7, 0.1, 1);
}

.veil::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(6, 5, 8, 0) 50%, rgba(6, 5, 8, 0.92) 100%);
}

.category {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.veil .category {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 22px;
  z-index: 2;
  text-align: center;
  padding-left: 0.32em;
}

@media (hover: hover) {
  .card.locked:hover .veil img {
    filter: brightness(0.7) saturate(0.75) contrast(1.08);
    transform: scale(1.03);
  }

  .card.locked:hover .veil {
    border-color: rgba(184, 147, 90, 0.5);
  }

  .keyhole:not(:disabled):hover .plate {
    filter: brightness(1.2) contrast(1.05);
  }

  .keyhole:not(:disabled):hover {
    transform: translateX(-50%) scale(1.07);
  }
}

.card.unlocked {
  cursor: pointer;
}

.card:focus-visible .side {
  border-color: var(--gold);
}

.keyhole {
  position: absolute;
  left: 50%;
  bottom: 13%;
  z-index: 2;
  width: 42%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  outline: none;
  transform: translateX(-50%);
  transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.1, 1);
  -webkit-tap-highlight-color: transparent;
}

.keyhole .glow,
.keyhole .plate {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.keyhole .glow {
  inset: 8%;
  background: radial-gradient(circle, rgba(130, 225, 235, 0.75) 0%, rgba(130, 225, 235, 0) 70%);
  filter: blur(12px);
  animation: breathe 3.4s ease-in-out infinite;
  transition: opacity 0.8s;
}

.keyhole .plate {
  background: url('/keyhole.webp') center / contain no-repeat;
  transition: filter 0.8s;
}

.keyhole:focus-visible .plate {
  box-shadow: 0 0 0 1px var(--key);
}

.keyhole:disabled {
  cursor: default;
}

.keyhole:disabled .glow {
  opacity: 0;
  animation: none;
}

.keyhole:disabled .plate {
  filter: grayscale(1) brightness(0.5) contrast(1.15);
}

.keyhole.beckon .glow {
  animation: beckon-key 1.2s ease-out;
}

.keyhole.turning .plate {
  filter: none;
  animation: turn 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.keyhole.turning .glow {
  opacity: 1;
  animation: flare 0.9s ease-out forwards;
}

.card.unlocked .keyhole {
  display: none;
}

.reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px 22px;
  text-align: center;
  transform: rotateY(180deg);
  background:
    radial-gradient(ellipse 90% 60% at 50% 35%, #211a26 0%, rgba(33, 26, 38, 0) 70%),
    #0b090d;
}

.reveal .category {
  color: var(--gold);
  padding-left: 0.32em;
}

.desc {
  margin: 0;
  max-height: 100%;
  min-height: 0;
  overflow-y: auto;
  font-size: clamp(17px, 2.3vw, 21px);
  line-height: 1.45;
  white-space: pre-line;
  overflow-wrap: anywhere;
  scrollbar-width: none;
}

.desc::-webkit-scrollbar {
  display: none;
}

.card.igniting .reveal {
  animation: ignite 2.4s ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

@keyframes drift {
  from {
    transform: translate3d(-4%, -3%, 0) rotate(0deg);
  }
  to {
    transform: translate3d(5%, 4%, 0) rotate(8deg);
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

@keyframes flicker {
  0%, 100% { opacity: 1; transform: scale(1); }
  30% { opacity: 0.72; transform: scale(0.92); }
  55% { opacity: 0.95; transform: scale(1.04); }
  75% { opacity: 0.8; transform: scale(0.97); }
}

@keyframes kindle {
  0% { opacity: 0; transform: scale(0); box-shadow: 0 0 0 0 var(--key-glow); }
  40% { opacity: 1; transform: scale(2.2); box-shadow: 0 0 40px 14px var(--key-glow); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes fade {
  to { opacity: 0; transform: scale(0.2); }
}

@keyframes breathe {
  0%, 100% { opacity: 0.45; transform: scale(0.92); }
  50% { opacity: 1; transform: scale(1.12); }
}

@keyframes beckon-key {
  0% { opacity: 1; transform: scale(1); }
  35% { opacity: 1; transform: scale(1.45); }
  100% { opacity: 0.6; transform: scale(1); }
}

@keyframes turn {
  0% { transform: rotate(0) scale(1); }
  55% { transform: rotate(90deg) scale(1.08); filter: brightness(1.5); }
  100% { transform: rotate(90deg) scale(1.25); filter: brightness(2.4); opacity: 0; }
}

@keyframes flare {
  0% { transform: scale(1); }
  60% { transform: scale(1.8); opacity: 1; }
  100% { transform: scale(2.4); opacity: 0; }
}

@keyframes ignite {
  0% { box-shadow: 0 0 80px 20px rgba(150, 230, 238, 0.6); border-color: #d8fbfc; }
  100% { box-shadow: 0 24px 48px -24px #000, 0 0 0 1px #000; border-color: var(--gold-faint); }
}

@media (prefers-reduced-motion: reduce) {
  .fog::before,
  .fog::after,
  .keyhole .glow {
    animation: none;
  }

  .inner {
    transition-duration: 0.01s;
  }

  .count,
  .hints li,
  #redeem,
  .vow,
  .card {
    animation-duration: 0.01s;
    animation-delay: 0s;
  }
}
