* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  display: grid;
  place-items: center;
  background: #10243b;
  color: #fff3da;
  font-family: system-ui, sans-serif;
}

.landscape,
.snow {
  position: fixed;
  pointer-events: none;
}

.landscape {
  inset: -4%;
  background:
    linear-gradient(#07182c55, #07182c22),
    url("karacsonyi-taj.webp") center / cover no-repeat;
  animation: landscape-drift 24s ease-in-out infinite alternate;
}

@keyframes landscape-drift {
  from { transform: translateX(-2%) scale(1.02); }
  to { transform: translateX(2%) scale(1.08); }
}

.snow {
  inset: 0;
  overflow: hidden;
  z-index: 2;
}

.snowflake {
  position: absolute;
  top: -12px;
  left: var(--left);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: white;
  opacity: var(--opacity);
  animation: snowfall var(--duration) linear var(--delay) infinite;
}

@keyframes snowfall {
  to { transform: translate(var(--drift), calc(100vh + 24px)); }
}

.scene {
  position: relative;
  z-index: 1;
  width: min(100% - 32px, 520px);
  padding: 24px 0;
  text-align: center;
}

h1 {
  margin: 0 0 12px;
  font: bold clamp(2.5rem, 8vw, 4.5rem) / 1 Georgia, serif;
  text-shadow: 0 4px 24px #081527;
}

.santa {
  width: clamp(150px, 32vw, 225px);
  aspect-ratio: 1;
  margin: 0 auto;
  background: url("mikulas.webp") 0% 0% / 400% 200% no-repeat;
  filter: drop-shadow(0 10px 12px #11243a88);
  animation: santa-sway 2.8s ease-in-out infinite;
  transform-origin: bottom center;
}

@keyframes santa-sway {
  50% { transform: translateY(-4px) rotate(1deg); }
}

.panel {
  background: #fff3da;
  color: #472b26;
  border: 2px solid #d5ab64;
  border-radius: 20px;
  padding: 16px 24px 22px;
  box-shadow: 0 12px 30px #08152777;
}

button {
  background: #a82635;
  color: white;
  border: 0;
  border-radius: 12px;
  padding: 12px 32px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  opacity: 0.65;
  cursor: default;
}

#ticket {
  --flight-duration: 650ms;
  --reindeer-slide-duration: 1200ms;
  --reindeer-finish-delay: calc(
    var(--flight-duration) + var(--reindeer-slide-duration)
  );
  width: min(580px, calc(100% - 24px));
  aspect-ratio: 2 / 1;
  padding: clamp(10px, 3vw, 24px) clamp(24px, 8vw, 64px);
  overflow: visible;
  border: 0;
  color: #442707;
  text-align: center;
  background: transparent url("arany-jegy.webp") center / 100% 100% no-repeat;
  isolation: isolate;
}

#ticket[open] {
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  align-items: center;
  animation: ticket-fly var(--flight-duration) cubic-bezier(.2, .8, .25, 1) both;
}

#ticket::backdrop {
  background: #07182caa;
}

#ticket-title {
  align-self: end;
  margin: 0 0 5px;
  font-size: clamp(0.75rem, 3vw, 1rem);
  font-weight: 700;
}

#ticket-name {
  margin: 0;
  font: bold clamp(1.35rem, 6vw, 3.5rem) / 1.05 Georgia, serif;
  overflow-wrap: anywhere;
}

#ticket[open] #ticket-name {
  animation: name-reveal 320ms ease-out var(--flight-duration) both;
}

#ticket form {
  align-self: start;
  margin-top: 6px;
}

#ticket button {
  padding: 5px 16px;
  font-size: clamp(0.75rem, 3vw, 0.9rem);
}

#ticket::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  mask: url("arany-jegy.webp") center / 100% 100% no-repeat;
  background:
    linear-gradient(
      115deg,
      transparent 42%,
      #ffd76855 46%,
      #fff7cecc 50%,
      #ffd76855 54%,
      transparent 58%
    ) 100% 50% / 300% 100% no-repeat;
}

#ticket[open]::before {
  animation: ticket-shine 900ms ease-in-out var(--flight-duration) 2;
}

#ticket[open]::after {
  content: "";
  position: absolute;
  inset: 12%;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse, #fff5b9, #ffc94a88 45%, transparent 72%);
  animation: ticket-trail var(--flight-duration) ease-out both;
}

@keyframes ticket-fly {
  from {
    opacity: 0;
    transform: translate(var(--from-x, 0px), var(--from-y, 0px))
               scale(.18) rotate(-12deg);
  }

  to {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(0);
  }
}

@keyframes ticket-shine {
  from { background-position: 100% 50%; }
  to { background-position: 0% 50%; }
}

@keyframes ticket-trail {
  0% { opacity: 0; transform: scale(1); }
  35% { opacity: 0.9; transform: scale(1.7); }
  100% { opacity: 0; transform: scale(1.25); }
}

@keyframes name-reveal {
  from { opacity: 0; transform: translateY(6px) scale(.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.ticket-spark {
  position: absolute;
  top: 50%;
  left: 50%;
  pointer-events: none;
  color: #ffe69c;
  font-size: var(--spark-size);
  line-height: 1;
  text-shadow: 0 0 8px #ffc44d, 0 0 16px #ffaf2b;
  animation: ticket-spark-burst 850ms ease-out var(--spark-delay) both;
}

@keyframes ticket-spark-burst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.3);
  }

  15% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(
      calc(-50% + var(--spark-x)),
      calc(-50% + var(--spark-y))
    ) rotate(70deg) scale(.7);
  }
}

/* A rénszarvas a név fölött áll meg. */
.ticket-reindeer {
  position: absolute;
  left: 50%;
  bottom: 87%;
  width: clamp(95px, 24vw, 165px);
  aspect-ratio: 1;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%);
  transform-origin: bottom center;
  filter: drop-shadow(0 5px 6px #40210e55);
}

.reindeer-slide-sprite,
.reindeer-finish-sprite {
  position: absolute;
  inset: 0;
  background-position: 0% 0%;
  background-size: 200% 200%;
  background-repeat: no-repeat;
}

.reindeer-slide-sprite {
  background-image: url("renszarvas-csuszas.webp");
}

.reindeer-finish-sprite {
  background-image: url("renszarvas-fenyek.webp");
  visibility: hidden;
}

#ticket[open] .ticket-reindeer {
  animation:
    reindeer-slide var(--reindeer-slide-duration)
    cubic-bezier(.22, .45, .35, 1) var(--flight-duration) both;
}

#ticket[open] .reindeer-slide-sprite {
  animation:
    reindeer-slide-frames var(--reindeer-slide-duration)
    steps(1, end) var(--flight-duration) both;
}

#ticket[open] .reindeer-finish-sprite {
  animation:
    reindeer-finish-frames 960ms
    steps(1, end) var(--reindeer-finish-delay) forwards;
}

/* A figura folyamatosan mozog, a mancsmozdulat külön vált képkockát. */
@keyframes reindeer-slide {
  from {
    opacity: 1;
    transform: translateX(calc(-50vw - 100%)) rotate(-5deg);
  }

  to {
    opacity: 1;
    transform: translateX(-50%) rotate(0);
  }
}

@keyframes reindeer-slide-frames {
  0%, 42% { background-position: 0% 0%; }
  14%, 56% { background-position: 100% 0%; }
  28%, 70% { background-position: 0% 100%; }
  84% { background-position: 100% 100%; }
  100% { visibility: hidden; }
}

@keyframes reindeer-finish-frames {
  0% {
    visibility: visible;
    background-position: 0% 0%;
  }

  25% { background-position: 100% 0%; }
  50% { background-position: 0% 100%; }

  75%, 100% {
    visibility: visible;
    background-position: 100% 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .landscape,
  .santa,
  .snowflake,
  #ticket[open],
  #ticket[open]::before,
  #ticket[open] #ticket-name,
  #ticket[open] .ticket-reindeer,
  #ticket[open] .reindeer-slide-sprite,
  #ticket[open] .reindeer-finish-sprite {
    animation: none;
  }

  .snow,
  #ticket[open]::after,
  .ticket-spark {
    display: none;
  }

  #ticket[open] .ticket-reindeer {
    opacity: 1;
  }

  #ticket[open] .reindeer-slide-sprite {
    visibility: hidden;
  }

  #ticket[open] .reindeer-finish-sprite {
    visibility: visible;
    background-position: 100% 100%;
  }
}
#draw-form {
  display: grid;
  gap: 8px;
  justify-items: center;
}

#draw-code {
  width: min(100%, 300px);
  padding: 10px 12px;
  border: 1px solid #a87a38;
  border-radius: 10px;
  font: inherit;
}

#already-drawn {
  width: min(460px, calc(100% - 24px));
  border: 2px solid #d5ab64;
  border-radius: 20px;
  padding: 18px;
  background: #fff3da;
  color: #472b26;
  text-align: center;
  overflow: hidden;
}

#already-drawn::backdrop {
  background: #07182caa;
}

.angry-santa {
  width: min(210px, 42vh, 60vw);
  aspect-ratio: 1;
  margin: 0 auto;
  background: url("mikulas-duhos.webp") 0 0 / 200% 200% no-repeat;
}

#already-drawn[open] .angry-santa {
  animation: angry-approach 1s ease-in both,
             angry-steps .32s steps(1, end) 3;
}

@keyframes angry-approach {
  from { transform: translateY(-12%) scale(.25); }
  to { transform: translateY(0) scale(1); }
}

@keyframes angry-steps {
  0% { background-position: 0% 0%; }
  25% { background-position: 100% 0%; }
  50% { background-position: 0% 100%; }
  75% { background-position: 100% 100%; }
}

@media (prefers-reduced-motion: reduce) {
  #already-drawn[open] .angry-santa { animation: none; }
}

#already-drawn form {
  margin-top: 8px;
}

#recovery-status:empty {
  display: none;
}
