/* Melusine — the dive.
   Colours are named after where they live in the water column. */
:root {
  --sky-top: #a6d9ec;
  --sky-mid: #d6eeee;
  --sky-low: #f9ecd0;
  /* sunlit zone: sea glass */
  --wave-back: #b3dccf;
  --wave-mid: #86c6b7;
  --surface: #62b3a6;          /* front wave = top of the sea */
  --shallow: #46a097;
  --reef: #2b7c87;
  /* twilight zone: deep teal-blue, carrying a little of the green down */
  --blue: #1a5e78;
  --twilight: #0e3d58;
  --dusk: #071a33;
  --midnight: #030a16;
  --ink: #1b4f68;
  --text: #2c3a40;
  --brand: #22c9f0;
  --waves-h: clamp(130px, 22vh, 220px);
  --pw: clamp(100px, 12vw, 170px);    /* puffin width */
  --hand: "Caveat", "Comic Sans MS", cursive;
  --body: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--midnight);
  color: var(--text);
  font-family: var(--body);
  overflow-x: hidden;
}

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

/* Paper grain over everything, so all colour reads as pigment on paper */
.paper {
  position: fixed; inset: 0; z-index: 50; pointer-events: none;
  opacity: .32; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .55  0 0 0 0 .5  0 0 0 0 .42  0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E");
}

.mark {
  position: fixed; top: 14px; left: 16px; z-index: 40;
  display: block; width: 44px; height: 44px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .18));
}
.mark img { width: 100%; height: 100%; display: block; }

/* Depth gauge, shown once you're underwater */
.depth {
  position: fixed; right: 16px; top: 50%; z-index: 40;
  transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  opacity: 0; transition: opacity .6s;
  font-family: var(--hand); font-size: 1.15rem; color: rgba(255, 255, 255, .85);
  text-align: center;
}
.depth.on { opacity: 1; }
.depth-track {
  width: 6px; height: 34vh; border-radius: 6px;
  border: 1.5px solid rgba(255, 255, 255, .55);
  overflow: hidden;
}
.depth-fill { width: 100%; height: 0; background: rgba(255, 255, 255, .7); }
.depth-zone { font-size: .95rem; line-height: 1; max-width: 4.5em; opacity: .75; }

.scene { position: relative; }
.layer { position: absolute; will-change: transform; }

/* ---------- SCENE 1: above the surface ---------- */
.surface {
  height: 100vh; height: 100svh; min-height: 560px;
  overflow: hidden;
  background: linear-gradient(var(--sky-top), var(--sky-mid) 55%, var(--sky-low));
}
.sky-wash {
  position: absolute; inset: 0;
  background:
    radial-gradient(40% 30% at 20% 25%, rgba(255, 255, 255, .45), transparent 70%),
    radial-gradient(35% 25% at 75% 45%, rgba(255, 236, 200, .5), transparent 70%),
    radial-gradient(50% 30% at 50% 5%, rgba(120, 190, 225, .35), transparent 70%);
}
.layer svg, .island svg { display: block; width: 100%; height: auto; }
[data-art="sun"] { width: clamp(90px, 13vw, 170px); }
[data-art="cloud"] { width: clamp(170px, 24vw, 320px); opacity: .95; }
[data-art="cloud-small"] { width: clamp(110px, 14vw, 190px); opacity: .85; }

.hero {
  position: absolute; left: 0; right: 0; top: 15%; z-index: 3;
  width: min(90vw, 640px); margin: 0 auto;
  text-align: center;
  will-change: transform;
}
.hero-logo { width: clamp(84px, 11vw, 124px); height: auto; margin: 0 auto -6px; display: block; }
.hero h1 {
  margin: 0;
  font-family: var(--hand); font-weight: 700;
  font-size: clamp(4rem, 12vw, 7.5rem); line-height: 1;
  color: var(--ink);
  letter-spacing: .01em;
}
.tagline {
  margin: .4rem 0 0;
  font-family: var(--hand); font-size: clamp(1.4rem, 3.4vw, 2rem);
  color: #3f7187;
}

.island {
  position: absolute; z-index: 1;
  right: 4%; bottom: calc(var(--waves-h) * .55);
  width: clamp(230px, 34vw, 480px);
}

.birds { position: absolute; left: 0; right: 0; top: 8%; height: 40%; z-index: 2; pointer-events: none; }
.bird { position: absolute; left: 0; animation: glide linear infinite; }
.bird svg { display: block; width: 100%; height: auto; }
.bird .b { animation: flap .9s steps(1) infinite; }
.bird .b2 { animation-delay: -.45s; }
@keyframes glide { from { transform: translateX(-12vw); } to { transform: translateX(112vw); } }
@keyframes flap { 0% { opacity: 1; } 50% { opacity: 0; } }

.waves {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  height: var(--waves-h);
}
.waves svg { display: block; width: 100%; height: 100%; overflow: visible; }
/* Two drawn states per wave, swapped like a boiling-line cartoon */
.waves .fa { animation: boil 1.4s steps(1) infinite; }
.waves .fb { animation: boil 1.4s steps(1) infinite reverse; }
@keyframes boil { 0% { opacity: 1; } 50% { opacity: 0; } }

.dive {
  position: absolute; left: 50%; bottom: calc(var(--waves-h) * .95); z-index: 4;
  transform: translateX(-50%);
  font-family: var(--hand); font-weight: 700; font-size: clamp(1.8rem, 4.5vw, 2.4rem);
  color: var(--ink); text-decoration: none; white-space: nowrap;
  text-shadow: 0 0 10px rgba(255, 250, 235, .9);
}
.arrow { display: inline-block; animation: bob 1.8s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(6px); } }

/* ---------- Below the waterline: one block per depth zone ---------- */
.sea { position: relative; margin-top: -2px; overflow-x: clip; }
.zone { position: relative; overflow-x: clip; }
.sunlit   { background: linear-gradient(var(--surface), var(--shallow) 14%, var(--reef) 55%, var(--blue)); }
.twilight { background: linear-gradient(var(--blue), var(--twilight) 45%, var(--dusk)); }
.midnight { background: linear-gradient(var(--dusk), var(--midnight) 70%); }

.zone-mark {
  position: relative; z-index: 3; margin: 0; padding: 16vh 6vw 0;
  text-align: center;
  font-family: var(--hand); font-size: clamp(2rem, 6vw, 3rem); color: rgba(210, 235, 255, .75);
}
.zone-mark span { display: block; font-size: .55em; opacity: .7; }

.rays { position: absolute; left: 0; right: 0; top: 0; height: 150vh; pointer-events: none; z-index: 0; }
.rays i {
  position: absolute; top: 0; width: 9vw; min-width: 50px; height: 100%;
  background: linear-gradient(rgba(255, 252, 230, 0), rgba(255, 252, 230, .42) 14%, rgba(255, 252, 230, 0) 85%);
  transform: rotate(var(--r)); transform-origin: top center;
  filter: blur(8px); mix-blend-mode: screen;
  animation: shimmer 7s ease-in-out infinite; animation-delay: var(--d);
}
@keyframes shimmer { 50% { opacity: .35; } }

.bubbles, .creatures, .snow { position: absolute; inset: 0; pointer-events: none; }
.bubble {
  position: absolute; border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, .6);
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, .5), transparent 60%);
  animation: rise linear infinite;
}
@keyframes rise {
  0% { transform: translate(0, 0); opacity: 0; }
  10% { opacity: 1; }
  50% { transform: translate(8px, -30vh); }
  100% { transform: translate(-4px, -60vh); opacity: 0; }
}
/* Marine snow: specks of drifting organic matter, the deep sea's weather */
.speck {
  position: absolute; border-radius: 50%; background: rgba(225, 235, 245, .55);
  animation: fall linear infinite;
}
@keyframes fall {
  0% { transform: translate(0, 0); opacity: 0; }
  15%, 85% { opacity: 1; }
  100% { transform: translate(14px, 40vh); opacity: 0; }
}

/* A creature = parallax wrapper (JS) > swim path (CSS) > body (flips) > drawing */
.critter { position: absolute; left: 0; right: 0; will-change: transform; }
.critter.far { z-index: 1; opacity: .75; }
.critter.mid { z-index: 2; }
.critter.near { z-index: 4; }
.swim { position: absolute; left: 0; animation: swim linear infinite; }
.swim.rtl { animation-direction: reverse; }
.swim.rtl > .body { transform: scaleX(-1); }
.body { position: relative; animation: wobble 3s ease-in-out infinite; }
.body svg, .hang svg { display: block; width: 100%; height: auto; }
.body .over, .hang .over { position: absolute; inset: 0; }
@keyframes swim { from { transform: translateX(-35vw); } to { transform: translateX(110vw); } }
@keyframes wobble { 50% { translate: 0 10px; } }
.hang { position: absolute; animation: drift 9s ease-in-out infinite; }
@keyframes drift { 50% { transform: translateY(-34px); } }

/* Bioluminescence */
.lights { filter: drop-shadow(0 0 3px #9ff6ff) drop-shadow(0 0 8px #49d4ff); animation: pulse 2.6s ease-in-out infinite; }
.lights.warm { filter: drop-shadow(0 0 4px #fff1c2) drop-shadow(0 0 14px #ffc95a); }
@keyframes pulse { 50% { opacity: .45; } }

/* Whale song and dolphin clicks: arcs rippling out from the head */
.song { position: absolute; right: -4%; top: 22%; width: 30%; height: 50%; }
.song i {
  position: absolute; left: 0; top: 0; width: 40%; height: 100%;
  border: 2.5px solid transparent; border-right-color: rgba(190, 230, 255, .55);
  border-radius: 50%;
  animation: ripple 3.6s ease-out infinite;
}
.song i:nth-child(2) { animation-delay: -1.2s; }
.song i:nth-child(3) { animation-delay: -2.4s; }
.song.clicks i { animation-duration: 1.4s; border-right-width: 2px; }
.song.clicks i:nth-child(2) { animation-delay: -.47s; }
.song.clicks i:nth-child(3) { animation-delay: -.93s; }
@keyframes ripple {
  0% { transform: translateX(0) scale(.4); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateX(140%) scale(1.5); opacity: 0; }
}

/* ---------- The puffin (position and pose set from scroll in scene.js) ---------- */
.puffin {
  position: fixed; left: 0; top: 0; z-index: 30; pointer-events: none;
  width: var(--pw); transform-origin: 50% 50%; will-change: transform;
}
.puffin .g-inner, .friend .g-inner { position: relative; animation: hover 3.2s ease-in-out infinite; }
.puffin.is-dive .g-inner, .puffin.is-swim .g-inner { animation: none; }
.puffin svg, .friend svg { display: block; width: 100%; height: auto; }
.puffin-art g[class^="w-"] { display: none; }
.is-glide .w-glide, .is-dive .w-dive, .is-swim .w-swim,
.is-perch .w-dive, .is-perch .w-perch { display: inline; }
@keyframes hover { 50% { transform: translateY(-5px) rotate(-1.5deg); } }
/* Perched puffins stand upright, like birds on a wire */
.up { transform-origin: 50% 100%; animation: shuffle 3.4s ease-in-out infinite; }
@keyframes shuffle { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2.5deg); } }
.puffin .up { display: none; position: absolute; left: 29%; bottom: 0; width: 42%; }
.puffin.is-perch .up { display: block; }
.puffin.is-perch .puffin-art { visibility: hidden; }
.puffin.is-perch .g-inner { animation: none; }
/* The two puffins already sitting on the BEX card */
.friend {
  position: absolute; z-index: 5; pointer-events: none;
  width: calc(var(--pw) * .42); top: calc(var(--pw) * -.571 + 9px);
}
.friend.facing-left { scale: -1 1; }
.trail { position: absolute; left: 0; top: 40%; width: 20%; height: 30%; display: none; }
.is-swim .trail { display: block; }
.trail i {
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, .75);
  animation: trail 1.1s linear infinite;
}
.trail i:nth-child(2) { width: 6px; height: 6px; animation-delay: -.37s; }
.trail i:nth-child(3) { width: 10px; height: 10px; animation-delay: -.74s; }
@keyframes trail { from { transform: translate(0, 0); opacity: 1; } to { transform: translate(-40px, -12px); opacity: 0; } }
.splash {
  position: fixed; left: 0; top: 0; z-index: 29; pointer-events: none; opacity: 0;
  width: clamp(120px, 14vw, 200px); transform-origin: 50% 92%;
}
.splash svg { display: block; width: 100%; height: auto; }

/* ---------- Text, on scraps of wet paper ---------- */
.shallows { padding: 34vh 6vw 20vh; }
/* A card with polaroids pinned in the open water beside it (.flip = photos on the left) */
.with-collage { display: flex; align-items: flex-start; gap: 5vw; }
.with-collage > .card { flex: 0 1 32rem; }
.with-collage > .card.project { flex-basis: 36rem; }
.with-collage.flip .collage { margin-top: 7rem; }

/* Polaroids pinned in the water beside the first card */
.collage { position: relative; flex: 1 1 0; max-width: 36rem; height: 36rem; margin-top: 3rem; z-index: 3; }
.collage .snap {
  position: absolute; width: 50%; margin: 0; padding: 8px 8px 0;
  transform: rotate(var(--tilt, 0deg));
  box-shadow: 0 10px 24px rgba(5, 40, 70, .3);
}
.collage .snap:nth-child(1) { left: 0; top: 0; }
.collage .snap:nth-child(2) { right: 0; top: 16%; }
.collage .snap:nth-child(3) { left: 16%; top: 50%; }
.collage .snap img, .collage .ph { aspect-ratio: 4 / 3; object-fit: cover; }
.collage .ph span { font-size: 1.2rem; }
/* Charts and wide screenshots keep their own shape instead of being cropped to 4:3 */
.collage .snap.fit img { aspect-ratio: auto; }
/* A collage with a single photo: one bigger print, no empty board around it */
.collage:has(> .snap:only-child) { height: auto; }
.collage .snap:only-child { position: relative; width: 82%; margin-top: 2rem; }
#birdgate ~ .collage .snap:nth-child(2) img { object-position: 50% 62%; }  /* the memory map, not the intro text */
#birdgate ~ .collage .snap:nth-child(3) { left: 4%; top: 56%; }  /* keep the chip caption readable */
.collage figcaption {
  font-family: var(--hand); font-size: 1.3rem; text-align: center; color: #45606b;
  padding: .25rem 0 .35rem;
}
.reef { padding: 10vh 6vw 34vh; display: flex; flex-direction: column; gap: 45vh; }
.projects { padding: 18vh 6vw 34vh; display: flex; flex-direction: column; gap: 32vh; }
.experiments { padding: 22vh 6vw 50vh; }

.card {
  position: relative; z-index: 3;
  max-width: 32rem; padding: 1.6rem 1.9rem 1.4rem;
  background:
    radial-gradient(60% 50% at 85% 10%, rgba(34, 201, 240, .13), transparent 70%),
    radial-gradient(50% 60% at 10% 95%, rgba(240, 200, 140, .18), transparent 70%),
    rgba(251, 246, 234, .94);
  border: 2px solid rgba(40, 70, 85, .35);
  border-radius: 255px 18px 225px 16px / 16px 225px 18px 255px;
  box-shadow: 0 14px 30px rgba(5, 40, 70, .28);
  transform: rotate(var(--tilt, 0deg));
}
.card.project { max-width: 36rem; }
.twilight .card { box-shadow: 0 14px 40px rgba(0, 10, 25, .5); }
.midnight .card { background-color: rgba(236, 232, 222, .92); box-shadow: 0 0 40px rgba(120, 200, 255, .12); }
.card h2 {
  margin: 0 0 .4rem;
  font-family: var(--hand); font-weight: 700; font-size: clamp(2.2rem, 6vw, 2.8rem); line-height: 1;
  color: var(--ink);
}
.card h2.logo-heading { margin: .2rem 0 .7rem; }
.logo-heading img { display: block; width: clamp(170px, 45%, 230px); height: auto; }
.card p a:not(.links a) { color: var(--ink); text-decoration-color: rgba(27, 79, 104, .45); text-underline-offset: 2px; }
.card p { margin: 0 0 .8rem; font-size: 1.05rem; line-height: 1.6; }
.links { display: flex; flex-wrap: wrap; gap: .6rem; }
.links a {
  font-family: var(--hand); font-weight: 700; font-size: 1.3rem; color: var(--ink); text-decoration: none;
  padding: .05rem .8rem; border: 2px solid currentColor;
  border-radius: 20px 6px 18px 8px / 8px 18px 6px 20px;
}
.links a:hover { background: rgba(34, 201, 240, .18); }
/* Not a link yet: same hand-drawn pill, dashed and faded */
.links .soon {
  font-family: var(--hand); font-weight: 700; font-size: 1.3rem; color: #6d838c;
  padding: .05rem .8rem; border: 2px dashed currentColor; cursor: default;
  border-radius: 20px 6px 18px 8px / 8px 18px 6px 20px;
}
.placeholder {
  display: inline-block; margin-top: .2rem; padding: .05rem .6rem;
  font-family: var(--hand); font-size: 1rem; color: #8a7a62;
  border: 1.5px dashed #c4b394; border-radius: 12px;
}

/* Taped-in photos and screenshots */
.snap {
  position: relative; margin: -.2rem 0 1.1rem;
  padding: 8px; background: #fffdf7;
  box-shadow: 0 3px 10px rgba(30, 40, 50, .2);
  transform: rotate(calc(var(--tape, 0deg) * -.3));
}
.snap::before {
  content: ""; position: absolute; top: -12px; left: 50%; width: 90px; height: 24px; margin-left: -45px;
  background: rgba(235, 220, 180, .75); transform: rotate(var(--tape, 0deg));
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}
.snap img { display: block; width: 100%; height: auto; }
/* Shown until the real image file exists */
.ph {
  aspect-ratio: 16 / 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
  border: 2px dashed #b7c9cf; color: #6b8790; text-align: center; padding: 1rem;
  background: repeating-linear-gradient(45deg, rgba(34, 201, 240, .06) 0 12px, transparent 12px 24px);
}
.ph span { font-family: var(--hand); font-size: 1.5rem; }
.ph code { font-size: .8rem; opacity: .8; word-break: break-all; }
.snap.portrait .ph { aspect-ratio: 4 / 5; padding: .5rem; }
.snap.portrait .ph span { font-size: 1.2rem; }

/* ---------- SCENE 5b: the anglerfish ---------- */
.abyss { position: relative; height: 280vh; background: var(--midnight); }
.stage {
  position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden;
  display: flex; align-items: center; justify-content: center; padding: 70px 6vw 40px;
}
.card.about {
  display: grid; grid-template-columns: minmax(130px, 210px) 1fr; gap: 1.6rem; align-items: start;
  max-width: 44rem; z-index: 2;
}
.about .snap { margin: .4rem 0 0; }
.dark {
  position: absolute; inset: 0; z-index: 4; background: var(--midnight);
  pointer-events: none;   /* it's only a shadow: let clicks reach the card underneath */
  -webkit-mask-image: radial-gradient(circle var(--r, 0px) at var(--lx, 110%) var(--ly, 20%), transparent 0, rgba(0, 0, 0, .25) 55%, #000 100%);
          mask-image: radial-gradient(circle var(--r, 0px) at var(--lx, 110%) var(--ly, 20%), transparent 0, rgba(0, 0, 0, .25) 55%, #000 100%);
}
.glow {
  position: absolute; inset: 0; z-index: 5; pointer-events: none; mix-blend-mode: screen;
  background: radial-gradient(circle calc(var(--r, 0px) * .7) at var(--lx, 110%) var(--ly, 20%), rgba(255, 214, 140, .2), transparent);
}
.hint {
  position: absolute; z-index: 6; left: 0; right: 0; top: 46%; margin: 0; text-align: center; pointer-events: none;
  font-family: var(--hand); font-size: clamp(1.6rem, 4vw, 2.2rem); color: rgba(200, 220, 240, .5);
}
.angler {
  position: absolute; left: 0; top: 0; z-index: 6; pointer-events: none;
  width: clamp(150px, 19vw, 250px);
}
.angler .inner { position: relative; animation: wobble 4s ease-in-out infinite; }
.angler svg { display: block; width: 100%; height: auto; }
.angler .over { position: absolute; inset: 0; }

footer {
  position: relative; background: var(--midnight); text-align: center;
  padding: 12vh 6vw 8vh; color: rgba(200, 220, 240, .5);
  font-family: var(--hand); font-size: 1.2rem;
}
.surface-link { font-size: 1.9rem; font-weight: 700; color: rgba(220, 240, 255, .8); text-decoration: none; }

@media (max-width: 900px) {
  .with-collage { flex-direction: column; gap: 2.5rem; }
  .with-collage.flip { flex-direction: column-reverse; }
  .with-collage.flip .collage { margin-top: 0; }
  .collage { height: auto; width: 100%; max-width: 36rem; margin: 0; display: flex; }
  .collage .snap:nth-child(n) { position: relative; left: auto; right: auto; top: auto; flex: 0 0 35%; min-width: 0; margin-right: -2.5%; padding: 5px 5px 0; }
  .collage .snap:nth-child(2) { margin-top: 1.2rem; }
  .collage .ph { padding: .3rem; }
  .collage .ph span { font-size: .95rem; }
  .collage .ph code { display: none; }
  .collage .snap:only-child { flex-basis: 75%; margin-top: 0; }
  .collage figcaption { font-size: 1rem; line-height: 1.1; }
}

@media (max-width: 600px) {
  .card { padding: 1.3rem 1.3rem 1.1rem; }
  .reef { gap: 30vh; }
  .projects { gap: 22vh; }
  .depth { top: auto; bottom: 14px; right: 14px; transform: none; }
  .depth-track, .depth-zone { display: none; }
  .hero { top: 20%; }
  .island { right: -16%; }
  .card.about { grid-template-columns: 96px 1fr; gap: .9rem; padding: 1.1rem; }
  .card.about h2 { font-size: 2rem; }
  .card.about p { font-size: .95rem; line-height: 1.5; }
  .about .snap { padding: 5px; }
  .about .snap::before { width: 50px; margin-left: -25px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; }
  .waves .fb { opacity: 0; }
  .bird .b2 { opacity: 0; }
  .swim { left: var(--x); }
  .bird { left: 30%; }
}
