/*
 * poppel.app, paused.
 *
 * "Poppel" is a poplar: leaves green above and silver beneath, which flicker
 * as they turn. The wordmark is a solid block standing in a small village,
 * and the whole scene turns toward the cursor. The face of the word and the
 * poplars go from green to silver as it tilts. A postman does his round.
 *
 * Everything in the scene is sized in em of the word, so it scales as one.
 */

@font-face {
  font-family: 'Martian Mono';
  font-weight: 800;
  font-style: normal;
  font-display: swap;
  src: url('/fonts/martian-mono-latin-800.woff2') format('woff2');
}

@font-face {
  font-family: 'Martian Mono';
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url('/fonts/martian-mono-latin-400.woff2') format('woff2');
}

:root {
  --ground: #e9efea;
  --leaf: #0b7a6b;
  --silver: #f4f8f5;
  --side-near: #0a5c52;
  --side-far: #06342f;
  --ink: #0e2a27;
  --post-red: #c8372d;

  /* The village, in the same family as the page so the word stays in front. */
  --turf: #dbe5dd;
  --road: #f1f5f2;
  --wall-lit: #f6f9f7;
  --wall-shade: #cfdbd4;
  --wall-dark: #b9c9c0;
  --roof-lit: #2c7f72;
  --roof-shade: #0a5c52;
  --trunk: #3d4f48;

  /* Set by app.js. Degrees of tilt, and 0..1 for how far the leaf has turned. */
  --rx: -34deg;
  --ry: 14deg;
  --flip: 0.2;

  /* Ten wide monospace characters: about 7.2em across. 9.6vw keeps the word
     inside a phone screen with room to turn; the cap is for large displays. */
  --word-size: clamp(1.5rem, 9.6vw, 9.5rem);

  --mono: 'Martian Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: 1fr auto;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--mono);
  overflow: hidden;
}

.stage {
  display: grid;
  place-items: center;
  min-height: 0;
}

/* A point in the middle of the stage: the world is built outward from it. */
.scene {
  width: 0;
  height: 0;
  font-size: var(--word-size);
  perspective: 8em;
  /* The village rises behind the word, so the word sits below the middle. */
  transform: translateY(1.15em);
}

.world,
.world .g {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}

.world {
  transform: rotateX(var(--rx)) rotateY(var(--ry));
}

/* A flat face, centred on the origin of its group before its own transform.
   Faces take no clicks: only the postman can be clicked (see .hit). */
.world .f {
  position: absolute;
  backface-visibility: hidden;
  pointer-events: none;
}

.world .f.both {
  backface-visibility: visible;
}

/* ---- The word ---------------------------------------------------------- */

.word {
  position: absolute;
  left: 0;
  top: 0;
  margin: 0;
  font-size: 1em;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  white-space: nowrap;
  color: var(--leaf);
  transform-style: preserve-3d;
  /* Bottom centre on the origin: the word stands on the ground. */
  transform: translate(-50%, -100%);
  user-select: none;
  cursor: default;
  pointer-events: none;
}

/* app.js replaces the text with a stack of copies, one per slice of depth. */
.word .layer {
  display: block;
  /* --z runs from 0 (front) to 1 (back); the block pivots around its middle. */
  transform: translateZ(calc((0.5 - var(--z)) * 0.26em));
  color: var(--tone);
}

.word .layer + .layer {
  position: absolute;
  inset: 0;
}

.word .layer.face {
  color: color-mix(in oklab, var(--leaf), var(--silver) calc(var(--flip) * 100%));
}

/* ---- The ground -------------------------------------------------------- */

.turf {
  background: radial-gradient(closest-side, var(--turf) 55%, transparent);
}

.road {
  border: 0.36em solid var(--road);
  border-radius: 0.7em;
}

.word-shadow {
  background: radial-gradient(closest-side, rgb(6 52 47 / 0.3), transparent);
  filter: blur(0.08em);
}

/* ---- Houses, trees, letterboxes ---------------------------------------- */

.wall-lit { background: var(--wall-lit); }
.wall-shade { background: var(--wall-shade); }
.wall-dark { background: var(--wall-dark); }
.roof-lit { background: var(--roof-lit); }
.roof-shade { background: var(--roof-shade); }
.gable { background: var(--wall-shade); clip-path: polygon(50% 0, 0 100%, 100% 100%); }
.door { background: var(--roof-shade); }
.window { background: color-mix(in oklab, var(--roof-lit), var(--silver) 55%); }
.trunk { background: var(--trunk); }
.ink { background: var(--ink); }
.box-lit { background: var(--wall-lit); }
.box-shade { background: var(--wall-dark); }
.red { background: var(--post-red); }
.red-shade { background: color-mix(in oklab, var(--post-red), black 22%); }
.skin { background: #e7c9a8; }
.skin-shade { background: #cfae8c; }
.bag { background: #6b5a45; }
/* An envelope: white, outlined so it shows against the houses, with a stamp. */
.paper {
  background:
    linear-gradient(var(--post-red), var(--post-red)) no-repeat right 12% top 20% / 22% 34%,
    #ffffff;
  outline: 0.012em solid var(--ink);
}

/* A poplar's crown: tall and narrow, turning silver with the tilt like the word. */
.crown {
  border-radius: 50% 50% 46% 46% / 64% 64% 36% 36%;
  background: color-mix(in oklab, var(--tone), var(--silver) calc(var(--flip) * 45%));
}

/* The flag on a letterbox lies flat until there is post in the box. */
.flag {
  transform: rotateZ(90deg);
  transition: transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.has-post > .flag {
  transform: rotateZ(0deg);
}

/* ---- The postman ------------------------------------------------------- */

/* Invisible panes around the postman. Clicking him lets the dog out; the
   pointer is the only hint. Inert until app.js marks them live (it does not
   when motion is reduced). */
.world .hit.live {
  pointer-events: auto;
  cursor: pointer;
}

.walking .limb.a {
  animation: swing 0.62s ease-in-out infinite alternate;
}

.walking .limb.b {
  animation: swing 0.62s ease-in-out infinite alternate-reverse;
}

/* Running: the same swing, much faster. Used for both of them. */
.running .limb.a,
.running .limb.b {
  animation-duration: 0.2s;
}

@keyframes swing {
  from { transform: rotateX(-32deg); }
  to { transform: rotateX(32deg); }
}

/* ---- The dog ----------------------------------------------------------- */

.fur { background: #b88248; }
.fur-shade { background: #96673a; }
.fur-dark { background: #5f3d20; }

.tail {
  animation: wag 0.18s ease-in-out infinite alternate;
}

@keyframes wag {
  from { transform: rotateZ(-30deg) rotateX(-25deg); }
  to { transform: rotateZ(30deg) rotateX(-25deg); }
}

/* "woof" and "!": a word above a head, in the page's typeface. */
.bubble {
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.12s;
}

.bubble.show {
  opacity: 1;
}

.bubble span {
  font-size: 0.13em;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
}

.letter {
  opacity: 0;
}

/* ---- The note ---------------------------------------------------------- */

.note {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
  padding: 1.25rem 1.5rem;
  font-size: 0.8125rem;
  font-weight: 400;
  line-height: 1.5;
}

.note p {
  margin: 0;
}

.note a {
  color: inherit;
  text-decoration-color: color-mix(in oklab, var(--ink), transparent 60%);
  text-underline-offset: 0.25em;
}

.note a:hover {
  text-decoration-color: currentColor;
}

.note a:focus-visible {
  outline: 2px solid var(--leaf);
  outline-offset: 4px;
  border-radius: 2px;
}

@media (max-width: 30rem) {
  .note {
    flex-direction: column;
    gap: 0.25rem;
  }
}
