:root {
  --night: #120b1e;
  --night-2: #1d1230;
  --purple: #6b3fa0;
  --orange: #ff8a1f;
  --orange-2: #ffb347;
  --bone: #f3e9ff;
  --muted: #b9a8d4;
  --bar-h: 56px;
  --ad-w: 300px;
  --ad-h: 250px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--night);
  color: var(--bone);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Landing ---------- */
.landing {
  position: relative;
  height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px 120px;
  background:
    radial-gradient(1200px 600px at 50% 120%, rgba(255, 138, 31, .18), transparent 60%),
    radial-gradient(circle at 20% 10%, #2a1846, transparent 50%),
    linear-gradient(#0b0614, var(--night) 60%, #1a0e14);
}
.landing::before { /* stars */
  content: "";
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, #fff8, transparent),
    radial-gradient(1px 1px at 30% 70%, #fff6, transparent),
    radial-gradient(1.5px 1.5px at 55% 15%, #fffa, transparent),
    radial-gradient(1px 1px at 75% 40%, #fff7, transparent),
    radial-gradient(1px 1px at 90% 10%, #fff9, transparent),
    radial-gradient(1px 1px at 65% 85%, #fff5, transparent),
    radial-gradient(1.5px 1.5px at 15% 55%, #fff8, transparent);
  pointer-events: none;
}
.moon {
  position: absolute;
  top: 8%; right: 12%;
  width: clamp(80px, 14vw, 160px); aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff7d6, #f1d98a 60%, #c9a956);
  box-shadow: 0 0 60px 20px rgba(255, 230, 150, .25);
  opacity: .9;
}
.hero { position: relative; z-index: 2; text-align: center; max-width: 720px; width: 100%; }
.logo {
  font-family: "Creepster", "Chiller", fantasy, cursive;
  font-weight: 400;
  font-size: clamp(52px, 11vw, 112px);
  line-height: 1;
  margin: 0 0 16px;
  color: var(--orange);
  letter-spacing: 2px;
  text-shadow: 0 0 24px rgba(255, 138, 31, .55), 0 4px 0 #6b2a00;
}
.tagline { font-size: clamp(17px, 2.4vw, 21px); color: var(--muted); margin: 0 auto 28px; max-width: 560px; }

.url-form { display: flex; gap: 8px; width: 100%; }
.url-form input {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  font: inherit;
  color: var(--bone);
  background: rgba(255, 255, 255, .06);
  border: 1.5px solid rgba(185, 168, 212, .35);
  border-radius: 10px;
  outline: none;
}
.url-form input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255, 138, 31, .25); }
.url-form button, .tool, #intensity {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 0;
  cursor: pointer;
}
.url-form button {
  padding: 10px 18px;
  color: #2a1000;
  background: linear-gradient(var(--orange-2), var(--orange));
  white-space: nowrap;
}
.url-form button:hover { filter: brightness(1.08); }
.url-form.big input { padding: 16px 18px; font-size: 18px; border-radius: 14px; }
.url-form.big button { padding: 16px 24px; font-size: 18px; border-radius: 14px; }

.examples { margin: 18px 0 0; color: var(--muted); font-size: 15px; }
.chip {
  font: inherit; font-size: 14px;
  margin: 4px 2px;
  padding: 4px 12px;
  color: var(--bone);
  background: rgba(107, 63, 160, .35);
  border: 1px solid rgba(185, 168, 212, .3);
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { background: rgba(107, 63, 160, .6); }
.hint { margin-top: 28px; color: var(--muted); font-size: 14px; opacity: .8; }
.foot {
  position: absolute; bottom: 14px; left: 16px;
  right: calc(var(--ad-w) + 40px);
  font-size: 12px; color: var(--muted); opacity: .6;
  z-index: 2;
}

/* ---------- Viewer ---------- */
.viewer { height: 100%; display: flex; flex-direction: column; }
.bar {
  height: var(--bar-h);
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: linear-gradient(#22143a, #170d28);
  border-bottom: 1px solid rgba(255, 138, 31, .35);
  position: relative; z-index: 40;
}
.bar-logo {
  font-family: "Creepster", fantasy, cursive;
  font-size: 26px;
  color: var(--orange);
  text-decoration: none;
  white-space: nowrap;
  text-shadow: 0 0 12px rgba(255, 138, 31, .5);
}
.bar .url-form { max-width: 640px; }
.bar-tools { display: flex; gap: 6px; margin-left: auto; }
#intensity, .tool {
  height: 40px;
  padding: 0 10px;
  color: var(--bone);
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(185, 168, 212, .3);
}
#intensity option { color: #000; }
.tool { min-width: 40px; }
.tool[aria-pressed="true"] { background: var(--purple); }

.stage { position: relative; flex: 1; background: #fff; }
#frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--night);
  color: var(--muted);
  z-index: 5;
}
.loading-pumpkin { font-size: 72px; animation: bob 1s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-14px) rotate(8deg); } }

/* ---------- Spook layer ---------- */
.spook-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 30;
}
body.viewing .spook-layer { top: var(--bar-h); }

.sprite {
  position: absolute; top: 0; left: 0;
  will-change: transform, opacity;
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
}
.sprite svg { display: block; width: 100%; height: 100%; overflow: visible; }
.sprite.dark svg { filter: drop-shadow(0 0 4px rgba(190, 140, 255, .85)) drop-shadow(0 0 1px #fff); }
.sprite.ghost svg { filter: drop-shadow(0 0 8px rgba(255, 255, 255, .8)) drop-shadow(0 3px 6px rgba(40, 0, 80, .55)); }
.sprite.pumpkin svg { filter: drop-shadow(0 0 10px rgba(255, 138, 31, .7)); }
.sprite.spider { cursor: default; }
.sprite.witch { pointer-events: none; }
.thread {
  position: absolute; top: 0;
  width: 1px;
  background: linear-gradient(rgba(220, 220, 230, .2), rgba(220, 220, 230, .85));
  transform-origin: top;
  pointer-events: none;
}

.bat .wing { transform-origin: 60px 30px; animation: flap .22s ease-in-out infinite alternate; }
@keyframes flap { from { transform: scaleY(1); } to { transform: scaleY(-.35); } }
.pumpkin .face { animation: flicker 2.4s infinite; }
@keyframes flicker { 0%, 100% { opacity: 1 } 45% { opacity: .75 } 50% { opacity: .95 } 70% { opacity: .65 } }

.poof { animation: poof .5s ease-out forwards; pointer-events: none; }
@keyframes poof { to { opacity: 0; filter: blur(6px); scale: 1.8; } }
.boo {
  position: absolute;
  font-family: "Creepster", fantasy, cursive;
  font-size: 34px;
  color: var(--orange);
  text-shadow: 0 0 10px #000, 0 0 2px #000;
  pointer-events: none;
  animation: booUp 1s ease-out forwards;
}
@keyframes booUp { from { opacity: 1; transform: translate(-50%, 0) scale(.6); } to { opacity: 0; transform: translate(-50%, -60px) scale(1.3); } }

.cobweb { position: absolute; top: 0; width: clamp(90px, 14vw, 170px); opacity: .7; pointer-events: none; }
.cobweb.left { left: 0; }
.cobweb.right { right: 0; transform: scaleX(-1); }

.fog {
  position: absolute; left: -50%; bottom: -20px;
  width: 200%; height: 140px;
  background:
    radial-gradient(ellipse 18% 60% at 10% 80%, rgba(220, 210, 240, .28), transparent 70%),
    radial-gradient(ellipse 22% 55% at 35% 90%, rgba(220, 210, 240, .22), transparent 70%),
    radial-gradient(ellipse 20% 60% at 60% 85%, rgba(220, 210, 240, .26), transparent 70%),
    radial-gradient(ellipse 25% 50% at 85% 90%, rgba(220, 210, 240, .22), transparent 70%);
  animation: drift 40s linear infinite;
  pointer-events: none;
}
.fog.two { animation-duration: 65s; animation-direction: reverse; opacity: .7; bottom: -40px; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(25%); } }

.vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(30, 0, 50, .35) 100%);
  pointer-events: none;
}
.lightning {
  position: absolute; inset: 0;
  background: #eef;
  opacity: 0;
  pointer-events: none;
}
.lightning.flash { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: 0 } 8% { opacity: .55 } 16% { opacity: .05 } 26% { opacity: .4 } 100% { opacity: 0 } }

.spook-layer.paused .sprite, .spook-layer.paused .thread,
.spook-layer.paused .fog, .spook-layer.paused .cobweb,
.spook-layer.paused .vignette { display: none; }

/* ---------- Ad ---------- */
.ad {
  position: fixed;
  right: 12px; bottom: 12px;
  z-index: 50;
  width: calc(var(--ad-w) + 12px);
  padding: 4px 6px 6px;
  background: rgba(18, 11, 30, .92);
  border: 1px solid rgba(185, 168, 212, .3);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
}
.ad-label { display: block; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); opacity: .7; margin-bottom: 3px; }
.ad-slot { width: var(--ad-w); height: var(--ad-h); overflow: hidden; border-radius: 6px; }
.ad-disclosure { margin: 4px 0 0; font-size: 10px; line-height: 1.3; color: var(--muted); opacity: .7; }

/* Amazon affiliate promo */
.promo {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  padding: 14px;
  text-align: center;
  text-decoration: none;
  color: var(--bone);
  border-radius: 6px;
  background:
    radial-gradient(circle at 80% 15%, rgba(255, 230, 150, .35) 0 18px, transparent 19px),
    radial-gradient(ellipse at 50% 110%, rgba(255, 138, 31, .45), transparent 65%),
    linear-gradient(#2a1846, #170d28);
  border: 1px solid rgba(255, 138, 31, .4);
  transition: border-color .2s, transform .2s;
}
.promo:hover { border-color: var(--orange); }
.promo:hover .promo-art { transform: rotate(-8deg) scale(1.06); }
.promo:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.promo-art { width: 84px; height: auto; flex: none; filter: drop-shadow(0 0 12px rgba(255, 138, 31, .6)); transition: transform .2s; }
.promo-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.promo-title { font-family: "Creepster", fantasy, cursive; font-weight: 400; font-size: 28px; line-height: 1.05; color: var(--orange); letter-spacing: 1px; }
.promo-sub { font-size: 14px; color: var(--muted); }
.promo-btn {
  flex: none;
  padding: 7px 16px;
  font-size: 14px; font-weight: 700;
  color: #2a1000;
  background: linear-gradient(var(--orange-2), var(--orange));
  border-radius: 999px;
  white-space: nowrap;
}

.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  background: var(--purple);
  color: #fff;
  border-radius: 10px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  :root { --ad-w: 320px; --ad-h: 50px; --bar-h: 104px; }
  .bar { flex-wrap: wrap; height: auto; min-height: var(--bar-h); padding: 8px 10px; gap: 8px; }
  .bar-logo { font-size: 22px; }
  .bar .url-form { order: 3; flex-basis: 100%; max-width: none; }
  .ad { right: 8px; bottom: 8px; max-width: calc(100vw - 16px); }
  .ad-slot { max-width: 100%; }
  .promo { flex-direction: row; justify-content: flex-start; gap: 8px; padding: 0 8px; text-align: left; }
  .promo-art { width: 36px; }
  .promo-title { font-size: 17px; }
  .promo-sub { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .promo-btn { margin-left: auto; padding: 5px 10px; font-size: 12px; }
  .ad-disclosure { font-size: 9px; }
  .foot { right: 16px; bottom: 90px; text-align: center; }
  .url-form.big { flex-direction: column; }
}
@media (max-width: 340px) {
  :root { --ad-w: 300px; }
}
