/* neek — ink on paper, one continuous climb. everything lowercase. */

@font-face {
  font-family: "labelle";
  src: url("/assets/fonts/labelle.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --paper: #f7f3e8;
  --ink: #2b2620;
  --ink-soft: #77705f;
}

/* night: the same drawing, inverted world */
body.night {
  --paper: #0f0d0a;
  --ink: #ece5d3;
  --ink-soft: #9a927e;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* the page scrolls, but the scrollbar stays invisible */
html {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
html::-webkit-scrollbar, body::-webkit-scrollbar { width: 0; display: none; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "labelle", "Segoe Script", cursive;
  text-transform: lowercase;
  overflow-x: hidden;
  overscroll-behavior-y: none; /* no pull-to-refresh fighting the ride */
  transition: background-color 0.9s ease;
}

::selection { background: rgba(154, 168, 138, 0.35); }

/* ============ the one scene ============ */

#scroller {
  position: relative;
  height: 750vh;
  background: var(--paper);
}

.stage {
  position: sticky;
  top: 0;
  height: 100svh;
  overflow: hidden;
  background: var(--paper);
  contain: layout paint;
  touch-action: pan-y;
  transition: background-color 0.9s ease;
}

/* ============ world (tree + links) ============ */

#world {
  position: absolute;
  left: 50%;
  top: 0;
  will-change: transform;
}

#world-svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* crown click target arms once the tree is out */
#crown-hit { pointer-events: none; }
#world-svg.crown-ready #crown-hit { pointer-events: all; cursor: pointer; }

/* black ink turns white after dark */
.ink-img { transition: filter 0.9s ease; }
body.night .ink-img { filter: invert(0.92); }

#world-svg, .leaf svg { color: var(--ink); }

/* chromatic ghosts: red/cyan copies breathing apart, print-misprint style.
   multiply on paper by day; screen glow on black by night */
.ch-ghost { mix-blend-mode: multiply; }
.ch-r { filter: url(#tint-r); animation: ch-r 7s ease-in-out infinite alternate; }
.ch-c { filter: url(#tint-c); animation: ch-c 7s ease-in-out infinite alternate; }
body.night .ch-ghost { mix-blend-mode: screen; }
body.night .ch-r { filter: url(#tint-rn); }
body.night .ch-c { filter: url(#tint-cn); }
@keyframes ch-r { from { transform: translate(-1.5px, -0.5px); } to { transform: translate(-4px, -2px); } }
@keyframes ch-c { from { transform: translate(1.5px, 0.5px); }  to { transform: translate(4px, 2px); } }

/* tree shake on crown click: lives on a clean wrapper (no filter/mask),
   because chrome won't repaint css transforms on filtered svg elements */
#tree-shaker {
  transform-box: view-box;
  transform-origin: 500px 950px;
}
#tree-shaker.shake { animation: tree-shake 0.75s ease-in-out; }

@keyframes tree-shake {
  0%, 100% { transform: rotate(0deg) translateX(0); }
  15%      { transform: rotate(-0.9deg) translateX(-4px); }
  35%      { transform: rotate(0.7deg) translateX(3px); }
  55%      { transform: rotate(-0.45deg) translateX(-2px); }
  75%      { transform: rotate(0.25deg) translateX(1px); }
}

/* burst leaves: shaken loose, fall past the ground and disappear */
.burst-leaf {
  transform-box: fill-box;
  transform-origin: center;
  animation: burst-fall var(--bd, 3.4s) cubic-bezier(0.3, 0, 0.7, 1) var(--bdl, 0s) forwards;
  opacity: 0;
}

@keyframes burst-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0.85; }
  70%  { opacity: 0.75; }
  100% { transform: translateY(640px) rotate(var(--br, 260deg)); opacity: 0; }
}

/* ============ branch links (dainty) ============ */

/* dainty ink letters with the same chromatic fringes as the leaves */
.branch-link text {
  font-family: "labelle", cursive;
  font-size: 30px;
  font-weight: 400;
  letter-spacing: 0.5px;
  fill: var(--ink);
  filter: drop-shadow(-1.2px -0.4px rgba(255, 61, 110, 0.5))
          drop-shadow(1.2px 0.4px rgba(0, 184, 200, 0.5));
  transition: fill 0.35s ease, opacity 0.35s ease;
  transform-box: fill-box;
  transform-origin: center;
}

body.night .branch-link text {
  filter: drop-shadow(-1.2px -0.4px rgba(255, 112, 150, 0.6))
          drop-shadow(1.2px 0.4px rgba(63, 230, 242, 0.6));
}

.branch-link {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 1.1s ease, visibility 0s linear 1.1s;
  cursor: pointer;
  outline: none;
}

/* kill underlines dead: # links count as :visited, where browsers get
   stubborn about decoration overrides */
.branch-link, .branch-link:visited, .branch-link:hover,
.branch-link *, .branch-link text {
  text-decoration: none !important;
}

.branch-link.is-live {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 1.1s ease;
}

/* hover: just the wiggle — ink stays ink (black by day, white by night) */
.branch-link:hover text,
.branch-link:focus-visible text {
  animation: wiggle 0.6s ease-in-out;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  30%      { transform: rotate(-2.4deg); }
  65%      { transform: rotate(1.8deg); }
}

/* ============ root songs + lyrics ============ */

.root-song {
  font-family: "labelle", cursive;
  font-size: 27px;
  fill: var(--ink);
  stroke: var(--paper);
  stroke-width: 5px;
  paint-order: stroke; /* paper halo lifts titles off the root lines */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  cursor: pointer;
  transform: translateY(16px);
  transition: opacity 0.9s ease, transform 0.9s ease, visibility 0s linear 0.9s;
  transform-box: fill-box;
  transform-origin: center;
  filter: drop-shadow(-1.2px -0.4px rgba(255, 61, 110, 0.5))
          drop-shadow(1.2px 0.4px rgba(0, 184, 200, 0.5));
}

body.night .root-song {
  filter: drop-shadow(-1.2px -0.4px rgba(255, 112, 150, 0.6))
          drop-shadow(1.2px 0.4px rgba(63, 230, 242, 0.6));
}

.root-song.is-live {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition: opacity 0.9s ease, transform 0.9s ease;
}

.root-song:hover { animation: wiggle 0.6s ease-in-out; }

/* hover taste: a little hand-drawn card of the first lines */
#lyric-pop {
  position: fixed;
  z-index: 20;
  max-width: 260px;
  padding: 0.7rem 1rem 0.8rem;
  background: var(--paper);
  color: var(--ink);
  border: 1.6px solid var(--ink);
  border-radius: 10px 14px 11px 15px / 14px 10px 15px 11px; /* wobbly */
  font-family: "labelle", cursive;
  font-size: 1.05rem;
  line-height: 1.5;
  pointer-events: none;
  transform: rotate(-1.2deg);
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.12);
  white-space: pre-line;
}

#lyric-pop strong { display: block; font-size: 1.2rem; font-weight: 400; margin-bottom: 0.25rem; }

/* the full page of words */
#lyric-view {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--paper);
  color: var(--ink);
  font-family: "labelle", cursive;
  transition: background-color 0.9s ease;
}

#lyric-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 5.5rem 1.5rem 4rem;
  text-align: center;
}

#lyric-title {
  font-weight: 400;
  font-size: clamp(2rem, 5vw, 3rem);
  margin-bottom: 1.8rem;
}

#lyric-body {
  font-family: "labelle", cursive;
  font-size: clamp(1.15rem, 2.4vw, 1.5rem);
  line-height: 1.85;
  white-space: pre-line;
  opacity: 0.9;
}

#lyric-back, #roots-back {
  background: none;
  border: none;
  color: var(--ink);
  font-family: "labelle", cursive;
  font-size: 1.15rem;
  letter-spacing: 0.05em;
  text-transform: lowercase;
  opacity: 0.7;
  cursor: pointer;
  transition: opacity 0.3s ease;
}

#lyric-back { position: absolute; top: 1rem; left: 1.2rem; z-index: 31; }

#roots-back {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
}

#lyric-back:hover, #roots-back:hover,
#lyric-back:focus-visible, #roots-back:focus-visible { opacity: 1; }

/* ============ shake surprises: bird, butterflies, the bomb ============ */

/* critters are ink by day, white by night, always chromatic-fringed */
.critter {
  color: var(--ink);
  filter: drop-shadow(-1.4px -0.4px rgba(255, 61, 110, 0.55))
          drop-shadow(1.4px 0.4px rgba(0, 184, 200, 0.55));
}

body.night .critter {
  filter: drop-shadow(-1.4px -0.4px rgba(255, 112, 150, 0.6))
          drop-shadow(1.4px 0.4px rgba(63, 230, 242, 0.6));
}

.bird-anim {
  animation: bird-pop 2.2s ease-in-out forwards;
  transform-box: fill-box;
  transform-origin: 50% 95%;
}

@keyframes bird-pop {
  0%        { transform: translateY(84px); }
  20%       { transform: translateY(0) rotate(0deg); }
  32%       { transform: translateY(0) rotate(-6deg); }
  46%       { transform: translateY(0) rotate(4deg); }
  74%       { transform: translateY(0) rotate(0deg); }
  100%      { transform: translateY(84px); }
}

.bfly-fly { animation: bfly-fly var(--fd, 2.6s) ease-out forwards; }

@keyframes bfly-fly {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0.9; }
  70%  { opacity: 0.75; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--r, 60deg)); opacity: 0; }
}

.bfly-flap {
  animation: bfly-flap 0.16s ease-in-out infinite alternate;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes bfly-flap { from { transform: scaleX(1); } to { transform: scaleX(0.45); } }

.bomb-fall { animation: bomb-fall 0.95s cubic-bezier(0.45, 0.02, 0.85, 0.55) forwards; }

@keyframes bomb-fall { to { transform: translateY(640px) rotate(16deg); } }

.boom-anim {
  animation: boom-flash 0.65s ease-out forwards;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes boom-flash {
  from { transform: scale(0.15); opacity: 0.95; }
  to   { transform: scale(2.1); opacity: 0; }
}

.debris-fly { animation: debris-fly var(--fd, 1s) cubic-bezier(0.2, 0.5, 0.6, 1) forwards; }

@keyframes debris-fly {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0.9; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--r, 200deg)); opacity: 0; }
}

/* the whole tree vanishes in the blast, then quietly grows back */
#tree-shaker { transition: opacity 1.8s ease; }
#tree-shaker.blown { opacity: 0; transition-duration: 0.1s; }

/* ============ falling ink leaves (always on) ============ */

.leaf-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.leaf {
  position: absolute;
  top: -8%;
  left: var(--x);
  width: var(--s);
  height: var(--s);
  animation: leaf-fall var(--d) linear var(--dl) infinite;
}

.leaf svg {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0.6;
  /* chromatic fringes: the leaves carry the same red/cyan ghosting */
  filter: drop-shadow(-1.4px -0.4px rgba(255, 61, 110, 0.55))
          drop-shadow(1.4px 0.4px rgba(0, 184, 200, 0.55));
  animation: leaf-sway calc(var(--d) / 3.2) ease-in-out var(--dl) infinite alternate;
}

@keyframes leaf-fall {
  from { transform: translateY(0) rotate(0deg); }
  to   { transform: translateY(118svh) rotate(290deg); }
}

@keyframes leaf-sway {
  from { transform: translateX(-9px) rotate(-14deg); }
  to   { transform: translateX(9px) rotate(14deg); }
}

/* ============ persistent signature: left-center, written once ============ */

#hero {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
}

/* down in the lyrics, the signature steps aside */
body.lyrics #hero { opacity: 0; }

.hero-inner {
  position: absolute;
  left: 25vw; /* centered in the left half of the screen */
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
}

#name {
  width: clamp(118px, 20.4vw, 281px);
  height: auto;
  overflow: visible;
}

/* the doodle writes itself in once: a soft slanted front (matching the
   writing angle) sweeps left to right, like ink flowing onto the page */
#name-wipe {
  animation: name-write 2.9s cubic-bezier(0.5, 0.05, 0.45, 0.95) 0.4s forwards;
}

@keyframes name-write {
  to { transform: translateX(680px); }
}

.hero-hint {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding-left: 0.4rem;
  font-size: clamp(1.1rem, 2vw, 1.35rem);
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  opacity: 0.85;
}

.hint-arrow {
  width: 15px;
  height: 26px;
  color: var(--ink-soft);
  animation: bob 2.6s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(5px); }
}

/* ============ grain ============ */

body.night .grain { mix-blend-mode: screen; opacity: 0.045; }

.grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============ sun / moon: click for night ============ */

#sky-toggle {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 11;
  width: clamp(154px, 19.6vw, 238px);
  aspect-ratio: 1;
  background: none;
  border: none;
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: translate(14%, -14%);
  transition: opacity 1.2s ease, transform 1.2s ease, color 0.9s ease;
  cursor: pointer;
}

#sky-toggle.show {
  opacity: 1;
  pointer-events: auto;
  transform: translate(0, 0);
}

/* the sun and moon carry the fringes too, and sway like they're drawn on water */
#sky-toggle svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(-1.6px -0.5px rgba(255, 61, 110, 0.5))
          drop-shadow(1.6px 0.5px rgba(0, 184, 200, 0.5));
  animation: sky-sway 9s ease-in-out infinite alternate;
  transform-origin: 85% 15%;
}

body.night #sky-toggle svg {
  filter: drop-shadow(-1.6px -0.5px rgba(255, 112, 150, 0.6))
          drop-shadow(1.6px 0.5px rgba(63, 230, 242, 0.6));
}

@keyframes sky-sway {
  from { transform: rotate(-1.2deg) scale(0.995); }
  to   { transform: rotate(1.2deg) scale(1.005); }
}

#sky-toggle:hover, #sky-toggle:focus-visible { opacity: 0.85; outline: none; }

/* mouse over the sky: the sun (or moon) gives a happy little shiver */
#sun-g, #moon-g {
  transform-box: fill-box;
  transform-origin: 60% 40%;
}

#sky-toggle:hover #sun-g, #sky-toggle:focus-visible #sun-g,
#sky-toggle:hover #moon-g, #sky-toggle:focus-visible #moon-g {
  animation: sky-wiggle 0.65s ease-in-out;
}

@keyframes sky-wiggle {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25%      { transform: rotate(-3.2deg) scale(1.03); }
  60%      { transform: rotate(2.4deg) scale(1.01); }
}

#moon-g { display: none; }
body.night #sun-g { display: none; }
body.night #moon-g { display: block; }

/* ============ chrome ============ */

#sound-toggle {
  position: fixed;
  right: 1.1rem;
  bottom: 0.95rem;
  z-index: 10;
  background: none;
  border: none;
  color: var(--ink);
  font-family: "labelle", cursive;
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  text-transform: lowercase;
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 0.3s ease;
}

#sound-toggle:hover, #sound-toggle:focus-visible { opacity: 0.95; }

#credit {
  display: none;
  position: fixed;
  left: 1.1rem;
  bottom: 1.05rem;
  z-index: 10;
  font-family: system-ui, sans-serif;
  font-size: 0.62rem;
  letter-spacing: 0.05em;
  color: var(--ink);
  opacity: 0;
  transition: opacity 1s ease;
  pointer-events: none;
}

#credit.show { opacity: 0.35; }

/* debug readout (?debug) */
#debug-p {
  position: fixed;
  top: 0.6rem;
  right: 0.8rem;
  z-index: 99;
  font: 12px/1 monospace;
  color: #9f9;
  background: rgba(0,0,0,0.6);
  padding: 4px 7px;
  border-radius: 4px;
}

/* ============ reduced motion ============ */

@media (prefers-reduced-motion: reduce) {
  #name-wipe { animation: none; transform: translateX(680px); }
  .hero-hint { transition: none; }
  .hint-arrow { animation: none; }
  #sky-toggle svg { animation: none; }
  #sky-toggle:hover #sun-g, #sky-toggle:hover #moon-g { animation: none; }
  .leaf-layer { display: none; }
  #tree-shaker.shake { animation: none; }
  .ch-r, .ch-c { animation: none; opacity: 0.22; }
  .branch-link, .branch-link.is-live { transition: none; }
  .branch-link:hover text, .branch-link:focus-visible text { animation: none; }
}

/* ============ small screens ============ */

@media (max-width: 700px) {
  .branch-link text { font-size: 36px; }
  .root-song { font-size: 30px; stroke-width: 6px; }
  /* the signature lives up in the sky on phones, clear of the link rows */
  .hero-inner { top: 20%; }
  #lyric-pop { display: none; } /* no hover on phones; tap opens the words */
  #credit { font-size: 0.55rem; max-width: 40vw; }
  /* phones: freeze the ghost breathing so the filtered tree isn't
     re-rendered every frame — same look, far cheaper */
  .ch-r { animation: none; transform: translate(-3px, -1.5px); }
  .ch-c { animation: none; transform: translate(3px, 1.5px); }
  /* and drop the per-leaf shadow fringes + the grain layer (repaint cost) */
  .leaf svg { filter: none; }
  .grain { display: none; }
  /* the big win: one masked tree image instead of three. the ghost look
     comes from cheap offset shadows on the single image instead */
  .ch-ghost { display: none; }
  #tree-img {
    filter: drop-shadow(-2.5px -1px rgba(255, 61, 110, 0.45))
            drop-shadow(2.5px 1px rgba(0, 184, 200, 0.45));
  }
  body.night #tree-img {
    filter: invert(1) drop-shadow(-2.5px -1px rgba(255, 112, 150, 0.35))
            drop-shadow(2.5px 1px rgba(63, 230, 242, 0.35));
  }
  /* smaller moon and sun on phones so they never sit on the links */
  #sky-toggle { width: 112px; }
}
