/* Fonts
   - Headings: Creepster
   - Body: Inter */

:root {
  --bg: #0b0f19;
  --bg-2: #090c14;
  --accent: #ff7a18;
  --accent-2: #ffb347;
  --ghost: #cfd8ff22;
  --moon: #f4f1c9;
  --moon-shadow: #c7c5a1;
  --scene-max: 880px;
  --control-bg: #151a28;
  --control-fg: #e8ecff;
  --house: #141824;
  --house-light: #ffd54a;
  --fog: #b0b8d855;
  --pumpkin: #ff8a00;
  --pumpkin-dark: #c55a00;
  --pumpkin-shadow: #7a3400;
  --leaf: #2e7d32;
  --flame-1: #ffd04a;
  --flame-2: #ff9b00;
  --flame-3: #ff5e00;
  --star: #dbe6ff;
  --hill-back: #0b1030;
  --hill-front: #0a0d24;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  color: #e6e8ef;
  background: radial-gradient(1200px 600px at 50% -20%, #111633 10%, var(--bg) 60%, var(--bg-2) 100%);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
}

.site-header {
  max-width: var(--scene-max);
  margin: 16px auto 0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.title {
  margin: 0;
  line-height: 1;
}
.title-main {
  display: block;
  font-family: Creepster, Inter, sans-serif;
  letter-spacing: 1px;
  font-size: clamp(28px, 3.2vw, 48px);
  color: var(--accent);
  text-shadow: 0 2px 0 #000, 0 0 24px #ff880055;
}
.title-sub {
  display: block;
  font-weight: 600;
  opacity: .9;
  font-size: clamp(12px, 1.4vw, 14px);
}

.controls { display: flex; gap: 8px; position: relative; }
.btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--control-fg);
  background: linear-gradient(#1c2237, #121829);
  box-shadow: inset 0 0 0 1px #2b375f, 0 10px 20px #05070d;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); box-shadow: inset 0 0 0 1px #2b375f, 0 4px 10px #05070d; }

/* Color picker control */
.color-control { display: none; align-items: center; }
input.color {
  appearance: none;
  width: 36px; height: 36px;
  padding: 0; border: none; border-radius: 10px;
  background: var(--control-bg);
  box-shadow: inset 0 0 0 1px #2b375f, 0 10px 20px #05070d;
  cursor: pointer;
}
input.color::-webkit-color-swatch-wrapper { padding: 4px; }
input.color::-webkit-color-swatch { border: none; border-radius: 8px; }
input.color::-moz-color-swatch { border: none; border-radius: 8px; }

/* Palette dropdown */
.palette { position: absolute; top: calc(100% + 8px); left: 110px; display: grid; grid-template-columns: repeat(8, 28px); gap: 8px; padding: 10px; border-radius: 12px; background: #0e1426; box-shadow: 0 10px 30px #000a, inset 0 0 0 1px #2b375f; z-index: 10; }
.palette[hidden] { display: none; }
.swatch { width: 28px; height: 28px; border-radius: 999px; border: 2px solid #1c223a; background: var(--sw); cursor: pointer; box-shadow: 0 2px 8px #0008; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px #fff6, 0 2px 8px #0008; }

.stage-wrapper {
  display: grid;
  place-items: center;
}

.stage {
  position: relative;
  width: min(92vw, var(--scene-max));
  aspect-ratio: 16/9;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(#0c1125, #0a0e1d 35%, #070a14 70%);
  box-shadow: 0 30px 80px #0008, inset 0 0 0 1px #ffffff10;
}

/* Sky, moon, stars */
.sky {
  position: absolute; inset: 0;
  background:
    radial-gradient(1200px 600px at 50% -20%, #1a2250 10%, #0e1433 50%, #0a0f21 95%);
}

.moon {
  position: absolute;
  top: 8%; left: 8%;
  width: clamp(70px, 12vw, 150px);
  aspect-ratio: 1/1;
  background: radial-gradient(circle at 40% 35%, var(--moon) 60%, var(--moon-shadow) 100%);
  border-radius: 50%;
  box-shadow: 0 0 40px 10px #fff3, 0 0 120px 40px #fff2;
  filter: blur(0.2px);
}
.moon .crater { position: absolute; background: #c2c1a2; border-radius: 50%; opacity: .5; }
.moon .c1 { width: 18%; aspect-ratio: 1; left: 18%; top: 30%; }
.moon .c2 { width: 12%; aspect-ratio: 1; left: 55%; top: 40%; }
.moon .c3 { width: 8%; aspect-ratio: 1; left: 35%; top: 60%; }

.stars {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, var(--star) 40%, transparent 45%),
    radial-gradient(1.2px 1.2px at 20% 60%, var(--star) 40%, transparent 45%),
    radial-gradient(1px 1px at 40% 30%, var(--star) 40%, transparent 45%),
    radial-gradient(1.5px 1.5px at 60% 20%, var(--star) 40%, transparent 45%),
    radial-gradient(1px 1px at 80% 50%, var(--star) 40%, transparent 45%),
    radial-gradient(1.2px 1.2px at 70% 80%, var(--star) 40%, transparent 45%),
    radial-gradient(1px 1px at 30% 75%, var(--star) 40%, transparent 45%),
    radial-gradient(1.3px 1.3px at 85% 30%, var(--star) 40%, transparent 45%);
  opacity: .9;
  animation: twinkle 6s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: .9; }
  50% { opacity: .6; }
}

/* Bats */
.bats { position: absolute; inset: 0; pointer-events: none; }
.bat {
  position: absolute;
  width: 32px; height: 12px;
  transform-origin: 50% 50%;
  animation: fly 16s linear infinite;
}
.bat .body { position: absolute; left: 50%; top: 50%; width: 6px; height: 8px; background: #0b0b0b; border-radius: 3px; transform: translate(-50%, -50%); }
.bat .wing { position: absolute; top: 50%; width: 14px; height: 6px; background: #0b0b0b; border-radius: 50% 50% 0 0; transform-origin: 100% 0; }
.bat .wing.left { left: -2px; transform-origin: 100% 0; animation: flap 400ms ease-in-out infinite; border-top-left-radius: 8px 10px; }
.bat .wing.right { right: -2px; transform-origin: 0 0; animation: flap 400ms ease-in-out infinite; border-top-right-radius: 8px 10px; }

.bat.b1 { left: 10%; top: 18%; animation-delay: 0s; }
.bat.b2 { left: 40%; top: 12%; animation-delay: -3s; transform: scale(.9); }
.bat.b3 { left: 75%; top: 26%; animation-delay: -6s; transform: scale(1.1); }

@keyframes flap {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-25deg); }
}
@keyframes fly {
  0% { transform: translateX(-5vw) translateY(0); }
  50% { transform: translateX(5vw) translateY(8px); }
  100% { transform: translateX(-5vw) translateY(0); }
}

/* Ground and haunted house silhouette */
.ground-line {
  position: absolute; left: 0; right: 0; bottom: 24%; height: 2px; background: linear-gradient(90deg, transparent, #5f6a9a33 40%, transparent 80%);
}

.house {
  position: absolute; bottom: 24%; left: 8%; width: 28%; height: 30%;
  filter: drop-shadow(0 10px 10px #0007);
}
.tower { position: absolute; bottom: 0; width: 20%; background: var(--house); box-shadow: inset 0 0 0 2px #0008; }
.tower.t1 { left: 12%; height: 60%; }
.tower.t2 { left: 56%; height: 85%; }
.roof { position: absolute; background: var(--house); clip-path: polygon(50% 0, 100% 60%, 0 60%); height: 22%; }
.roof.r1 { left: 8%; width: 38%; bottom: 60%; }
.roof.r2 { left: 52%; width: 30%; bottom: 85%; }
.door { position: absolute; bottom: 0; left: 0; right: 0; margin: 0 auto; width: 14%; height: 26%; background: #0e1222; border-radius: 2px 2px 0 0; }
.window { position: absolute; width: 36%; height: 18%; background: #0e1222; box-shadow: inset 0 0 0 2px #000a; }
.window.w1 { left: 32%; bottom: 40%; }
.window.w2 { left: 12%; bottom: 62%; height: 14%; }

/* Pumpkin */
.pumpkin { position: absolute; bottom: 6%; right: 8%; width: min(40vmin, 360px); aspect-ratio: 4/3; display: grid; place-items: end; }
.pumpkin-body {
  position: relative; width: 100%; height: 100%;
  filter: drop-shadow(0 30px 15px #0007);
}
.pumpkin .segment {
  position: absolute; bottom: 0; width: 28%; height: 78%; background: radial-gradient(120% 80% at 50% 20%, var(--pumpkin) 0, var(--pumpkin-dark) 60%, var(--pumpkin-shadow) 100%);
  border-radius: 60% 60% 40% 40% / 70% 70% 30% 30%;
  box-shadow: inset 0 -8px 12px #0006, inset 0 8px 10px #fff1;
}
.pumpkin .s1 { left: 4%; transform: rotate(-6deg); height: 70%; }
.pumpkin .s2 { left: 20%; height: 85%; }
.pumpkin .s3 { left: 36%; height: 92%; z-index: 2; }
.pumpkin .s4 { left: 52%; height: 85%; }
.pumpkin .s5 { left: 68%; transform: rotate(6deg); height: 70%; }

.pumpkin .stem { position: absolute; left: 46%; bottom: 76%; width: 8%; height: 20%; background: linear-gradient(#2e7d32, #1b4d1d); border-radius: 4px; transform: rotate(-12deg); box-shadow: inset 0 0 0 2px #0005; }

.pumpkin .face { position: absolute; inset: 0; }
.pumpkin .eye { position: absolute; top: 40%; width: 16%; height: 12%; background: #0b0b0b; clip-path: polygon(0 100%, 50% 0, 100% 100%); filter: drop-shadow(0 0 10px #000a); }
.pumpkin .eye.left { left: 30%; transform: rotate(-10deg); }
.pumpkin .eye.right { right: 30%; transform: rotate(10deg); }
.pumpkin .nose { position: absolute; left: 50%; top: 50%; width: 8%; height: 8%; transform: translate(-50%,-40%); background: #0b0b0b; clip-path: polygon(50% 0, 0 100%, 100% 100%); }
.pumpkin .mouth { position: absolute; left: 50%; bottom: 22%; width: 48%; height: 16%; transform: translateX(-50%); background: #0b0b0b; clip-path: polygon(0 60%, 10% 80%, 20% 50%, 30% 80%, 40% 60%, 50% 85%, 60% 60%, 70% 80%, 80% 50%, 90% 80%, 100% 60%, 100% 100%, 0 100%); box-shadow: inset 0 -10px 20px #0007; }

/* Candle/glow */
.candle { position: absolute; left: 50%; bottom: 26%; width: 6%; height: 20%; transform: translateX(-50%); z-index: 1; }
.flame { position: absolute; left: 50%; bottom: 46%; width: 12px; height: 18px; transform: translateX(-50%); border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; filter: blur(.4px); mix-blend-mode: screen; }
.flame.l1 { background: radial-gradient(50% 70% at 50% 30%, #fff 0%, var(--flame-1) 35%, transparent 75%); animation: flicker1 1100ms ease-in-out infinite; }
.flame.l2 { background: radial-gradient(60% 80% at 50% 30%, var(--flame-1) 0%, var(--flame-2) 40%, transparent 80%); animation: flicker2 1200ms linear infinite; filter: blur(1px); }
.flame.l3 { background: radial-gradient(60% 80% at 50% 30%, var(--flame-2) 0%, var(--flame-3) 60%, transparent 85%); animation: flicker3 900ms ease-in-out infinite; filter: blur(2px); }

@keyframes flicker1 { 0%,100%{ transform: translateX(-50%) scale(1); opacity: .95;} 40%{ transform: translateX(calc(-50% + 1px)) scale(1.05); opacity: .9;} 60%{ transform: translateX(calc(-50% - 1px)) scale(.98); opacity: 1; } }
@keyframes flicker2 { 0%,100%{ transform: translateX(-50%) translateY(0) scaleY(1);} 50%{ transform: translateX(-50%) translateY(-1px) scaleY(1.08);} }
@keyframes flicker3 { 0%,100%{ transform: translateX(-50%) scale(.98);} 30%{ transform: translateX(-50%) scale(1.06);} 70%{ transform: translateX(-50%) scale(1);} }

/* Fog */
.fog { position: absolute; left: -20%; right: -20%; height: 28%; background: radial-gradient(60% 80% at 50% 40%, var(--fog), transparent 70%); filter: blur(6px); opacity: .6; animation: drift 40s linear infinite; }
.fog.f1 { bottom: 30%; animation-duration: 48s; }
.fog.f2 { bottom: 12%; animation-duration: 60s; opacity: .5; }
@keyframes drift {
  0% { transform: translateX(-10%); }
  50% { transform: translateX(10%); }
  100% { transform: translateX(-10%); }
}

/* Lightning (storm mode) */
.lightning { position: absolute; inset: 0; background: radial-gradient(120% 60% at 30% 10%, #ffffff22, transparent 60%); mix-blend-mode: screen; opacity: 0; pointer-events: none; }
.storm .lightning { animation: strike 5.6s infinite; }
@keyframes strike {
  0%, 95%, 100% { opacity: 0; }
  45% { opacity: 0; }
  46% { opacity: .8; }
  47% { opacity: 0; }
  49% { opacity: .55; }
  52% { opacity: 0; }
}

/* Storm windows glow */
.storm .window { background: radial-gradient(circle at 50% 50%, var(--house-light) 0 60%, #0e1222 62%); box-shadow: 0 0 10px 2px #ffd54a22, inset 0 0 0 2px #000a; }

/* Pause animations */
.paused *, .paused *::before, .paused *::after { animation-play-state: paused !important; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .bats .wing, .bats .bat, .stars, .fog, .lightning, .flame { animation: none !important; }
}

.note { max-width: var(--scene-max); margin: 0 auto; padding: 0 16px 24px; color: #b8c2ea; }
.site-footer { text-align: center; color: #a9b4dc; padding: 8px 16px 24px; font-size: 14px; opacity: .85; }

/* Utility - screen reader only */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Parallax hills */
.hills { position: absolute; left: -10%; right: -10%; bottom: 24%; height: 24%; pointer-events: none; }
.hills.back {
  background: radial-gradient(120% 80% at 20% 100%, var(--hill-back) 20%, transparent 22%),
              radial-gradient(120% 80% at 60% 100%, var(--hill-back) 20%, transparent 22%),
              radial-gradient(120% 80% at 90% 100%, var(--hill-back) 20%, transparent 22%);
  filter: blur(1px);
  transform: translateZ(0);
}
.hills.front {
  bottom: 22%; height: 26%;
  background: radial-gradient(120% 80% at 30% 100%, var(--hill-front) 20%, transparent 22%),
              radial-gradient(120% 80% at 70% 100%, var(--hill-front) 20%, transparent 22%);
}

/* Witch flyby */
.witch { position: absolute; top: 18%; left: -10%; width: 60px; height: 30px; animation: flyby 18s linear infinite; opacity: .9; filter: drop-shadow(0 2px 0 #000); }
.witch .hat { position: absolute; left: 8px; top: 0; width: 22px; height: 10px; background: #0b0b0b; clip-path: polygon(0 100%, 20% 70%, 60% 70%, 100% 0, 80% 100%); }
.witch .head { position: absolute; left: 22px; top: 8px; width: 10px; height: 10px; background: #0b0b0b; border-radius: 50%; }
.witch .cloak { position: absolute; left: 28px; top: 12px; width: 22px; height: 14px; background: #0b0b0b; clip-path: polygon(0 0, 100% 20%, 80% 100%, 0 60%); }
.witch .broom { position: absolute; left: 0; top: 16px; width: 50px; height: 6px; background: #1a1208; box-shadow: inset -20px 0 0 #4c3a22; border-radius: 2px; transform: rotate(4deg); }
@keyframes flyby {
  0% { transform: translateX(0) translateY(0) scale(1); }
  40% { transform: translateX(60vw) translateY(6px) scale(1.05); }
  50% { transform: translateX(70vw) translateY(0) scale(1.05); }
  100% { transform: translateX(110vw) translateY(-4px) scale(1.1); }
}

/* Ghost */
.ghost { position: absolute; left: 68%; top: 34%; width: 46px; height: 58px; background: radial-gradient(60% 60% at 50% 30%, #ffffffdd 30%, #cfd8ffbb 70%, #cfd8ff55 100%); border-radius: 50% 50% 40% 40%/ 50% 50% 30% 30%; animation: floaty 5.5s ease-in-out infinite; filter: blur(.2px); }
.ghost::after { content: ""; position: absolute; left: 0; right: 0; bottom: -8px; height: 12px; background: radial-gradient(10px 6px at 8px 0, #cfd8ffbb 60%, transparent 65%), radial-gradient(10px 6px at 22px 0, #cfd8ffbb 60%, transparent 65%), radial-gradient(10px 6px at 36px 0, #cfd8ffbb 60%, transparent 65%); }
.ghost .eye { position: absolute; top: 18px; width: 6px; height: 8px; background: #0b0b0b; border-radius: 50%; filter: drop-shadow(0 0 2px #000); }
.ghost .eye.e1 { left: 14px; }
.ghost .eye.e2 { left: 26px; }
.ghost .mouth { position: absolute; top: 30px; left: 50%; width: 10px; height: 8px; transform: translateX(-50%); background: #0b0b0b; border-radius: 0 0 8px 8px; }
@keyframes floaty { 0%,100% { transform: translateY(0); opacity: .95; } 50% { transform: translateY(-8px); opacity: 1; } }

/* Spider */
.spider { position: absolute; left: 78%; top: -20%; width: 20px; height: 24px; pointer-events: none; opacity: 0; }
.spider .thread { position: absolute; left: 50%; top: -120px; width: 1px; height: 120px; background: #9fb0ff33; transform: translateX(-50%); }
.spider .body { position: absolute; left: 50%; top: 0; width: 18px; height: 18px; background: #0b0b0b; border-radius: 50%; transform: translateX(-50%); box-shadow: 0 2px 0 #000; }
.spider .leg { position: absolute; width: 14px; height: 2px; background: #0b0b0b; top: 6px; }
.spider .leg.l1 { left: -6px; transform: rotate(20deg); }
.spider .leg.l2 { left: -6px; top: 10px; transform: rotate(-10deg); }
.spider .leg.l3 { right: -6px; transform: rotate(-20deg); }
.spider .leg.l4 { right: -6px; top: 10px; transform: rotate(10deg); }
.spider-active .spider { animation: drop 3.2s ease-in-out forwards; opacity: 1; }
@keyframes drop { 0% { top: -20%; } 40% { top: 18%; } 60% { top: 16%; } 100% { top: -20%; } }

/* Shooting star */
.shooting-star { position: absolute; top: 12%; left: -10%; width: 2px; height: 2px; background: #fff; border-radius: 50%; box-shadow: 0 0 8px 2px #fff8; opacity: 0; }
.shooting-star::after { content: ""; position: absolute; left: -80px; top: 0; width: 80px; height: 2px; background: linear-gradient(90deg, #ffffffaa, transparent); transform: rotate(0.5turn); transform-origin: right center; }
.shooting-star.active { animation: shoot 2.2s ease-in-out 1; }
@keyframes shoot { 0% { opacity: 0; transform: translate(0, 0); } 10% { opacity: 1; } 100% { opacity: 0; transform: translate(110vw, 30vh); } }

/* Theme toggle: alternate palette */
.alt-theme { --bg: #140b19; --bg-2: #0f0714; --accent: #ad7aff; --accent-2: #e0b3ff; --moon: #f1e9ff; --moon-shadow: #c9b7ff; --hill-back: #1a0f33; --hill-front: #120a26; --pumpkin: #ff6a00; --pumpkin-dark: #b94a00; --pumpkin-shadow: #6a2e00; --star: #efe4ff; }


