/* Landing page: the grass island. Positions/routes live in island.css (generated).

   Everything on the island is measured in --u ("island units"). --u is picked so the
   whole island (CONTENT box below, in island units) fits between the nav bar and the
   bottom of the first screen, centred, at any window size. */

.page-home {
  /* the island's bounding box, in island units (measured from geometry.json) */
  --cx0: 1.7; --cy0: -2; --cw: 89.3; --ch: 64;
  --top: 76px;          /* room for the nav bar */
  --bottom: 28px;
  --side: 24px;
  --vh: 1vh;
  --u: min(calc((100vw - 2 * var(--side)) / var(--cw)), calc((100 * var(--vh) - var(--top) - var(--bottom)) / var(--ch)));
  --px: calc(var(--u) * 0.2778);    /* 1 sprite pixel of the little guys */
  --tree: calc(var(--u) * 0.2778);  /* 1 pixel of the trees and grass */
  --ex: calc(var(--u) * 0.06944);   /* one layer of the 3D name extrusion */
  overflow-x: hidden;
}
@supports (height: 100svh) { .page-home { --vh: 1svh; } }

.stage {
  position: relative;
  height: calc(100 * var(--vh));
  min-height: 420px;
  overflow: hidden;
}
.page-home > .site-header { position: absolute; top: 0; left: 0; right: 0; z-index: 20; }

.world { position: absolute; inset: 0; }
.rise { position: absolute; inset: 0; transition: opacity .7s ease .15s, transform .9s cubic-bezier(.2, .8, .2, 1) .15s; }
.is-loading .rise { opacity: 0; transform: translateY(40px); }
.scene {
  position: absolute;
  width: calc(var(--cw) * var(--u)); height: calc(var(--ch) * var(--u));
  /* centre the island's box in the space under the nav bar */
  left: calc(50% - (var(--cx0) + var(--cw) / 2) * var(--u));
  top: calc(var(--top) + (100% - var(--top) - var(--bottom) - var(--ch) * var(--u)) / 2 - var(--cy0) * var(--u));
}
.scene .prop, .scene .anchor, .scene .walker, .island > span {
  left: calc(var(--x) * var(--u));
  top: calc(var(--y) * var(--u));
}
.island > span { width: calc(var(--w) * var(--u)); height: calc(var(--h) * var(--u)); }

/* ---- island ---- */
.island {
  position: absolute; inset: 0;
  pointer-events: none;
  filter: drop-shadow(0 calc(2.4 * var(--u)) calc(2.2 * var(--u)) rgba(20, 40, 30, 0.18));
}
.island .top {
  position: absolute;
  transform-origin: 0 0;
  transform: matrix(0.866, 0.5, -0.866, 0.5, 0, 0);
  background-color: #63ab3f;
  background-image: url(/assets/world/grass_tile.png);
  background-size: calc(16 * var(--tree)) calc(16 * var(--tree));
  image-rendering: pixelated;
}
.island .face { position: absolute; transform-origin: 0 0; }
.island .face.l {
  transform: skewY(30deg) scaleX(0.866);
  background: linear-gradient(180deg, #3b7d4f 0 calc(0.55 * var(--u)), #2a594f calc(0.55 * var(--u)) calc(0.85 * var(--u)), #c0704a calc(0.85 * var(--u)) calc(1.9 * var(--u)), #a65a3e calc(1.9 * var(--u)));
}
.island .face.r {
  transform: skewY(-30deg) scaleX(0.866);
  background: linear-gradient(180deg, #2f6a46 0 calc(0.55 * var(--u)), #234a42 calc(0.55 * var(--u)) calc(0.85 * var(--u)), #99553b calc(0.85 * var(--u)) calc(1.9 * var(--u)), #82462f calc(1.9 * var(--u)));
}

.prop {
  position: absolute;
  display: block;
  transform: translate(-50%, -100%);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  image-rendering: pixelated;
  pointer-events: none;
}

/* ---- 3D name ---- */
.name { margin: 0; font-size: inherit; font-weight: inherit; }
.anchor { position: absolute; width: 0; height: 0; }
.wall {
  position: absolute; left: 0; bottom: 0;
  margin: 0;
  white-space: nowrap;
  transform-origin: 0 100%;
  transform: skewY(30deg) scaleX(0.866);
  color: var(--ink);
  font: 800 calc(13 * var(--u))/0.78 var(--display);
  letter-spacing: -0.06em;
}
.cast {
  position: absolute; left: 0; top: 0;
  width: calc(29 * var(--u)); height: calc(7 * var(--u));
  transform-origin: 0 0;
  transform: matrix(0.866, 0.5, -0.866, 0.5, 0, 0);
  background: linear-gradient(180deg, rgba(18, 50, 34, 0.38), rgba(18, 50, 34, 0));
  filter: blur(6px);
}

/* ---- walkers ---- */
.walker { position: absolute; display: block; width: 0; height: 0; text-decoration: none; }
.walker .body {
  position: absolute;
  left: calc(-12 * var(--px)); top: calc(-37 * var(--px));
  width: calc(24 * var(--px)); height: calc(38 * var(--px));
}
.walker .flip { position: absolute; inset: 0; }
.walker .spr {
  position: absolute; inset: 0;
  width: auto; height: auto;
  background-size: calc(96 * var(--px)) calc(38 * var(--px));
  animation: island-walk .6s steps(4) infinite;
}
.walker .shadow {
  position: absolute; left: 28%; right: 28%;
  bottom: calc(var(--px) * -0.5); height: calc(var(--px) * 2.5);
  border-radius: 50%;
  background: rgba(20, 21, 24, 0.14);
}
.walker .tag {
  position: absolute; left: 50%; top: var(--px);
  transform: translate(-50%, -100%) translateY(6px);
  opacity: 0;
  white-space: nowrap;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--ink); color: #fff;
  font: 600 12.5px var(--display);
  letter-spacing: -0.01em;
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
}

.walker:hover, .walker:focus-visible,
.walker:hover .flip, .walker:focus-visible .flip { animation-play-state: paused; }
.walker:hover, .walker:focus-visible { z-index: 9 !important; }
.walker:hover .spr, .walker:focus-visible .spr { background-image: var(--idle); animation: island-idle .9s steps(4) infinite; }
.walker:hover .tag, .walker:focus-visible .tag { opacity: 1; transform: translate(-50%, -100%); }
.walker:focus-visible { outline: none; }
.walker:focus-visible .tag { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--ink); }

/* click / tap: one full jump, then island.js follows the link */
.walker.is-jumping, .walker.is-jumping .flip { animation-play-state: paused; }
.walker.is-jumping { z-index: 9 !important; }
.walker.is-jumping .spr {
  background-image: var(--jump);
  background-size: calc(192 * var(--px)) calc(38 * var(--px));
  animation: island-jump .8s steps(8) 1 forwards;
}
.walker.is-jumping .tag { opacity: 1; transform: translate(-50%, -100%); }

@keyframes island-walk { from { background-position-x: 0; } to { background-position-x: calc(var(--px) * -96); } }
@keyframes island-idle { from { background-position-x: 0; } to { background-position-x: calc(var(--px) * -96); } }
@keyframes island-jump { from { background-position-x: 0; } to { background-position-x: calc(var(--px) * -192); } }

/* ---- copy ---- */
.home-copy {
  position: absolute; z-index: 10;
  left: 20px; bottom: 24px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 18px;
  max-width: 380px;
}
.home-copy p { margin: 0; }
.home-copy .hello { font-size: 22px; font-weight: 600; line-height: 1.2; letter-spacing: -0.015em; }
.home-copy .fine { font-size: 13px; font-weight: 500; color: var(--muted); }

/* ---- loading screen ----
   island.js counts the island's real downloads (grass, trees, every sprite sheet, fonts).
   The screen fades in only if loading takes longer than a quarter second, so a cached
   visit goes straight to the island. */
.loader {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: var(--bg);
  opacity: 0;
  animation: loader-in .2s ease .25s forwards, loader-failsafe 0s linear 15s forwards;
}
.loader.is-done { animation: loader-out .45s ease forwards; }
.loader.is-skipped { display: none; }
.loader .lg { position: relative; --k: 4; }
.loader .lg .shadow { position: absolute; left: 28%; right: 28%; bottom: -2px; height: 10px; border-radius: 50%; background: rgba(20, 21, 24, 0.14); }
.loader .bar { width: 240px; height: 18px; border: 3px solid var(--ink); padding: 3px; background: #fff; box-shadow: 4px 4px 0 var(--ink); }
.loader .fill { width: 0; height: 100%; background: repeating-linear-gradient(90deg, var(--ink) 0 10px, transparent 10px 12px); }
.loader .txt { font-family: var(--pixel); font-size: 14px; letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
.loader .count { margin-top: -12px; font-family: var(--pixel); font-size: 11px; letter-spacing: 0.04em; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1em; }
.loader .tip { font-size: 12.5px; color: var(--muted); }
.is-loading .rise { animation: rise-failsafe 0s linear 15s forwards; }
@keyframes loader-in { to { opacity: 1; } }
@keyframes loader-out { from { opacity: 1; } to { opacity: 0; visibility: hidden; pointer-events: none; } }
@keyframes loader-failsafe { to { opacity: 0; visibility: hidden; pointer-events: none; } }
@keyframes rise-failsafe { to { opacity: 1; transform: none; } }

@media (scripting: none) {
  .loader { display: none; }
  .is-loading .rise { opacity: 1; transform: none; }
}

/* ---- phones: the whole island across the screen, copy below it ---- */
@media (max-width: 760px) {
  .page-home {
    --side: 10px;
    --u: calc((100vw - 2 * var(--side)) / var(--cw));
    --px: 1.6px;  /* the guys stay big enough to tap */
  }
  .page-home > .site-header { position: relative; }
  /* first screen = island + the line under it; the island is centred in the space left over */
  .stage { display: flex; flex-direction: column; height: auto; min-height: calc(100 * var(--vh) - 72px); }
  .world { position: relative; inset: auto; flex: 1 0 auto; min-height: calc(var(--ch) * var(--u) + 28px); }
  .scene { top: calc(50% - (var(--cy0) + var(--ch) / 2) * var(--u)); }
  .walker .tag { font-size: 11px; padding: 4px 8px; }
  .home-copy { position: static; max-width: none; padding: 12px 20px 28px; }
  .home-copy .hello { font-size: 20px; }
}

/* ---- reduced motion: everyone stands still (but stays a link) ---- */
@media (prefers-reduced-motion: reduce) {
  .walker, .walker .flip { animation-play-state: paused !important; }
  .walker .spr, .walker:hover .spr { background-image: var(--idle); animation: none !important; }
  .walker.is-jumping .spr { background-image: var(--idle); background-size: calc(96 * var(--px)) calc(38 * var(--px)); }
  .rise { transition: none; }
  .loader .lg .spr { animation: none; }
}
