:root {
  --night: #0b1a3a;
  --night-2: #1d2f63;
  --dusk: #3a2a4f;
  --paper: #fbf3df;
  --paper-edge: #e9d7ae;
  --gold: #c8a96a;
  --ink: #4a2f1a;
  --red: #b3202c;
  --red-dark: #861620;
  --green: #2f6b3f;
  --green-dark: #1f4d2c;
  --snow: #f4f1ea;
  --glow: #ffcf7a;
  --display: "Mountains of Christmas", "Georgia", serif;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  height: 100%;
  background: linear-gradient(180deg, var(--night) 0%, var(--night-2) 55%, var(--dusk) 100%) fixed var(--night);
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--body);
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 110%, rgba(90, 59, 79, 0.8) 0%, transparent 55%) fixed;
  overflow-x: hidden;
}

#snow {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* String of twinkling lights */
.lights {
  position: fixed;
  top: -6px; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  margin: 0; padding: 0 8px;
  list-style: none;
  z-index: 2;
  pointer-events: none;
}
.lights::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 10px;
  height: 18px;
  border-bottom: 2px solid #1a2238;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.lights li {
  position: relative;
  width: 12px; height: 20px;
  margin-top: 22px;
  border-radius: 50%;
  background: var(--c, #ffd76a);
  box-shadow: 0 4px 18px 3px var(--c, #ffd76a);
  animation: twinkle 2.4s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * -0.37s);
}
.lights li::before {
  content: "";
  position: absolute;
  top: -5px; left: 3px;
  width: 6px; height: 6px;
  border-radius: 2px;
  background: #2a3046;
}
.lights li:nth-child(4n + 1) { --c: #ff5d5d; --i: 1; }
.lights li:nth-child(4n + 2) { --c: #ffd76a; --i: 3; }
.lights li:nth-child(4n + 3) { --c: #6ee28c; --i: 2; }
.lights li:nth-child(4n + 4) { --c: #79b8ff; --i: 4; }
.lights li:nth-child(n + 9) { display: none; }
@media (min-width: 640px) { .lights li:nth-child(n + 9) { display: block; } }
@keyframes twinkle { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; box-shadow: 0 4px 8px 1px var(--c); } }

main {
  position: relative;
  z-index: 3;
  max-width: 560px;
  margin: 0 auto;
  padding: 64px 18px 190px;
  text-align: center;
}

header h1 {
  margin: 4px 0 22px;
  font-family: var(--display);
  font-size: clamp(2.4rem, 10vw, 3.6rem);
  line-height: 1;
  color: var(--snow);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25), 0 0 30px rgba(255, 207, 122, 0.35);
}
header h1 span {
  display: block;
  color: #ff6b6b;
  font-size: 1.18em;
}
.kicker {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--glow);
  opacity: 0.85;
}

/* Parchment card */
.card {
  position: relative;
  padding: 28px 22px 26px;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.7), transparent 40%),
    radial-gradient(circle at 90% 95%, rgba(200, 169, 106, 0.25), transparent 40%),
    var(--paper);
  border: 3px solid var(--gold);
  border-radius: 22px;
  box-shadow: 0 0 0 6px rgba(251, 243, 223, 0.12), 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 80px rgba(255, 207, 122, 0.18);
}
.card::before, .card::after {
  content: "❄";
  position: absolute;
  top: 10px;
  font-size: 1rem;
  color: var(--gold);
}
.card::before { left: 14px; }
.card::after { right: 14px; }

.view { animation: fade-up 0.5s ease both; }
.view[hidden] { display: none; }
@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.lead { margin: 0 0 18px; font-size: 1.15rem; font-weight: 700; }
.hint { margin: 14px 0 0; font-size: 0.85rem; opacity: 0.7; }
.psst { margin: 0 0 6px; font-family: var(--display); font-size: 1.6rem; color: var(--red); }
.invite-name { font-family: var(--display); font-size: 1.5em; color: var(--green); }

form { display: flex; flex-direction: column; gap: 12px; }

input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  font: 700 1.2rem var(--body);
  color: var(--ink);
  text-align: center;
  background: #fffaf0;
  border: 2px dashed var(--gold);
  border-radius: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="text"]:focus { border-style: solid; border-color: var(--red); box-shadow: 0 0 0 4px rgba(179, 32, 44, 0.15); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 20px;
  font: 800 1.05rem var(--body);
  color: #fff;
  text-decoration: none;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.2s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); }
.btn-red { background: var(--red); box-shadow: 0 4px 0 var(--red-dark); }
.btn-red:active { box-shadow: 0 2px 0 var(--red-dark); }
.btn-green { background: var(--green); box-shadow: 0 4px 0 var(--green-dark); }
.btn-green:active { box-shadow: 0 2px 0 var(--green-dark); }
.btn-ghost { color: var(--ink); background: transparent; border: 2px solid var(--gold); }
.btn-big { width: 100%; padding: 17px 20px; font-size: 1.25rem; }
.btn-red.btn-big { background-image: repeating-linear-gradient(-45deg, transparent 0 14px, rgba(255, 255, 255, 0.08) 14px 28px); }

.link-btn {
  margin-top: 14px;
  padding: 6px;
  font: 700 0.95rem var(--body);
  color: var(--ink);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  opacity: 0.75;
}

/* Checking: the scroll */
.scroll { margin: 4px auto 18px; width: min(300px, 90%); }
.scroll-roll {
  height: 22px;
  margin: 0 -10px;
  border-radius: 12px;
  background: linear-gradient(180deg, #e8d3a2, #b99355 60%, #8f6d3a);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
  position: relative;
  z-index: 1;
}
.scroll-paper {
  position: relative;
  height: 0;
  overflow: hidden;
  margin: -6px 0;
  background: repeating-linear-gradient(180deg, #fdf6e3 0 27px, #efe2c2 27px 28px);
  box-shadow: inset 0 10px 10px -8px rgba(0, 0, 0, 0.25), inset 0 -10px 10px -8px rgba(0, 0, 0, 0.25);
  animation: unroll 0.9s cubic-bezier(.3, .8, .3, 1) forwards;
}
@keyframes unroll { to { height: 196px; } }
.scroll-names {
  margin: 0; padding: 12px 18px;
  list-style: none;
  text-align: left;
  font-family: var(--display);
  font-size: 1.25rem;
  line-height: 28px;
  color: #6b4a2c;
  animation: scroll-names 2.6s linear infinite;
}
.scroll-names li { display: flex; justify-content: space-between; filter: blur(0.6px); }
.scroll-names li::after { content: "✓"; color: var(--green); opacity: 0.6; }
.scroll-names li.x::after { content: "✗"; color: var(--red); }
@keyframes scroll-names { from { transform: translateY(0); } to { transform: translateY(-50%); } }
.quill {
  position: absolute;
  right: 12px; top: 40px;
  font-size: 2rem;
  animation: quill 0.7s ease-in-out infinite alternate;
}
@keyframes quill { from { transform: translate(0, 0) rotate(-10deg); } to { transform: translate(-30px, 70px) rotate(10deg); } }
.checking-text {
  margin: 0;
  font-family: var(--display);
  font-size: 1.7rem;
  color: var(--ink);
  min-height: 2.2em;
}

/* Result */
.result-for { margin: 0; font-size: 1.2rem; font-weight: 800; }
.result-name { font-family: var(--display); font-size: 1.7em; color: var(--ink); }

.stamp {
  display: inline-block;
  margin: 10px auto 6px;
  padding: 6px 22px 2px;
  font-family: var(--display);
  font-size: clamp(3rem, 15vw, 4.4rem);
  line-height: 1.05;
  letter-spacing: 0.03em;
  border: 6px double currentColor;
  border-radius: 14px;
  transform: rotate(-7deg);
  opacity: 0;
}
.stamp.go { animation: stamp 0.55s cubic-bezier(.2, 1.6, .4, 1) forwards; }
.result-naughty .stamp { color: var(--red); background: rgba(179, 32, 44, 0.06); }
.result-nice .stamp { color: var(--green); background: rgba(47, 107, 63, 0.06); }
@keyframes stamp {
  0% { opacity: 0; transform: scale(2.6) rotate(-16deg); }
  60% { opacity: 1; transform: scale(0.92) rotate(-6deg); }
  100% { opacity: 1; transform: scale(1) rotate(-7deg); }
}
.result-naughty .stamp.go { animation: stamp 0.55s cubic-bezier(.2, 1.6, .4, 1) forwards, wobble 0.5s 0.6s ease-in-out 2; }
@keyframes wobble { 0%, 100% { transform: rotate(-7deg); } 25% { transform: rotate(-11deg) translateX(-3px); } 75% { transform: rotate(-3deg) translateX(3px); } }

.verdict-title { margin: 0; font-family: var(--display); font-size: 2.2rem; line-height: 1; }
.verdict-line { margin: 6px 0 16px; font-weight: 700; }

.meter { margin: 0 auto 16px; max-width: 380px; text-align: left; }
.meter-label { display: flex; justify-content: space-between; font-weight: 800; font-size: 0.9rem; margin-bottom: 6px; }
.meter-track {
  height: 18px;
  border-radius: 999px;
  background: #efe2c2;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: repeating-linear-gradient(-45deg, #fff 0 8px, var(--fill, var(--green)) 8px 16px);
  transition: width 1.4s cubic-bezier(.3, .8, .3, 1);
}
.result-naughty .meter-fill { --fill: var(--red); }

.reasons {
  margin: 0 auto 10px;
  max-width: 400px;
  padding: 12px 16px;
  text-align: left;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 12px;
  border: 1px solid var(--paper-edge);
}
.reasons-title { margin: 0 0 4px; font-family: var(--display); font-size: 1.35rem; }
.reasons-list { margin: 0; padding-left: 1.3em; }
.reasons-list li { margin: 4px 0; font-weight: 700; opacity: 0; animation: fade-up 0.4s ease forwards; }
.reasons-list li:nth-child(2) { animation-delay: 0.35s; }
.result-naughty .reasons-list li::marker { content: "😈 "; }
.result-nice .reasons-list li::marker { content: "⭐ "; }

.checked-by { margin: 8px 0 18px; font-size: 0.85rem; font-style: italic; opacity: 0.75; }

.actions { display: flex; flex-direction: column; gap: 12px; }

/* Coal and dust */
.coal {
  position: fixed;
  z-index: 20;
  width: 56px; height: 44px;
  border-radius: 46% 54% 40% 60% / 55% 45% 55% 45%;
  background: radial-gradient(circle at 30% 30%, #5b5b63, #1d1d22 60%, #0d0d10);
  box-shadow: inset -4px -6px 10px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: coal-drop 1.1s cubic-bezier(.5, 0, .7, 1) forwards;
}
@keyframes coal-drop {
  0% { transform: translateY(-140px) rotate(0); opacity: 0; }
  15% { opacity: 1; }
  70% { transform: translateY(0) rotate(160deg); }
  82% { transform: translateY(-18px) rotate(180deg); }
  100% { transform: translateY(0) rotate(200deg); opacity: 0; }
}
.dust {
  position: fixed;
  z-index: 19;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: rgba(40, 40, 46, 0.55);
  pointer-events: none;
  animation: dust 0.9s ease-out forwards;
}
@keyframes dust { to { transform: translate(var(--dx), var(--dy)) scale(2.4); opacity: 0; } }

footer { margin-top: 22px; color: rgba(244, 241, 234, 0.75); font-size: 0.85rem; }
footer p { margin: 10px 0 0; }
footer .privacy { font-size: 0.75rem; opacity: 0.7; }
.sound-toggle {
  padding: 6px 14px;
  font: 700 0.85rem var(--body);
  color: var(--snow);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  cursor: pointer;
}

.globe-link {
  display: inline-block;
  margin-left: 8px;
  padding: 6px 14px;
  font: 700 0.85rem var(--body);
  color: var(--snow);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
}

/* Village */
.village {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 170px;
  z-index: 1;
  pointer-events: none;
}
.village svg { width: 100%; height: 100%; display: block; }
.window { fill: var(--glow); filter: drop-shadow(0 0 6px var(--glow)); animation: flicker 3s ease-in-out infinite; }
.window + .window { animation-delay: -1.3s; }
@keyframes flicker { 0%, 100% { opacity: 1; } 45% { opacity: 0.8; } 50% { opacity: 0.95; } 70% { opacity: 0.85; } }

/* Share dialog */
dialog {
  width: min(440px, calc(100% - 28px));
  padding: 26px 20px 20px;
  color: var(--ink);
  text-align: center;
  background: var(--paper);
  border: 3px solid var(--gold);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
dialog[open] { animation: fade-up 0.3s ease both; }
dialog::backdrop { background: rgba(5, 10, 25, 0.65); backdrop-filter: blur(3px); }
dialog h3 { margin: 6px 22px 10px; font-family: var(--display); font-size: 1.9rem; line-height: 1.1; }
dialog p { margin: 0 0 14px; }
.dialog-close-form { display: block; }
.dialog-close {
  position: absolute;
  top: 8px; right: 10px;
  width: 36px; height: 36px;
  font-size: 1.1rem;
  color: var(--ink);
  background: none;
  border: 0;
  cursor: pointer;
}
.share-step[hidden] { display: none; }
.share-link-row { display: flex; gap: 8px; margin-bottom: 12px; }
.share-link-row input { font-size: 0.95rem; padding: 10px; text-align: left; }
.native-share { margin-bottom: 12px; }
.native-share[hidden] { display: none; }
.share-grid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.share-chip {
  padding: 9px 14px;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--ink);
  text-decoration: none;
  background: #fffaf0;
  border: 2px solid var(--paper-edge);
  border-radius: 999px;
}
.share-chip:hover { border-color: var(--gold); }
.copied { min-height: 1.3em; margin: 12px 0 0 !important; font-weight: 800; color: var(--green); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .scroll-paper { height: 196px; }
  .stamp { opacity: 1; }
  .reasons-list li { opacity: 1; }
}
