/* =========================================================
   Star Equestrian Hub — Autumn / Halloween theme
   Toggled via body.spooky. Everything here is opt-in:
   nothing changes on the page unless that class is present.

   Reused across index.html, evervale-map.html and database.html —
   include this file + autumn-theme.js on any page that should
   offer the toggle.

   Performance notes:
   - Decorations are inline SVG (no image requests, crisp at any size).
   - Spiderwebs and leaf piles are fully static (no animation cost).
   - Only the bats animate, and only via a cheap CSS transform,
     capped at 3 elements — no JS render loop, no canvas/particles.
   - Everything respects prefers-reduced-motion.
   ========================================================= */

:root{
  --autumn-orange: #c96a2e;
  --autumn-red:    #a5432b;
  --autumn-yellow: #d9a441;
  --autumn-brown:  #6b4a2f;
}

/* Decorations are hidden entirely unless the theme is on, so there is
   zero footprint (not even layout) on a page where nobody enabled it. */
.autumn-deco{ display:none; }
body.spooky .autumn-deco{ display:block; }

/* Subtle mood shift behind the existing background — a second overlay,
   not a replacement, so it layers on top of whatever background.jpg
   treatment a page already has. */
body.spooky::after{
  content:"";
  position:fixed; inset:0; z-index:-1;
  pointer-events:none;
  background:
    radial-gradient(ellipse at 15% 0%, rgba(201,106,46,0.12), transparent 55%),
    radial-gradient(ellipse at 85% 100%, rgba(90,55,120,0.12), transparent 60%);
}

/* Containers that host decorations need a positioning context (harmless when
   the theme is off). The header still clips — the bats fly across it and must
   not escape. Tiles and the discord panel deliberately DON'T clip, so leaves
   can straddle the border and read as frame decoration rather than as
   something dumped inside the box on top of the text. */
header,
.tile,
.discord-panel{ position:relative; }
body.spooky header{ overflow:hidden; }
body.spooky .tile,
body.spooky .discord-panel{ overflow:visible; }

/* ---------- Spiderwebs (corners) ---------- */
.spiderweb{
  position:absolute; width:150px; height:150px;
  z-index:2;
  pointer-events:none;
  opacity:.9;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.55));
}
.spiderweb svg{
  width:100%; height:100%;
  fill:none;
  stroke:rgba(255,255,255,0.8);
  stroke-width:1.6;
  stroke-linecap:round;
}
.spiderweb.corner-tl{ top:-4px; left:-4px; }
.spiderweb.corner-tr{ top:-4px; right:-4px; transform:scaleX(-1); }
.spiderweb.corner-bl{ bottom:-4px; left:-4px; transform:scaleY(-1); }
.spiderweb.corner-br{ bottom:-4px; right:-4px; transform:scale(-1,-1); }
.spiderweb.inset.corner-tl{ top:2px; left:2px; }
.spiderweb.inset.corner-tr{ top:2px; right:2px; transform:scaleX(-1); }

/* Smaller web variant for tighter corners, e.g. the discord panel */
.spiderweb.sm{ width:104px; height:104px; }

/* ---------- Leaf piles (sitting ON the bottom edge) ---------- */
/* The pile is offset past the panel's bottom border so only its upper part
   overlaps the box. That keeps it clear of the text — the previous version
   sat fully inside and ran straight through the last line. */
.leaf-pile{
  position:absolute; width:84px; height:47px;
  z-index:2;
  pointer-events:none;
  opacity:.95;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.45));
}
.leaf-pile svg{
  width:100%; height:100%; display:block;
}
.leaf-pile.corner-bl{ left:14px; bottom:-15px; }
.leaf-pile.corner-br{ right:14px; bottom:-15px; transform:scaleX(-1); }

/* .below: sits ENTIRELY under the host's own box (top:100%) instead of
   partly overlapping its bottom edge — for hosts where that bottom edge is
   busy content (a map image, a list) rather than empty panel background,
   where a -15px overlap would land ON the content instead of below it. */
.leaf-pile.below{ top:100%; bottom:auto; margin-top:2px; }

/* ---------- Single leaves (top corners, frame accents) ---------- */
.leaf-single{
  position:absolute; width:40px; height:40px;
  z-index:2;
  pointer-events:none;
  opacity:.95;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.45));
}
.leaf-single svg{ width:100%; height:100%; display:block; }
.leaf-single.corner-tl{ top:-14px; left:-12px; }
.leaf-single.corner-tr{ top:-14px; right:-12px; transform:scaleX(-1); }
.leaf-single.edge-tr{ top:-13px; right:64px; }
.leaf-single.sm{ width:30px; height:30px; }

/* ---------- Hosts on the map / database pages ---------- */
/* Those pages have their own boxes worth decorating. */
.demo-banner,
.controls,
.panel{ position:relative; }

/* The header and the map page's .panel boxes clip their own content (bats
   must not escape the banner; the panels round off the map and the scroll
   areas). Decorations inside them therefore use these .inset variants, which
   tuck against the inner edge instead of hanging over the border. */
.leaf-pile.inset{ bottom:0; }
.leaf-pile.inset.corner-bl{ left:8px; }
.leaf-pile.inset.corner-br{ right:8px; }
.leaf-single.inset.corner-tl{ top:3px; left:5px; }
.leaf-single.inset.corner-tr{ top:3px; right:5px; }

/* ---------- Deco hosts (decorations OUTSIDE a clipped panel) ---------- */
/* .panel itself clips its content (rounded map corners, scroll areas), so a
   decoration that should hang past a panel's own edge — into the page
   background around it — goes on a plain wrapper placed around the panel
   instead of inside it. The wrapper takes the panel's exact footprint
   (it has no other content) and imposes no clipping of its own. */
.panel-deco-host{ position:relative; }

/* The Map panel sits directly above the Pet-XP panel with only the grid's
   18px row gap between them — too tight for a pile hanging fully below
   (zero overlap) to have room to breathe. This adds just enough extra
   clearance for that one spot; it does not affect the Items panel, whose
   row-1 cell already has ample empty space below its own (shorter) box. */
.map-deco-host{ margin-bottom:34px; }

/* Leaf colors (and the stem/vein accents) are set directly on each <path>
   inside the pile/leaf symbols, not via classes — CSS from the main document
   can't reliably reach through a <symbol>/<use> reference, which is why they
   rendered solid black before. Three pile arrangements and four single-leaf
   shapes exist so repeated corners don't look copy-pasted. */

/* ---------- Bats ---------- */
.bat-layer{
  position:absolute; inset:0;
  overflow:hidden;
  pointer-events:none;
}
.bat{
  position:absolute;
  width:clamp(46px, 3.6vw, 100px);
  aspect-ratio: 200 / 90;
  fill:#241a14;
  opacity:.78;
  will-change:left, transform;
  animation-name: bat-fly;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}
.bat.b1{ top:12%; left:-14%; animation-duration:72s; animation-delay:0s; }
.bat.b2{ top:40%; left:-14%; width:clamp(34px, 2.7vw, 76px); opacity:.62; animation-duration:48s; animation-delay:-15s; }
.bat.b3{ top:2%;  left:-14%; width:clamp(28px, 2.2vw, 62px); opacity:.55; animation-duration:95s; animation-delay:-30s; }

@keyframes bat-fly{
  0%   { left:-14%; transform: translateY(0)     scale(.9); }
  12%  { left:2%;   transform: translateY(-20px) scale(1); }
  24%  { left:18%;  transform: translateY(8px)   scale(.94); }
  38%  { left:36%;  transform: translateY(-18px) scale(1); }
  50%  { left:52%;  transform: translateY(10px)  scale(.92); }
  62%  { left:68%;  transform: translateY(-20px) scale(1); }
  76%  { left:84%;  transform: translateY(8px)   scale(.94); }
  88%  { left:101%; transform: translateY(-12px) scale(1); }
  100% { left:118%; transform: translateY(0)     scale(.9); }
}

@media (prefers-reduced-motion: reduce){
  .bat{ animation: none; left:-10%; }
}

/* ---------- Toggle button ---------- */
.autumn-toggle{
  position:fixed; right:18px; bottom:18px; z-index:500;
  width:46px; height:46px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  font-size:20px; line-height:1; cursor:pointer;
  background:var(--panel); border:1px solid var(--line);
  box-shadow:0 4px 14px rgba(0,0,0,0.35);
  transition:transform .15s ease, border-color .15s ease, background .15s ease;
}
.autumn-toggle:hover{ transform:translateY(-2px); border-color:var(--gold); }
body.spooky .autumn-toggle{ background:var(--panel-2); border-color:var(--gold); }

@media (max-width:480px){
  .autumn-toggle{ right:14px; bottom:14px; width:42px; height:42px; font-size:18px; }
}
