/* ------------------------------------------------------------------
   LAYOUT IDEA: a fixed hill photo behind a tall, mostly empty page.
   Every piece sits on a 1440px wide canvas that scales with the screen
   (--u is one canvas pixel), and drifts at its own speed as you scroll.
   ------------------------------------------------------------------ */

:root {
  --u: calc(100vw / 1440);   /* script.js replaces this with the exact width minus the scrollbar */
  --base: #ff01d3;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { background: var(--base); }

body {
  margin: 0;
  background: var(--base);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* fixed backdrop: the hill and its soft pink glow */
#bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  pointer-events: none;
}

/* the page itself: tall so there is something to scroll through, otherwise empty */
#scene {
  position: relative;
  z-index: 1;
  height: max(calc(var(--u) * var(--page-h, 2400)), 190vh);
  overflow-x: clip;
}

/* ---------- every piece ---------- */

.layer {
  position: absolute;
  left: calc(var(--u) * var(--x));
  top: calc(var(--u) * var(--y));
  width: calc(var(--u) * var(--w));
  will-change: transform;
  pointer-events: none;
}

.piece {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  transform: rotate(var(--r, 0deg));
  transform-origin: 50% 50%;
}

.piece img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* the title swings side to side like an early-internet banner */
.wobble img {
  transform-origin: 50% 55%;
  animation: wobble var(--ws, 2.7s) ease-in-out infinite alternate;
}

@keyframes wobble {
  from { transform: rotate(calc(var(--wd, 4deg) * -1)); }
  to { transform: rotate(var(--wd, 4deg)); }
}

/* a group of pieces that swings together; each .part inside bobs on its own */
.group { position: relative; }
.sway { transform-origin: 50% 70%; animation: sway var(--ws, 7s) ease-in-out infinite alternate; }
@keyframes sway {
  from { transform: rotate(calc(var(--r, 0deg) - var(--wd, 4deg))); }
  to { transform: rotate(calc(var(--r, 0deg) + var(--wd, 4deg))); }
}
.part { position: absolute; }

/* a part that links to another page: same lift and glow as the pressable notes */
.part.link {
  display: block;
  pointer-events: auto;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.28s cubic-bezier(0.2, 1.5, 0.4, 1),
    filter 0.28s ease;
}
.part.link:hover,
.part.link:focus-visible {
  transform: translateY(calc(var(--u) * -12)) scale(1.05);
  filter:
    drop-shadow(0 0 calc(var(--u) * 10) rgba(255, 244, 150, 0.95))
    drop-shadow(0 0 calc(var(--u) * 30) rgba(255, 208, 40, 0.8));
}
.part.link:active { transform: translateY(calc(var(--u) * -4)) scale(1.01); }
.part.link:focus-visible { outline: none; }

/* music notes drifting out of the speaker frog */
.float-note {
  position: absolute;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 0;
  will-change: transform, opacity;
}

/* the burger layers float up and down, each on its own beat */

.bob img {
  animation: bob var(--bs, 6s) ease-in-out var(--bd, 0s) infinite alternate;
}

@keyframes bob {
  from { transform: translateY(calc(var(--u) * var(--amp, 30) * -1)); }
  to { transform: translateY(calc(var(--u) * var(--amp, 30))); }
}

/* ---------- the "click 2 neigh" note ---------- */

.note {
  pointer-events: auto;
  cursor: pointer;
  transition:
    transform 0.28s cubic-bezier(0.2, 1.5, 0.4, 1),
    filter 0.28s ease;
}

/* a piece that can be pressed but doesn't lift or glow (the logo) */
.tap {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}
.tap:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }

.note:hover,
.note:focus-visible {
  transform: translateY(calc(var(--u) * -12)) rotate(var(--r, 0deg)) scale(1.05);
  filter:
    drop-shadow(0 0 calc(var(--u) * 10) rgba(255, 244, 150, 0.95))
    drop-shadow(0 0 calc(var(--u) * 30) rgba(255, 208, 40, 0.8));
}

.note:active {
  transform: translateY(calc(var(--u) * -4)) rotate(var(--r, 0deg)) scale(1.01);
}

.note:focus-visible { outline: none; }

/* ---------- the skeleton sprint ---------- */

/* DOM order puts it after the fixed hill photo (#bg) but before #scene, so it
   runs in front of the photo and behind every piece on the page. */
.skeleton {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100vw;
  height: auto;
  z-index: 1;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------- the pop-up windows ---------- */

.popup {
  position: fixed;
  aspect-ratio: var(--aspect, 1 / 1);
  filter: drop-shadow(0 calc(var(--u) * 10) calc(var(--u) * 30) rgba(0, 0, 0, 0.45));
}

/* nearly fills the screen, keeps its shape, stays centred */
.popup-center {
  z-index: 100;
  left: 50%;
  top: 50%;
  width: min(94vw, calc(90vh * var(--ratio, 1)));
  transform: translate(-50%, -50%);
  animation: pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

/* tucked into the top-right corner. Its window border is drawn at exactly the same
   scale as the centre pop-up's (--s is one file pixel on screen), so the red X matches. */
.popup-corner {
  z-index: 101;
  right: max(16px, env(safe-area-inset-right, 0px));
  top: max(16px, env(safe-area-inset-top, 0px));
  --s: calc(min(94vw, calc(90vh * 1800 / 1899)) / 1800);
  width: calc(var(--s) * var(--nw, 1456));
  max-width: calc(100vw - 32px);
  transform-origin: 100% 0;
  animation: pop-corner 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

/* middle of the left edge; same window-border scale as the others */
.popup-left {
  z-index: 100;
  left: max(16px, env(safe-area-inset-left, 0px));
  top: 50%;
  --s: calc(min(94vw, calc(90vh * 1800 / 1899)) / 1800);
  width: min(calc(var(--s) * var(--nw, 1436)), calc(90vh * var(--ratio, 1)), calc(100vw - 32px));
  transform: translateY(-50%);
  transform-origin: 0 50%;
  animation: pop-left 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

/* sits at the bottom middle of the screen (script.js slides it in from the left); same window-border scale as the others */
.popup-slide {
  z-index: 102;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  --s: calc(min(94vw, calc(90vh * 1800 / 1899)) / 1800);
  width: min(calc(var(--s) * var(--nw, 1536)), calc(90vh * var(--ratio, 1.3)), calc(100vw - 32px));
  transform: translateX(-50%);
}

.popup img {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

/* invisible button sitting on the red X of the window */
.popup-close {
  position: absolute;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.popup-close:focus-visible { outline: 2px solid #fff; }

@keyframes pop {
  from { transform: translate(-50%, -50%) scale(0.85); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes pop-left {
  from { transform: translateY(-50%) scale(0.85); opacity: 0; }
  to { transform: translateY(-50%) scale(1); opacity: 1; }
}
@keyframes pop-corner {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ------------------------------------------------------------------
   ENTER PAGE: shown once per visit, in front of everything (see enter.js)
   ------------------------------------------------------------------ */
#enter {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #2a2a2a;
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: opacity 0.6s ease, visibility 0.6s;
}
#enter.leaving { opacity: 0; visibility: hidden; pointer-events: none; }
#enter[hidden] { display: none !important; }
#enter-stage {
  position: relative;
  /* the whole window always fits the screen */
  width: min(100vw, calc(100vh * 1996 / 1061));
  aspect-ratio: 1996 / 1061;
}
#enter .e { position: absolute; display: block; height: auto; user-select: none; -webkit-user-drag: none; pointer-events: none; }
#enter button.e {
  padding: 0; border: 0; background: none; cursor: pointer; pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.28s cubic-bezier(0.2, 1.5, 0.4, 1), filter 0.28s ease;
}
#enter button.e img { display: block; width: 100%; height: auto; pointer-events: none; }
#enter button.e:hover,
#enter button.e:focus-visible {
  outline: none;
  transform: translateY(-1.2%) scale(1.04);
  filter: drop-shadow(0 0 10px rgba(255, 244, 150, 0.95)) drop-shadow(0 0 28px rgba(255, 208, 40, 0.8));
}
#enter button.e:active { transform: scale(1.01); }

/* the burger on the enter page floats like the one on the main page, and the logo swings side to side */
#enter-stage { --eu: calc(min(100vw, calc(100vh * 1996 / 1061)) / 1440); }
#enter .eb { animation: e-bob var(--bs, 6s) ease-in-out var(--bd, 0s) infinite alternate; }
@keyframes e-bob {
  from { transform: translateY(calc(var(--eu) * var(--amp, 30) * -1)); }
  to   { transform: translateY(calc(var(--eu) * var(--amp, 30))); }
}
#enter .ew { animation: e-wobble 2.7s ease-in-out infinite alternate; transform-origin: 50% 50%; }
@keyframes e-wobble { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
@media (prefers-reduced-motion: reduce) { #enter .eb, #enter .ew { animation: none; } }
