: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 */
html { color-scheme: light; overflow-x: clip; }

body {
  margin: 0;
  overflow-x: clip;
  padding: var(--frame);
  min-height: 100vh;
  background: var(--maroon) url(assets/clay-marble.jpg) center / cover fixed;
  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 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) */
.slime {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  border-radius: 99px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(226, 238, 214, 0.42) 30%,
    rgba(255, 255, 255, 0.72) 50%, rgba(226, 238, 214, 0.42) 70%, rgba(255, 255, 255, 0));
  filter: blur(0.4px);
}
.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; }

.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 */
.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 load moment, once the arrival frames are in (main.js adds .go):
     pieces get stuck onto the page... */
  .js:not(.go) .title,
  .js:not(.go) .herb,
  .js:not(.go) .strips li { opacity: 0; }
  .go .title,
  .go .herb,
  .go .strips li {
    animation: stick 0.42s cubic-bezier(.2, 1.4, .4, 1) both;
    animation-delay: calc(var(--i, 0) * 65ms + 80ms);
  }

  /* the clay pieces loop on their own (animated WebP); frame and grain keep the same beat */
  body { animation: frame-boil calc(var(--tick) * 3) steps(1, end) infinite; }
  .window::after { animation: grain calc(var(--tick) * 2) steps(1, end) infinite; }

  /* a letter coming back to its place after wandering off (main.js) */
  .letter.back { animation: stick 0.42s cubic-bezier(.2, 1.4, .4, 1) both; }

  /* the ladybird wanders across the scraps, stops, turns, wanders off */
  .bug { animation: wander 36s steps(18, end) infinite; }
}
@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; }
}

@keyframes stick {
  from { opacity: 0; transform: translateY(-16px) scale(1.06) rotate(3deg); }
  to { opacity: 1; transform: none; }
}

@keyframes frame-boil {
  0% { background-position: 50% 50%; }
  33.333% { background-position: calc(50% + 3px) calc(50% - 2px); }
  66.666% { background-position: calc(50% - 2px) calc(50% + 3px); }
}

@keyframes grain {
  0% { background-position: 0 0; }
  50% { background-position: -23px 17px; }
}
