:root {
  --ink: #1b120e;
  --maroon: #5c0d16;
  --sun: #ecd03a;
  --cream: #f5efe0;
  --frame: clamp(12px, 3.6vw, 40px);
  /* the browser's own default face, printed onto paper */
  --type: "Times New Roman", Times, serif;
  --tick: 170ms; /* one stop-motion frame, same as the clay WebPs */
  /* spacing between scraps grows with the screen height so the page fills up */
  --gap: clamp(14px, 3.4vh, 38px);
  --gap: clamp(14px, 3.4svh, 38px);
  --grass: clamp(84px, 14vh, 140px);
  --grass: clamp(84px, 14svh, 140px);
}

*, *::before, *::after { box-sizing: border-box; }

/* plants may hang over the frame, never past the screen */
/* no rubber band past the end of the page (it showed the bare red frame on iPhone) */
html { color-scheme: light; overflow-x: clip; overscroll-behavior-y: none; background: var(--maroon); }

body {
  margin: 0;
  /* anything past the page (plants at the sides, objects of the title leaving
     the screen) is cut off at its edge and never makes the page longer; the
     plants still spill over the frame */
  overflow: clip;
  padding: var(--frame);
  min-height: 100vh;
  background: none;
  color: var(--ink);
  font-family: var(--type);
  -webkit-font-smoothing: antialiased;
}

picture { display: block; }
picture img { display: block; width: 100%; height: auto; }

/* the photo "window" inside the clay frame, like a cover */
.window {
  position: relative;
  min-height: calc(100vh - 2 * var(--frame));
  min-height: calc(100svh - 2 * var(--frame));
  padding: clamp(24px, 4svh, 48px) 20px calc(var(--grass) * 0.72);
  /* the collage is one block, centred in the window: no gap to fill */
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: #2f4229 url(assets/garden-blur.jpg) center / cover;
  box-shadow:
    inset 0 0 0 2px rgba(20, 4, 6, 0.45),
    inset 0 14px 40px rgba(10, 2, 4, 0.55),
    0 0 0 1px rgba(255, 220, 220, 0.15);
  isolation: isolate;
}

/* the red clay frame: a fixed layer a little bigger than the screen, so its boil
   (a few px of shake) never shows an edge; fixed layers also hold still on iPhone */
body::before {
  content: "";
  position: fixed;
  inset: -10px;
  z-index: -1;
  pointer-events: none;
  background: url(assets/clay-marble.jpg) center / cover;
}

/* the soil in the green sheet's place (html.soil in index.html), the red frame
   straight behind, its edge crumbling over the frame */
.soil .window { background: none; box-shadow: none; }
.soil .window::before { display: none; }
/* main.js draws the soil in this canvas, to fit the window exactly (photo at its
   real scale, crumbling edge, crumbs on the frame) */
.soil-layer {
  position: absolute;
  inset: calc(-1 * var(--spill, 0px));
  z-index: 0;
  pointer-events: none;
  visibility: hidden;
}
.soil-layer.on { visibility: visible; }
.soil-layer canvas { display: block; width: 100%; height: 100%; }

/* with the soil, the film grain and the dust cover the whole screen, frame included:
   kept to the window, they showed its rectangle wherever the soil crumbles away */
.soil .window::after,
.soil .dust { position: fixed; inset: 0; }

/* the photo looks printed and handled: crumpled relief under the collage */
.window::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: url(assets/crumple.jpg) center / cover;
  mix-blend-mode: overlay;
  opacity: 0.42;
}

/* dust, hairs and scratches on top, like a scanned collage */
.dust {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: url(assets/dust.webp) 0 0 / 520px;
  opacity: 0.75;
}

/* film grain over everything */
.window::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0.22;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 1.6 -.3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* the page itself: title and scraps in one block, centred in the window */
.sheet {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 380px;
  margin-inline: auto;
}
.head, nav { position: relative; z-index: 2; }
/* letters wandering off pass over the scraps */
.head { z-index: 3; }

/* ---------- header: the name, whole, on one line */
.title { position: relative; margin: 0 auto; width: min(100%, 360px); line-height: 0; rotate: -1.5deg; }
.letters { position: absolute; inset: 0; }
.letter { position: absolute; transform-origin: var(--o, 50% 50%); }
.letter img { display: block; width: 100%; height: auto; }
.letter.away { z-index: 5; }
.letter .pin { position: absolute; width: 0; height: 0; }

/* left behind by the snail and the worm, and the hole the worm nibbles (main.js) */
/* the snail's trail (tools/slime.py): fresh, then drying (s2), then dry flakes (s3) */
.slime {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  border-radius: 99px;
  background: url(assets/slime-1.webp) center top / 100% auto repeat-y;
}
.slime.s2 { background-image: url(assets/slime-2.webp); }
.slime.s3 { background-image: url(assets/slime-3.webp); }
.hole { position: absolute; z-index: 1; pointer-events: none; }
.hole img { display: block; width: 100%; height: 100%; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- herbarium: pressed plants (tools/herbier.py) */
.herbs { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.herb {
  position: absolute;
  height: auto;
  /* plants hang off the window onto the clay frame: --l / --rr is the distance
     from the screen edge; an undefined variable leaves that side on auto */
  left: calc((100% - 100vw) / 2 + var(--l));
  right: calc((100% - 100vw) / 2 + var(--rr));
}
.herb.on { z-index: 3; }
.herb > img:first-child { display: block; width: 100%; height: auto; }

/* hand stitches holding a scrap to the page */
.stitch { position: absolute; height: auto; pointer-events: none; }

/* ---------- ladybird walking over the links */
.bug {
  position: absolute;
  z-index: 4;
  width: 34px;
  left: -12%;
  top: 6%;
  translate: -50% -50%;
  pointer-events: none;
}

/* ---------- cut grass along the bottom, laid over the photo */
.grass {
  position: absolute;
  /* a little wider than the window: the blades spill over the frame at the sides */
  left: calc(var(--frame) * -0.7);
  right: calc(var(--frame) * -0.7);
  bottom: 0;
  height: var(--grass);
  z-index: 3;
  pointer-events: none;
  background: url(assets/grass.webp) left bottom / auto 100% repeat-x;
  filter: drop-shadow(0 -2px 4px rgba(10, 16, 6, 0.35));
}

/* ---------- link strips */
nav { margin-top: calc(var(--gap) * 1.2); }

.strips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--gap);
}
.strips li { position: relative; }
.strips .strip { z-index: 1; }
/* a long press on a link selects nothing and draws no grey box; the browser's own
   link preview (iOS, Android) is left alone, except iOS's callout menu */
.strip, .strip * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.strip img { -webkit-user-drag: none; }

.strip {
  --r: 0deg;
  --k: 0;
  --w: 250px;
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: var(--w);
  max-width: 100%;
  height: 60px;
  /* each scrap sits somewhere along the row, never past the edge */
  margin-left: max(0px, calc((100% - var(--w)) * var(--k)));
  padding: 0 24px 2px 18px;
  color: var(--ink);
  text-decoration: none;
  line-height: 0;
  isolation: isolate;
  transform: rotate(var(--r));
  filter: drop-shadow(1px 2px 1px rgba(15, 4, 4, 0.3)) drop-shadow(3px 7px 6px rgba(10, 3, 3, 0.3));
  transition: transform 0.18s cubic-bezier(.3, 1.6, .5, 1), filter 0.18s ease;
}

/* labels keep their relative sizes: one scale for all of them */
/* white letters on white paper: a cast shadow draws their outline */
.strip .word.shadowed { filter: drop-shadow(0 1px 0.6px rgba(70, 50, 30, .55)) drop-shadow(0 0 1.5px rgba(70, 50, 30, .35)); }
.strip .word { display: block; width: calc(var(--lw) * 0.8px); max-width: calc(100% - 50px); height: auto; }

/* arriving: main.js walks each scrap through three rough poses (crumpled,
   rolled or folded, tools/collage.py) before it lies flat with its logo and word */
.strip[data-f="1"]::before { background-image: var(--f1); }
.strip[data-f="2"]::before { background-image: var(--f2); }
.strip[data-f="3"]::before { background-image: var(--f3); }
.strip[data-f] > * { visibility: hidden; }

/* the scrap itself: a torn, crumpled piece of paper (tools/collage.py) */
.strip::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--paper) center / 100% 100% no-repeat;
}

.strip .logo { width: 42px; flex: none; rotate: calc(var(--r) * -6); transition: rotate 0.25s ease; }
.strip .logo img { width: 42px; height: 42px; object-fit: contain; }

/* tape: every piece is a different tape (tools/herbier.py), each across a stem */
.tape {
  position: absolute;
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 1px 0.6px rgba(20, 10, 5, 0.28));
}
/* across a plant's stem; turns with the plant */
.herb .tape { left: var(--tx); top: var(--ty); width: var(--tw); translate: -50% -50%; rotate: var(--tr); }

.strip:hover {
  transform: translateY(-3px) rotate(0deg);
  filter: drop-shadow(2px 4px 2px rgba(15, 4, 4, 0.28)) drop-shadow(6px 13px 10px rgba(10, 3, 3, 0.3));
}
.strip:hover .logo { rotate: -14deg; }
.strip:active {
  transform: translateY(1px) rotate(0deg) scale(0.985);
  filter: drop-shadow(1px 1px 1px rgba(15, 4, 4, 0.4));
}
.strip:focus-visible {
  outline: 3px dashed var(--sun);
  outline-offset: 5px;
}

@media (prefers-reduced-motion: no-preference) {
  /* one entrance, once everything is loaded (main.js adds .go): until then the
     page is plain maroon. Then the frame, the soil poured out (main.js), and,
     in stop-motion, never a fade: the grass pushes up, each piece is stuck on
     in turn, the ladybird and the dust come last. */
  .js:not(.go) body::before,
  .js:not(.go) .window::after { visibility: hidden; }
  .js .grass,
  .js .title,
  .js .herb,
  .js .strips li,
  .js .bug,
  .js .dust { visibility: hidden; }
  .go .grass { animation: grow calc(var(--tick) * 3) steps(1, end) var(--enter) forwards; }
  .go .title,
  .go .herb,
  .go .strips li { animation: stick calc(var(--tick) * 3) steps(1, end) calc(var(--enter) + var(--i, 0) * 85ms) forwards; }
  .go .dust { animation: show 1ms var(--last) forwards; }
  .go .bug { animation: show 1ms var(--last) forwards, wander 36s steps(18, end) var(--last) infinite; }
  /* a very slow connection: everything at once, flat */
  .flat .grass, .flat .title, .flat .herb, .flat .strips li, .flat .dust { animation: show 1ms forwards; }
  .flat .bug { animation: show 1ms forwards, wander 36s steps(18, end) infinite; }

  /* the clay pieces loop on their own (animated WebP); frame and grain keep the same beat */
  body::before { animation: frame-boil calc(var(--tick) * 3) steps(1, end) infinite; }
  .window::after { animation: grain calc(var(--tick) * 2) steps(1, end) infinite; }

  /* the ladybird wanders across the scraps, stops, turns, wanders off (started above,
     once the entrance is over) */
}
@media (prefers-reduced-motion: reduce) {
  .bug { display: none; }
}

@keyframes wander {
  0% { left: -14%; top: 7%; rotate: 100deg; }
  16% { left: 38%; top: 12%; rotate: 96deg; }
  21% { left: 38%; top: 12%; rotate: 150deg; }
  36% { left: 64%; top: 36%; rotate: 150deg; }
  42% { left: 64%; top: 36%; rotate: 205deg; }
  58% { left: 42%; top: 60%; rotate: 205deg; }
  63% { left: 42%; top: 60%; rotate: 245deg; }
  80% { left: 8%; top: 74%; rotate: 220deg; }
  86% { left: 8%; top: 74%; rotate: 190deg; }
  100% { left: -14%; top: 98%; rotate: 215deg; }
}

/* stuck on by hand in three jerky poses: held a little above, pressed, flat */
@keyframes stick {
  0% { visibility: visible; transform: translateY(-14px) scale(1.06) rotate(3deg); }
  33.333% { visibility: visible; transform: translateY(-5px) scale(1.02) rotate(1deg); }
  66.666%, 100% { visibility: visible; transform: none; }
}
/* the grass pushes up from under the frame in three poses */
@keyframes grow {
  0% { visibility: visible; transform: translateY(60%); }
  33.333% { visibility: visible; transform: translateY(28%); }
  66.666%, 100% { visibility: visible; transform: none; }
}
@keyframes show { to { visibility: visible; } }

@keyframes frame-boil {
  0% { transform: none; }
  33.333% { transform: translate(3px, -2px); }
  66.666% { transform: translate(-2px, 3px); }
}

@keyframes grain {
  0% { background-position: 0 0; }
  50% { background-position: -23px 17px; }
}
