/* Halloween week (26 to 31 October). /scripts/season.js adds .halloween to
   <html> on those days (unless the visitor switched it off with the 🎃
   button), plus one style class:
     hw-pastel  each page keeps its own background, with faded pumpkins over it
     hw-dusk    each page's own colour, darkened to twilight, games on cream pages
     hw-night   a night sky full of pumpkins, games on cream pages
   Everything hangs off .halloween, so it all switches itself off on 1 November. */

html.halloween {
  --pumpkin: #f28c28;
  --pumpkin-soft: #f6a95a;
  --ghost: #f6ecda;      /* light text on the dark styles */
  --parchment: #fdf6ea;  /* the side panels, in the dark styles */
  /* Each game's centre column keeps its own original colour (Nick's call):
     the page colour on a phone, the lighter middle band on a computer, or
     cream for the games that use cream (Crease, Killer Clues) */
  --hw-center: var(--page, var(--cream));
}
@media (min-width: 1200px) {
  html.halloween { --hw-center: var(--middle, var(--page, var(--cream))); }
}

/* ===== In every style ===== */

/* Bats: over the wordmark on the home page, beside each game's title */
.halloween body:has(.hero)::before {
  content: "";
  position: absolute;
  z-index: 5;
  top: 10px;
  left: 50%;
  width: 150px;
  height: 56px;
  margin-left: -75px;
  background: url("/styles/halloween/bats.svg") no-repeat center / contain;
  pointer-events: none;
  animation: bats-flap 2.6s ease-in-out infinite alternate;
}
.halloween .title::after {
  content: "";
  display: inline-block;
  flex: none;
  width: 52px;
  height: 20px;
  background: url("/styles/halloween/bats.svg") no-repeat center / contain;
  animation: bats-flap 2.6s ease-in-out infinite alternate;
}
/* (not on community pages or small phones, where the titles need the room) */
.halloween .page .title::after { display: none; }
@media (max-width: 430px) { .halloween .title::after { display: none; } }
@keyframes bats-flap {
  from { transform: translateY(0) rotate(0deg); }
  to { transform: translateY(6px) rotate(-3deg); }
}

/* Cobwebs, in different corners and sizes so they look found, not placed.
   The web is drawn in its top-left corner; flips move it to the others. */
.halloween .st,
.halloween .board-card,
.halloween .panel.hello { position: relative; }
.halloween .st::after,
.halloween .board-card::after,
.halloween .panel.hello::after {
  content: "";
  position: absolute;
  width: var(--web, 44px);
  height: var(--web, 44px);
  background: url("/styles/halloween/cobweb.svg") no-repeat top left / contain;
  pointer-events: none;
}
.halloween li:nth-child(4n + 1) > .st::after { --web: 46px; top: 3px; right: 3px; transform: scaleX(-1); }
.halloween li:nth-child(4n + 2) > .st::after { --web: 36px; top: 3px; left: 3px; }
.halloween li:nth-child(4n + 3) > .st::after { --web: 54px; bottom: 3px; right: 3px; transform: scale(-1, -1); }
.halloween li:nth-child(4n) > .st::after { --web: 40px; bottom: 3px; left: 3px; transform: scaleY(-1); }
.halloween .board-card::after { top: 3px; right: 3px; transform: scaleX(-1); }
.halloween .panel.hello::after { --web: 50px; bottom: 3px; right: 3px; transform: scale(-1, -1); }

/* Pumpkins by the dates, and pumpkin colours here and there */
.halloween .date::before,
.halloween .case-line::before { content: "🎃 "; }
.halloween .nick svg path { stroke: var(--pumpkin); }
.halloween .date-pill { background: var(--pumpkin); }
.halloween svg path[stroke="#e9b872"] { stroke: var(--pumpkin); }   /* Knot Really's rope */

/* Crease: pumpkin paper on a purple target */
html.halloween {
  --paper-front: var(--pumpkin-soft);
  --target: #cdbaf2;
}
.halloween #paper-front rect:first-child { fill: var(--pumpkin-soft); }
.halloween #paper-front rect:last-child { fill: #f39a45; }

/* The 🎃 switch (added by season.js) */
.season-btn { font-size: 18px; }
.season-btn[aria-pressed="false"] { filter: grayscale(1); opacity: 0.6; }
.season-btn.in-header { margin-left: 10px; }
.page > .topbar:has(.season-btn) { gap: 10px; }
.page > .topbar:has(.season-btn) .home-link:last-of-type { margin-left: auto; }
.season-btn.floating { position: absolute; z-index: 20; top: 12px; right: 12px; }

/* ===== Pastel: each page keeps its own background, with faded pumpkins over it ===== */

html.halloween.hw-pastel::before {
  content: "";
  position: fixed;
  z-index: -1;
  inset: 0;
  background-image: url("/styles/halloween/pumpkins.svg"), url("/styles/halloween/pumpkins.svg");
  background-size: 320px 320px, 470px 470px;
  background-position: 0 0, 160px 110px;
  opacity: 0.32;
  pointer-events: none;
}

/* The game itself stays solid in its own colour, so the pumpkins only
   show round the edges */
.halloween.hw-pastel .desk > main,
.halloween.hw-pastel .page {
  background: var(--hw-center);
  border-radius: 26px;
}
.halloween.hw-pastel .desk > main { width: calc(100% - 16px); margin: 4px auto 0; padding-top: 10px; }
.halloween.hw-pastel .page { margin-top: 12px; margin-bottom: 12px; }
@media (min-width: 1200px) {
  .halloween.hw-pastel .desk > main { width: auto; margin: 0; border-radius: 0; }
  /* The game pages' middle band runs the full height, so keep the pumpkins out of it */
  html.halloween.hw-pastel:has(.desk)::before {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(50% - 320px), transparent calc(50% - 320px), transparent calc(50% + 320px), #000 calc(50% + 320px));
    mask-image: linear-gradient(90deg, #000 calc(50% - 320px), transparent calc(50% - 320px), transparent calc(50% + 320px), #000 calc(50% + 320px));
  }
}

/* ===== Dusk and night: a darker sky with a moon, and each game on a cream page ===== */

html.halloween.hw-night { --hw-sky: #1d1430; }
/* Dusk: each page's own colour, darkened to twilight */
html.halloween.hw-dusk { --hw-sky: #5d4c94; }                       /* home and other pages: lavender */
html.halloween.hw-dusk:has(#paper-front) { --hw-sky: #46679a; }     /* Crease: sky blue */
html.halloween.hw-dusk:has(#shelf) { --hw-sky: #6b5470; }           /* Snug: mauve */
html.halloween.hw-dusk:has(#knot-card) { --hw-sky: #3c7558; }       /* Knot Really: mint */
html.halloween.hw-dusk:has(#case-line) { --hw-sky: #504a5c; }       /* Killer Clues: case-file grey */

html.halloween:is(.hw-night, .hw-dusk) body {
  position: relative;
  isolation: isolate;
  background-color: var(--hw-sky);
  /* The same tile twice, at different sizes and offsets, so the pumpkins look scattered */
  background-image: url("/styles/halloween/pumpkins.svg"), url("/styles/halloween/pumpkins.svg");
  background-size: 320px 320px, 470px 470px;
  background-position: 0 0, 160px 110px;
}
/* The moon's box stays inside the page (anything hanging off the edge makes
   phones zoom out); the picture is pushed past its corner instead. */
.halloween:is(.hw-night, .hw-dusk) body::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  right: 0;
  width: 230px;
  height: 230px;
  background: url("/styles/halloween/moon.svg") no-repeat;
  background-size: 300px 300px;
  background-position: 100px -160px;
  pointer-events: none;
}
@media (max-width: 700px) {
  .halloween:is(.hw-night, .hw-dusk) body::after { width: 150px; height: 150px; background-size: 220px 220px; background-position: 65px -140px; }
}

/* The pages the games sit on: the centre column in its own colour, the
   side panels in cream. Both are solid, so no pumpkins behind the game. */
.halloween:is(.hw-night, .hw-dusk) .desk > main,
.halloween:is(.hw-night, .hw-dusk) .side-inner,
.halloween:is(.hw-night, .hw-dusk) .page,
.halloween:is(.hw-night, .hw-dusk) .lost {
  position: relative;
  background: var(--hw-center);
  border: 3px solid #0e0918;
  border-radius: 26px;
  box-shadow: 0 6px 0 #0e0918, 0 0 40px rgba(242, 140, 40, 0.18);
}
.halloween:is(.hw-night, .hw-dusk) .desk > main { width: calc(100% - 20px); margin: 6px auto 0; padding-top: 14px; }
.halloween:is(.hw-night, .hw-dusk) .side-inner { padding: 22px 22px 24px; background: var(--parchment); }
.halloween:is(.hw-night, .hw-dusk) .lost { background: var(--cream); }
.halloween:is(.hw-night, .hw-dusk) .page { margin-top: 16px; margin-bottom: 16px; }
@media (min-width: 1200px) {
  .halloween:is(.hw-night, .hw-dusk) .desk > main { width: auto; margin: 0 10px; }
}
/* Cobwebs on the pages too (the top corners of .page hold its links and 🎃) */
.halloween:is(.hw-night, .hw-dusk) .desk > main::before,
.halloween:is(.hw-night, .hw-dusk) .desk > main::after,
.halloween:is(.hw-night, .hw-dusk) .side-inner::after,
.halloween:is(.hw-night, .hw-dusk) .page::after,
.halloween:is(.hw-night, .hw-dusk) .lost::after {
  content: "";
  position: absolute;
  width: var(--web, 44px);
  height: var(--web, 44px);
  background: url("/styles/halloween/cobweb.svg") no-repeat top left / contain;
  pointer-events: none;
}
.halloween:is(.hw-night, .hw-dusk) .desk > main::before { --web: 64px; top: 2px; left: 2px; }
.halloween:is(.hw-night, .hw-dusk) .desk > main::after { --web: 48px; bottom: 2px; right: 2px; transform: scale(-1, -1); }
.halloween:is(.hw-night, .hw-dusk) .side-inner::after { --web: 46px; top: 2px; right: 2px; transform: scaleX(-1); }
.halloween:is(.hw-night, .hw-dusk) .page::after { --web: 58px; bottom: 2px; left: 2px; transform: scaleY(-1); }
.halloween:is(.hw-night, .hw-dusk) .lost::after { --web: 58px; bottom: 2px; left: 2px; transform: scaleY(-1); }

/* Things straight on the sky: light, with a dark glow so the pumpkins never
   get in the way of reading */
.halloween:is(.hw-night, .hw-dusk) .home-link,
.halloween:is(.hw-night, .hw-dusk) .site-footer,
.halloween:is(.hw-night, .hw-dusk) .site-footer a,
.halloween:is(.hw-night, .hw-dusk) .hero h1,
.halloween:is(.hw-night, .hw-dusk) .hero p,
.halloween:is(.hw-night, .hw-dusk) .soon-note {
  color: var(--ghost);
  text-shadow: 0 0 4px var(--hw-sky), 0 0 10px var(--hw-sky), 0 0 18px var(--hw-sky);
}
.halloween:is(.hw-night, .hw-dusk) .page .home-link { color: var(--plum); text-shadow: none; }
.halloween:is(.hw-night, .hw-dusk) body:has(.hero)::before { filter: invert(1) brightness(0.9); }   /* pale bats on the sky */
.halloween:is(.hw-night, .hw-dusk) .paper { background: transparent; border-top-color: var(--pumpkin); }
.halloween:is(.hw-night, .hw-dusk) .strip.soon { background: var(--parchment); }

@media (prefers-reduced-motion: reduce) {
  .halloween body:has(.hero)::before, .halloween .title::after { animation: none; }
}
