/* Trunk or Treat voter page: Halloween night theme.
   Only transform/opacity are animated so it stays smooth on phones; every decorative
   layer is aria-hidden and pointer-events:none; prefers-reduced-motion turns motion off. */
:root {
  --night: #0b0614;
  --night-2: #160b26;
  --plum: #2a1446;
  --card: rgba(27, 14, 44, 0.82);
  --card-2: rgba(40, 20, 64, 0.9);
  --line: rgba(160, 110, 255, 0.22);
  --text: #f6efff;
  --muted: #c3b3dc;
  --pumpkin: #ff7a1a;
  --pumpkin-2: #ffb347;
  --ember: #d05620;           /* Emetrix brand orange */
  --slime: #7dff5a;
  --slime-2: #b8ff4d;
  --ghost: #eef2ff;
  --red: #ff6b7a;
  --radius: 18px;
  --display: "Creepster", "Chiller", fantasy, system-ui;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--night); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  font: 17px/1.5 var(--body);
  background:
    radial-gradient(900px 520px at 80% -120px, #3b1d63 0%, transparent 65%),
    radial-gradient(700px 500px at -10% 30%, #23103d 0%, transparent 70%),
    linear-gradient(180deg, var(--night-2) 0%, var(--night) 55%, #07040d 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }
a { color: var(--pumpkin-2); }

/* ---------------------------------------------------------------- night sky */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.star {
  position: absolute; width: 2px; height: 2px; border-radius: 50%; background: #fff;
  opacity: .25; animation: twinkle var(--d, 3s) ease-in-out var(--delay, 0s) infinite;
}
.star.big { width: 3px; height: 3px; box-shadow: 0 0 6px #fff; }
@keyframes twinkle { 0%, 100% { opacity: .15; transform: scale(.8); } 50% { opacity: .95; transform: scale(1.15); } }

.moon {
  position: absolute; top: 14px; right: 14px; width: 64px; height: 64px; border-radius: 50%;
  background:
    radial-gradient(circle at 30% 38%, rgba(200, 170, 100, .55) 0 7px, transparent 8px),
    radial-gradient(circle at 62% 64%, rgba(200, 170, 100, .45) 0 11px, transparent 12px),
    radial-gradient(circle at 66% 30%, rgba(200, 170, 100, .35) 0 5px, transparent 6px),
    radial-gradient(circle at 35% 35%, #fffbe6, #ffe8a3 55%, #e9c46a 100%);
  box-shadow: 0 0 40px 10px rgba(255, 226, 140, .35), 0 0 120px 40px rgba(255, 190, 90, .14);
  animation: moonglow 6s ease-in-out infinite;
}
@keyframes moonglow { 50% { transform: scale(1.04); box-shadow: 0 0 55px 16px rgba(255, 226, 140, .45), 0 0 160px 60px rgba(255, 190, 90, .18); } }

/* bats: an SVG <use>, flown across with transform only */
.bat { position: absolute; left: 0; width: 46px; height: 24px; color: #06030b; opacity: .9; animation: fly var(--dur, 16s) linear var(--delay, 0s) infinite; }
.bat svg { width: 100%; height: 100%; display: block; animation: flap .28s ease-in-out infinite alternate; transform-origin: 50% 40%; }
@keyframes fly {
  0%   { transform: translate(-80px, var(--y, 120px)) scale(var(--s, 1)); }
  25%  { transform: translate(25vw, calc(var(--y, 120px) - 40px)) scale(var(--s, 1)); }
  50%  { transform: translate(52vw, calc(var(--y, 120px) + 20px)) scale(var(--s, 1)); }
  75%  { transform: translate(78vw, calc(var(--y, 120px) - 30px)) scale(var(--s, 1)); }
  100% { transform: translate(calc(100vw + 80px), var(--y, 120px)) scale(var(--s, 1)); }
}
@keyframes flap { from { transform: scaleY(1); } to { transform: scaleY(.45); } }

/* ghosts bobbing at the edges */
.ghost-float { position: absolute; width: 54px; opacity: .22; animation: bob 7s ease-in-out infinite; }
.ghost-float.g1 { left: 4%; top: 46%; }
.ghost-float.g2 { right: 5%; top: 70%; width: 40px; animation-duration: 9s; animation-delay: -3s; }
@keyframes bob { 0%, 100% { transform: translate(0, 0) rotate(-4deg); } 50% { transform: translate(10px, -26px) rotate(5deg); } }

/* fog: two wide translucent bands drifting sideways */
.fog { position: absolute; left: 0; bottom: -40px; width: 200%; height: 46vh; opacity: .55; will-change: transform; animation: drift 38s linear infinite;
  background:
    radial-gradient(40% 55% at 15% 70%, rgba(190, 170, 230, .22), transparent 70%),
    radial-gradient(35% 45% at 45% 80%, rgba(170, 150, 220, .18), transparent 70%),
    radial-gradient(40% 55% at 65% 70%, rgba(190, 170, 230, .22), transparent 70%),
    radial-gradient(35% 45% at 95% 80%, rgba(170, 150, 220, .18), transparent 70%);
}
.fog.f2 { bottom: -80px; opacity: .4; animation-duration: 60s; animation-direction: reverse; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ---------------------------------------------------------------- layout */
.wrap { position: relative; z-index: 1; max-width: 560px; margin: 0 auto; padding: 18px 16px calc(130px + env(safe-area-inset-bottom)); }

.hero { text-align: center; padding: 58px 0 22px; }
@media (min-width: 700px) { .hero { padding-top: 40px; } }
.hero-row { display: flex; align-items: center; justify-content: center; gap: 10px; }
.lantern { font-size: 2.1rem; line-height: 1; display: inline-block; animation: flicker 3.2s infinite; filter: drop-shadow(0 0 10px rgba(255, 140, 30, .75)); }
.lantern.r { animation-delay: -1.3s; }
@keyframes flicker {
  0%, 100% { opacity: 1; transform: rotate(-3deg) scale(1); }
  8% { opacity: .65; } 10% { opacity: 1; }
  40% { transform: rotate(3deg) scale(1.06); }
  62% { opacity: .8; } 64% { opacity: 1; }
}
.hero h1 {
  font-family: var(--display); font-weight: 400; font-size: clamp(2.6rem, 11vw, 3.6rem); letter-spacing: .02em; line-height: 1.02;
  color: var(--pumpkin);
  text-shadow: 0 0 18px rgba(255, 122, 26, .55), 0 3px 0 #5a1f00, 0 0 42px rgba(255, 90, 0, .35);
  animation: rise .9s cubic-bezier(.2, .9, .3, 1.2) both;
}
.hero .sub { color: var(--muted); margin-top: 10px; font-size: 1.05rem; animation: fadeup .8s .25s both; }
.hero .sub b { color: var(--slime); font-weight: 800; text-shadow: 0 0 10px rgba(125, 255, 90, .45); }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes fadeup { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 18px; margin-bottom: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .04);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.center { text-align: center; }
.card h2 { font-family: var(--display); font-weight: 400; font-size: 2rem; letter-spacing: .03em; color: var(--slime); text-shadow: 0 0 14px rgba(125, 255, 90, .4); margin-bottom: 6px; }
.muted { color: var(--muted); }

/* state transitions (JS adds .enter / .leave) */
/* fill-mode backwards (not both): a lingering transform would trap the fixed submit bar */
.view.enter { animation: viewin .45s cubic-bezier(.2, .8, .2, 1) backwards; }
.view.leave { animation: viewout .2s ease-in both; }
@keyframes viewin { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes viewout { to { opacity: 0; transform: translateY(-10px) scale(.98); } }

/* loading */
.loader { font-size: 2.8rem; display: inline-block; animation: hop 1s ease-in-out infinite; }
@keyframes hop { 0%, 100% { transform: translateY(0) rotate(-8deg); } 50% { transform: translateY(-14px) rotate(8deg); } }
#loadingMsg { margin-top: 8px; color: var(--muted); }

/* ---------------------------------------------------------------- ballot */
.cat { border: 1px solid var(--line); background: var(--card); border-radius: var(--radius); padding: 14px 14px 16px; margin: 0 0 18px; transition: border-color .3s, box-shadow .3s; }
.cat legend { font-family: var(--display); font-weight: 400; font-size: 1.75rem; letter-spacing: .04em; padding: 0 8px; color: var(--pumpkin-2); display: flex; align-items: center; gap: 8px; }
.cat legend .emoji { font-size: 1.5rem; }
.cat legend .check { font-family: var(--body); font-size: .8rem; font-weight: 800; color: #0b1a05; background: var(--slime); border-radius: 99px; padding: 2px 9px; letter-spacing: 0; opacity: 0; transform: scale(.4); transition: opacity .25s, transform .35s cubic-bezier(.3, 1.8, .5, 1); }
.cat.done { border-color: rgba(125, 255, 90, .45); box-shadow: 0 0 0 1px rgba(125, 255, 90, .18), 0 0 26px rgba(125, 255, 90, .12); }
.cat.done legend .check { opacity: 1; transform: scale(1); }

.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 58px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card-2); cursor: pointer;
  transition: border-color .2s, background-color .2s, transform .15s;
  -webkit-tap-highlight-color: transparent;
}
/* staggered entrance; JS removes .in once it has played so the pick wobble can take over */
.opt.in { animation: cardin .5s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(min(var(--i, 0), 14) * 45ms + 80ms); }
@keyframes cardin { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: none; } }
.opt:active { transform: scale(.98); }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt .dot {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(195, 179, 220, .55);
  display: grid; place-items: center; font-size: 1.05rem; line-height: 1; transition: border-color .2s, background-color .2s;
}
.opt .dot::after { content: "🎃"; opacity: 0; transform: scale(0) rotate(-90deg); transition: opacity .2s, transform .45s cubic-bezier(.3, 1.9, .5, 1); }
.num { font-weight: 800; color: var(--pumpkin-2); min-width: 2.4em; font-variant-numeric: tabular-nums; }
.txt { display: flex; flex-direction: column; min-width: 0; }
.txt strong { font-weight: 800; }
.txt small { color: var(--muted); }

.opt:has(input:checked) {
  border-color: var(--pumpkin); background-color: rgba(255, 122, 26, .16);
  box-shadow: 0 0 0 1px var(--pumpkin), 0 0 22px rgba(255, 122, 26, .38);
  animation: wobble .55s ease both;
}
.opt:has(input:checked) .dot { border-color: var(--pumpkin); background: rgba(255, 122, 26, .18); }
.opt:has(input:checked) .dot::after { opacity: 1; transform: scale(1) rotate(0); }
.opt:has(input:focus-visible) { outline: 3px solid var(--slime); outline-offset: 2px; }
/* fallback for browsers without :has(): JS also sets .picked */
.opt.picked { border-color: var(--pumpkin); background-color: rgba(255, 122, 26, .16); box-shadow: 0 0 0 1px var(--pumpkin), 0 0 22px rgba(255, 122, 26, .38); }
.opt.picked .dot::after { opacity: 1; transform: scale(1) rotate(0); }
@keyframes wobble {
  0% { transform: scale(1); } 25% { transform: scale(1.03) rotate(-1.2deg); }
  50% { transform: scale(1.02) rotate(1deg); } 75% { transform: scale(1.01) rotate(-.5deg); } 100% { transform: none; }
}

.err { color: var(--red); font-weight: 700; margin: 8px 0; text-align: center; }

.submit-bar { position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(to top, rgba(7, 4, 13, .97) 65%, transparent); }
.progress { max-width: 528px; height: 6px; margin: 0 auto 10px; border-radius: 99px; background: rgba(160, 110, 255, .2); overflow: hidden; }
.progress span { display: block; height: 100%; width: 100%; transform-origin: left; transform: scaleX(var(--p, 0)); background: linear-gradient(90deg, var(--slime), var(--slime-2)); box-shadow: 0 0 12px var(--slime); transition: transform .45s cubic-bezier(.3, 1.4, .5, 1); }
.btn {
  appearance: none; display: block; width: 100%; max-width: 528px; margin: 0 auto; padding: 17px; border-radius: 16px;
  font: 800 1.1rem/1.2 var(--body); cursor: pointer; border: 0; color: #2a0f00;
  background: linear-gradient(180deg, var(--pumpkin-2), var(--pumpkin)); box-shadow: 0 6px 0 #8a3200, 0 10px 30px rgba(255, 122, 26, .35);
  transition: transform .12s, box-shadow .12s, opacity .2s, filter .2s;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #8a3200, 0 6px 18px rgba(255, 122, 26, .3); }
.btn:disabled { cursor: not-allowed; filter: grayscale(.65) brightness(.7); box-shadow: 0 4px 0 #3a2a3a; }
.btn.ready { animation: pulse 1.6s ease-in-out infinite; }
.btn:focus-visible { outline: 3px solid var(--slime); outline-offset: 3px; }
@keyframes pulse { 50% { box-shadow: 0 6px 0 #8a3200, 0 0 36px rgba(255, 150, 40, .75); } }

/* ---------------------------------------------------------------- done */
.big { font-size: 4.2rem; line-height: 1; display: inline-block; filter: drop-shadow(0 0 18px rgba(255, 122, 26, .7)); animation: bounce 1.1s cubic-bezier(.3, 1.6, .5, 1) both, flicker 3s 1.1s infinite; }
@keyframes bounce { 0% { transform: scale(0) rotate(-30deg); } 70% { transform: scale(1.15) rotate(6deg); } 100% { transform: none; } }
.picks { list-style: none; padding: 0; margin: 18px 0; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.picks li { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--card-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; animation: cardin .5s cubic-bezier(.2, .8, .2, 1) both; }
.picks li:nth-child(2) { animation-delay: .12s; } .picks li:nth-child(3) { animation-delay: .24s; }
.picks span { color: var(--muted); }
.picks strong { text-align: right; }

/* celebration particles (WAAPI drives them) */
.boom { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.boom i { position: absolute; left: 50%; top: 60%; font-style: normal; font-size: 1.6rem; will-change: transform, opacity; }

/* ---------------------------------------------------------------- footer */
.brand { margin: 34px 0 0; text-align: center; }
.brand a {
  display: inline-flex; align-items: center; gap: 10px; padding: 12px 18px; min-height: 48px; border-radius: 99px; text-decoration: none;
  color: var(--muted); background: rgba(20, 10, 34, .7); border: 1px solid rgba(208, 86, 32, .45);
  box-shadow: 0 0 0 1px rgba(208, 86, 32, .08), 0 0 24px rgba(208, 86, 32, .18); transition: border-color .2s, box-shadow .2s, transform .2s;
}
.brand a:hover, .brand a:focus-visible { border-color: var(--pumpkin); box-shadow: 0 0 30px rgba(255, 122, 26, .35); transform: translateY(-1px); outline: none; }
.brand .by { font-size: .85rem; letter-spacing: .02em; }
.brand .mark { font: 900 1.12rem/1 var(--body); letter-spacing: .22em; color: #fff; }
.brand .mark em { font-style: normal; color: var(--ember); text-shadow: 0 0 10px rgba(208, 86, 32, .6); }
.brand .tag { display: block; margin-top: 8px; font-size: .78rem; color: rgba(195, 179, 220, .7); }

/* ---------------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .bat, .fog.f2 { display: none; }
  .star { opacity: .6; }
}
@media (min-width: 700px) { .moon { top: 34px; right: 7vw; width: 120px; height: 120px; } }
