/* ───────────────────────────────────────────────────────────────────────────
   The Marauder's Map — parchment, ink and footprints
   ─────────────────────────────────────────────────────────────────────────── */

:root {
  --ink:        #2a1a0b;
  --ink-soft:   #4c3517;
  --ink-faint:  rgba(42, 26, 11, 0.42);
  --parchment:  #e7d3a5;
  --parchment-lit: #f4e5c2;
  --parchment-dim: #cbac74;
  --burn:       #8a5f28;

  /* The brown the drained map is tinted with. Tweak to taste; the tone
     curve that fades the ink lives in the #ink-rough filter in index.html. */
  --map-tint: sepia(0.95) saturate(1.5) hue-rotate(-13deg) brightness(1.03);

  --foot-scale: 1;
  --ribbon-scale: 1;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #b99a63;
  color: var(--ink);
  font-family: "IM Fell English", Georgia, "Times New Roman", serif;
  -webkit-text-size-adjust: 100%;
}

.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.app { position: fixed; inset: 0; }

/* ── Parchment ─────────────────────────────────────────────────────────── */

.parchment {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 120% 90% at 28% 18%, var(--parchment-lit) 0%, transparent 55%),
    radial-gradient(ellipse 100% 80% at 82% 88%, #e3cb99 0%, transparent 60%),
    radial-gradient(ellipse 140% 120% at 50% 50%, var(--parchment) 40%, var(--parchment-dim) 100%);
}

/* Fibre grain + larger mottling, both baked as data-URI turbulence */
.parchment::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='260' height='260' filter='url(%23f)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='700' height='700'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.011' numOctaves='5'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='700' height='700' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 260px 260px, 700px 700px;
  mix-blend-mode: multiply;
  opacity: 0.3;
  pointer-events: none;
}

/* Scorched edges and the shadow of a much-folded page */
.stains {
  position: absolute;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  background:
    radial-gradient(ellipse 88% 78% at 50% 50%, transparent 46%, rgba(122, 82, 33, 0.22) 82%, rgba(78, 47, 14, 0.48) 100%),
    linear-gradient(90deg, rgba(120, 82, 34, 0.30), transparent 12%, transparent 88%, rgba(120, 82, 34, 0.30)),
    linear-gradient(180deg, rgba(120, 82, 34, 0.26), transparent 10%, transparent 90%, rgba(120, 82, 34, 0.26));
  mix-blend-mode: multiply;
}

/* Hand-ruled double border */
.frame {
  position: absolute;
  inset: 0;
  z-index: 300;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: url(#sketch);
}
.frame rect { fill: none; stroke: var(--ink-soft); vector-effect: non-scaling-stroke; }
.frame__outer { stroke-width: 3; opacity: 0.75; }
.frame__inner { stroke-width: 1; opacity: 0.5; }

/* ── The map, dragged through a bottle of ink ──────────────────────────── */

.map {
  position: absolute;
  inset: 0;
  background: transparent;
  z-index: 1;
}
.leaflet-container { background: transparent; font-family: inherit; }

.leaflet-tile-pane {
  filter: url(#ink-rough) var(--map-tint);
  mix-blend-mode: multiply;
}
/* The turbulence is far too costly to run on every frame of a pan */
.is-moving .leaflet-tile-pane { filter: url(#ink-flat) var(--map-tint); }

/* ── Safari: wash each tile instead of the pane ─────────────────────────
   WebKit gives Leaflet's tiles their own compositing layers, and a composited
   descendant escapes an ancestor's `filter` and `mix-blend-mode` entirely —
   so the wash above never reaches them and the map shows raw OpenStreetMap
   colour. The old answer was `L.Browser.any3d = false`, which put the tiles
   back in normal paint order but also stopped Leaflet ever *scaling* them:
   pinch-zooming then flung the tile container off-screen and left bare
   parchment until you lifted your fingers.

   So each tile is washed on its own instead, and the paper is multiplied in
   by `#on-paper` rather than by a blend mode. Nothing here depends on an
   ancestor or on compositing, which means Leaflet can transform and scale the
   panes as much as it likes — and does, because `any3d` stays on.

   `#ink-flat`, not `#ink-rough`: the wobble displaces by 6px, which per tile
   would drag transparent pixels in at every tile edge and show seams. */
.ink-tiles .leaflet-tile-pane { filter: none; mix-blend-mode: normal; }
.ink-tiles .leaflet-tile { filter: url(#ink-flat) var(--map-tint) url(#on-paper); }

/* The paper's own fibre and mottling would be hidden under opaque tiles, so
   in this mode they are laid over the top instead — on `.stains`, which is
   above the map, already multiplies, and is never touched by Leaflet. */
.ink-tiles .stains {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='260' height='260' filter='url(%23f)' opacity='0.28'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='700' height='700'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.011' numOctaves='5'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='700' height='700' filter='url(%23g)' opacity='0.26'/%3E%3C/svg%3E"),
    radial-gradient(ellipse 88% 78% at 50% 50%, transparent 46%, rgba(122, 82, 33, 0.22) 82%, rgba(78, 47, 14, 0.48) 100%),
    linear-gradient(90deg, rgba(120, 82, 34, 0.30), transparent 12%, transparent 88%, rgba(120, 82, 34, 0.30)),
    linear-gradient(180deg, rgba(120, 82, 34, 0.26), transparent 10%, transparent 90%, rgba(120, 82, 34, 0.26));
  background-size: 260px 260px, 700px 700px, auto, auto, auto;
}

.leaflet-control-attribution {
  background: rgba(231, 211, 165, 0.72) !important;
  color: var(--ink-soft) !important;
  font-family: inherit;
  font-size: 11px;
  border-radius: 3px 0 0 0;
}
.leaflet-control-attribution a { color: var(--burn) !important; }

/* ── Footprints ────────────────────────────────────────────────────────── */

.foot-icon { pointer-events: none; }

/* Size comes from CFG.footW/footH in app.js, which also writes the inline
   margins that centre the glyph on its anchor; the values here are only a
   fallback for the brief moment before the script runs. */
.foot {
  width: var(--foot-w, 8px);
  height: var(--foot-h, 10px);
  margin: calc(var(--foot-h, 10px) / -2) 0 0 calc(var(--foot-w, 8px) / -2);
  transform-origin: 50% 50%;
  animation: ink-in 620ms var(--ease) both;
}
.foot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.foot g { fill: var(--ink); filter: url(#sketch-fine); }

/* The live pair shifts its weight while you stand about */
.foot--stand.foot--l g { animation: weight 2.9s ease-in-out infinite; }
.foot--stand.foot--r g { animation: weight 2.9s ease-in-out infinite 1.45s; }

@keyframes weight {
  0%, 100% { opacity: 0.95; }
  50%      { opacity: 0.62; }
}
@keyframes ink-in {
  from { opacity: 0; filter: blur(3px); transform: scale(0.72); }
  to   { opacity: 1; filter: blur(0);   transform: scale(1); }
}

/* ── The name on its little flag ───────────────────────────────────────── */

.flag-icon { pointer-events: none; }

/* A zero-size box pinned to the wizard's own position, so the banner grows
   and shrinks about that point as the map zooms — belonging to the map the
   way the prints do, rather than floating over it at a fixed size. */
.flag-zoom { position: relative; width: 0; height: 0; }

/* The banner is sized by multiplying its base size by the zoom scale, rather
   than being transform-scaled. A transform makes WebKit rasterise the ribbon
   once at its starting size and then stretch that bitmap, so zooming in gives
   a pixellated banner; re-laying the SVG out at its true pixel size keeps it
   vector-sharp in both engines.

   Placed with left/top rather than margins, too: a margin on a child of a
   zero-height box collapses through it and moves the box itself, which would
   carry the banner off the wizard as you zoomed. */
.flag {
  position: absolute;
  width: calc(var(--rw) * var(--ribbon-scale, 1));
  left:  calc(var(--rw) * var(--ribbon-scale, 1) * -0.5);
  top:   calc(var(--rh) * var(--ribbon-scale, 1) * -1 - 6px);
  /* `backwards`, not `both`: `both` would leave the keyframe's filter applied
     for good, and a filter forces the banner into a rasterised layer. */
  animation: ink-in 900ms var(--ease) backwards;
}
.ribbon {
  width:  calc(var(--rw) * var(--ribbon-scale, 1));
  height: calc(var(--rh) * var(--ribbon-scale, 1));
}
.flag svg { display: block; overflow: visible; }
/* The traced banner. It is drawn as one evenodd path, so its hollows stay
   open and the parchment shows through them exactly as it does in the films. */
.ribbon__art { fill: var(--ink); }
/* Parchment behind the writing, so the name reads over busy streets.
   Matching the paper's own colour keeps it invisible on bare ground. */
.ribbon__ground { fill: rgba(233, 214, 170, 0.88); }

/* The roll at the left is heavy and the right end is loose ribbon, so the
   sway is pivoted near the roll: the free end travels furthest, the way a
   pinned banner actually moves. Two odd periods keep it from looking looped. */
.ribbon {
  overflow: visible;
  transform-origin: 14% 30%;
  animation: ribbon-drift 11s ease-in-out infinite;
}
.ribbon__art {
  transform-origin: 14% 30%;
  animation: ribbon-lift 7s ease-in-out infinite;
}

@keyframes ribbon-drift {
  0%, 100% { transform: rotate(-0.55deg) translateY(0.4px); }
  50%      { transform: rotate(0.5deg)  translateY(-0.6px); }
}
@keyframes ribbon-lift {
  0%, 100% { transform: skewY(0.28deg) scaleY(1); }
  50%      { transform: skewY(-0.3deg) scaleY(1.012); }
}

.flag__name {
  font-family: "IM Fell English", Georgia, serif;
  font-style: italic;
  fill: var(--ink);
  dominant-baseline: middle;
}

/* ── Furniture ─────────────────────────────────────────────────────────── */

.banner {
  position: absolute;
  isolation: isolate;
  top: max(14px, env(safe-area-inset-top));
  left: 0; right: 0;
  z-index: 400;
  text-align: center;
  pointer-events: none;
  filter: url(#sketch-fine);
}
.banner::before {
  content: "";
  position: absolute;
  inset: -26px -6px -34px;
  z-index: -1;
  background: radial-gradient(ellipse 62% 100% at 50% 45%,
    rgba(240, 226, 192, 0.94) 0%, rgba(240, 226, 192, 0.72) 52%, transparent 78%);
}
.banner__title {
  margin: 0;
  font-family: "IM Fell English SC", Georgia, serif;
  font-size: clamp(22px, 6.2vw, 40px);
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 245, 220, 0.45);
}
.banner__sub {
  margin: 2px auto 0;
  max-width: 34ch;
  font-size: clamp(10px, 2.9vw, 13px);
  line-height: 1.35;
  color: var(--ink-soft);
  opacity: 0.82;
}

.status {
  position: absolute;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 400;
  margin: 0;
  padding: 0 16px;
  max-width: 90vw;
  text-align: center;
  font-size: 14px;
  font-style: italic;
  color: var(--ink-soft);
  text-shadow: 0 0 6px rgba(243, 230, 198, 0.95), 0 0 14px rgba(243, 230, 198, 0.8),
               0 1px 0 rgba(255, 245, 220, 0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity 400ms;
}
.status.is-on { opacity: 0.9; }

.compass {
  position: absolute;
  right: 14px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  width: 74px;
  height: 74px;
  z-index: 380;
  opacity: 0.7;
  pointer-events: none;
  filter: url(#sketch);
}
.compass svg { width: 100%; height: 100%; }
.compass__ring { fill: none; stroke: var(--ink-soft); stroke-width: 2; }
.compass__ring--in { stroke-width: 1; opacity: 0.7; }
.compass__needle { fill: var(--ink); }
.compass__needle--s { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.compass__n {
  font-family: "IM Fell English SC", serif;
  font-size: 15px;
  fill: var(--ink);
  text-anchor: middle;
}

.controls {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 400;
  display: flex;
  flex-wrap: wrap;          /* four spells is more than a narrow phone holds */
  gap: 8px;
  justify-content: center;
  padding: 0 12px;
}

.btn {
  font-family: "IM Fell English SC", Georgia, serif;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: rgba(238, 222, 184, 0.78);
  border: 1.5px solid var(--ink-soft);
  border-radius: 2px;
  padding: 9px 16px;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(80, 52, 18, 0.25);
  transition: transform 120ms var(--ease), background 200ms;
  filter: url(#sketch-fine);
}
.btn:hover { background: rgba(244, 231, 199, 0.92); }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:focus-visible { outline: 2px dashed var(--burn); outline-offset: 3px; }
.btn.is-live { background: rgba(206, 176, 118, 0.9); }

.btn--seal { border-style: double; border-width: 4px; }

/* ── The gate ──────────────────────────────────────────────────────────── */

.gate {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(ellipse 120% 90% at 30% 15%, var(--parchment-lit), transparent 55%),
    radial-gradient(ellipse 140% 120% at 50% 50%, var(--parchment) 40%, #c3a269 100%);
  transition: opacity 900ms var(--ease), visibility 900ms;
}
.gate.is-open { opacity: 0; visibility: hidden; }

/* The same fibres and scorching as the map behind it */
.gate::before,
.gate::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
}
.gate::before {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='260' height='260' filter='url(%23f)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='700' height='700'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.011' numOctaves='5'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='700' height='700' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 260px 260px, 700px 700px;
  opacity: 0.3;
}
.gate::after {
  background:
    radial-gradient(ellipse 88% 78% at 50% 50%, transparent 46%, rgba(122, 82, 33, 0.22) 82%, rgba(78, 47, 14, 0.5) 100%);
}
.gate__paper { position: relative; z-index: 1; }

.gate__mark {
  width: 96px;
  margin: 26px auto 0;
  opacity: 0.5;
  filter: url(#sketch-fine);
}
.gate__mark svg { width: 100%; display: block; }
.gate__mark g { fill: var(--ink); }

.gate__paper {
  width: min(440px, 100%);
  text-align: center;
  padding: 8px 4px;
}
.gate__title {
  margin: 0 0 14px;
  font-family: "IM Fell English SC", Georgia, serif;
  font-weight: 400;
  font-size: clamp(30px, 9vw, 46px);
  letter-spacing: 0.05em;
  filter: url(#sketch-fine);
}
.gate__blurb {
  margin: 0 auto 26px;
  max-width: 32ch;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-soft);
}
.gate__form { display: grid; gap: 12px; justify-items: center; }
.gate__label {
  font-family: "IM Fell English SC", serif;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.gate__input {
  width: 100%;
  padding: 10px 8px;
  font-family: "IM Fell English", Georgia, serif;
  font-style: italic;
  font-size: 26px;
  text-align: center;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--ink-faint);
}
.gate__input::placeholder { color: rgba(42, 26, 11, 0.28); }
.gate__input:focus { outline: none; border-bottom-color: var(--ink); }

/* Consent, and the plain truth about what swearing the oath does. Kept on the
   gate rather than buried in a README, because this is the moment a wizard
   decides to broadcast where they are. */
.gate__consent {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 6px;
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
}
.gate__consent input {
  width: 17px;
  height: 17px;
  accent-color: var(--ink-soft);
  cursor: pointer;
}
.gate__fine {
  margin: 0 auto;
  max-width: 36ch;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-soft);
  opacity: 0.8;
}

.btn--oath {
  margin-top: 10px;
  font-size: 16px;
  padding: 12px 20px;
  line-height: 1.3;
}
.gate__note {
  margin: 4px 0 0;
  min-height: 1.4em;
  font-size: 14px;
  font-style: italic;
  color: var(--burn);
}
.gate__link {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-style: italic;
  color: var(--ink-soft);
  text-decoration: underline dotted;
  cursor: pointer;
}

/* ── Mischief managed: the ink drains away ─────────────────────────────── */

.is-wiping .leaflet-tile-pane,
.is-wiping .leaflet-marker-pane,
.is-wiping .banner,
.is-wiping .status,
.is-wiping .compass,
.is-wiping .controls {
  opacity: 0;
  transition: opacity 1200ms ease-in;
}

@media (prefers-reduced-motion: reduce) {
  .foot, .flag { animation-duration: 1ms; }
  .ribbon, .ribbon__art { animation: none; }
  .foot--stand.foot--l g, .foot--stand.foot--r g { animation: none; opacity: 0.9; }
  .gate, .is-wiping * { transition-duration: 1ms; }
}

@media (max-width: 380px) {
  .btn { font-size: 13px; padding: 8px 12px; }
  .compass { width: 56px; height: 56px; }
}

/* Rotation wrapper: a zero-size box pinned to the anchor, so the glyph turns
   about its own centre while Leaflet keeps positioning the parent. */
.foot-rot { width: 0; height: 0; }
