/* DOOF. The world is a 16:9 video that always covers the viewport; everything else is an
   object standing in that world, positioned in world percentages so it stays planted when
   the crop changes. Colours are read off his plate. */

@font-face {
  font-family: "MPlusRounded";
  src: url("assets/fonts/m-plus-rounded-1c-latin-800-normal.woff2") format("woff2");
  font-weight: 800;
  font-display: swap;
}
@font-face {
  font-family: "MPlusRounded";
  src: url("assets/fonts/m-plus-rounded-1c-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "JetBrainsMono";
  src: url("assets/fonts/jetbrains-mono-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

:root {
  --sky: #3fa9e8;
  --grass: #55cf1f;
  --cream: #f4f0d8;
  --lav: #b6b2d6;
  --wood: #c79a5a;
  --ink: #3a3326;
  --shadow: rgba(40, 60, 20, .35);

  /* Objects are furniture in front of the camera, so they are placed and sized against
     the VIEWPORT, not against the 16:9 stage that gets cropped behind them. Only the
     world video lives in stage space. --horizon is measured from the stage by main.js. */
  --wordmark-x: 32%;   --wordmark-y: 56%;  --wordmark-w: clamp(190px, 29vw, 500px);
  --board-x: 19%;      --board-y: 98%;     --board-w: clamp(270px, 31vw, 470px);
  --stereo-x: 94%;     --stereo-y: 99%;    --stereo-w: clamp(84px, 10vw, 170px);
  --item-w: clamp(62px, 8vw, 132px);
  --hole-w: clamp(76px, 10vw, 164px);
  --horizon: 42%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1b1f14;
  font-family: "MPlusRounded", "Trebuchet MS", system-ui, sans-serif;
  font-weight: 800;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

body {
  cursor: url("assets/img/cursor.png") 1 0, auto;
}
a, button, .item, .ground {
  cursor: url("assets/img/cursor-dig.png") 1 0, pointer;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:where(a, button):focus-visible {
  outline: 4px solid #fff;
  outline-offset: 2px;
  border-radius: 4px;
}
/* the dig surface is the whole field, so its ring is drawn inside it */
.ground:focus-visible {
  outline: 5px dashed rgba(255, 255, 255, .9);
  outline-offset: -14px;
}

/* ── the world ──────────────────────────────────────────────────────────── */

.stage {
  position: fixed;
  left: 50%;
  top: 50%;
  width: max(100vw, calc(100vh * 16 / 9));
  height: max(100vh, calc(100vw * 9 / 16));
  transform: translate(calc(-50% + var(--shift, 0%)), -50%);
  overflow: hidden;
}

.world {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* the viewport layer: everything the visitor can touch */
.field {
  position: fixed;
  inset: 0;
  z-index: 2;
}

.ground {
  position: absolute;
  left: 0;
  top: var(--horizon);
  width: 100%;
  height: calc(100% - var(--horizon));
  border: 0;
  padding: 0;
  background: transparent;
  appearance: none;
}

.obj {
  position: absolute;
  transform: translate(-50%, calc(-100% + var(--lift, 0px))) scale(var(--squash, 1));
  transform-origin: 50% 100%;
  transition: transform .12s ease-out;
  user-select: none;
  -webkit-user-drag: none;
}
.obj-art {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 6px 5px var(--shadow));
  pointer-events: none;
}

.wordmark {
  left: var(--wordmark-x);
  top: var(--wordmark-y);
  width: var(--wordmark-w);
  filter: drop-shadow(0 10px 6px var(--shadow));
  z-index: 2;
}

/* ── the contract: a message box from his world, standing in the grass ──── */

.plaque {
  left: var(--board-x);
  top: var(--board-y);
  width: var(--board-w);
  z-index: 6;
  container-type: inline-size;
}
.plaque-title {
  position: absolute;
  left: 13%;
  top: 7.4%;
  margin: 0;
  font-size: 5.4cqw;
  line-height: 1;
  letter-spacing: .06em;
  color: #eef1f6;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .45);
}
/* the panel's own writing area runs from 7.2% to 97.2% of the object, so the text sits
   inside it with an even margin on both sides rather than against the bevel */
.plaque-face {
  position: absolute;
  left: 13%;
  top: 27%;
  width: 78%;
  height: 62%;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr auto;
  align-content: stretch;
  gap: 4% 4%;
  padding: 1% 0 2%;
}
.plaque-ticker {
  grid-column: 1;
  grid-row: 1;
  align-self: center;
  margin: 0;
  font-size: 8.4cqw;
  line-height: 1;
  color: #2c2a26;
}
.plaque-label {
  grid-column: 2;
  grid-row: 1;
  align-self: center;
  justify-self: end;
  margin: 0;
  font-family: "JetBrainsMono", ui-monospace, monospace;
  font-weight: 500;
  font-size: 3.4cqw;
  line-height: 1;
  letter-spacing: .04em;
  color: #6d6a61;
  text-transform: lowercase;
}
.plaque-ca {
  grid-column: 1 / -1;
  grid-row: 2;
  margin: 0;
  align-self: center;
  font-family: "JetBrainsMono", ui-monospace, "Courier New", monospace;
  font-weight: 500;
  font-size: 4.15cqw;
  line-height: 1.32;
  letter-spacing: -.01em;
  color: #23211d;
  overflow-wrap: anywhere;
}
.plaque-copy {
  grid-column: 1 / -1;
  grid-row: 3;
  align-self: end;
  justify-self: end;
  font: inherit;
  font-size: 4cqw;
  letter-spacing: .04em;
  color: #23211d;
  background: #cdcabf;
  border: 0;
  padding: .45em 1.1em .5em;
  box-shadow:
    inset 0 0 0 1px #6f6c63,
    inset 2px 2px 0 #f2f0e7,
    inset -2px -2px 0 #86837a;
  white-space: nowrap;
}
.plaque-copy:active {
  box-shadow:
    inset 0 0 0 1px #6f6c63,
    inset 2px 2px 0 #86837a,
    inset -2px -2px 0 #f2f0e7;
  padding: .5em 1.05em .45em 1.15em;
}
.plaque-copy:disabled { color: #7c7a72; text-shadow: 1px 1px 0 #eeece4; }
.plaque.copied .plaque-copy { color: #1f6b1a; }
.plaque.failed .plaque-copy { color: #93231f; }

/* ── the two links: one pair of buttons, top right, and nothing else ─────── */

.links {
  position: fixed;
  top: max(2.2vh, 14px);
  right: max(2.2vw, 14px);
  z-index: 30;
  display: flex;
  align-items: flex-start;      /* or the flex row stretches the buttons out of square */
  gap: clamp(8px, .9vw, 14px);
}
.lnk {
  flex: 0 0 auto;
  width: clamp(42px, 3.4vw, 58px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 30%;
  background: linear-gradient(#fdfaea, #ece5c8);
  box-shadow:
    inset 0 0 0 clamp(2px, .22vw, 4px) #b6b2d6,
    0 3px 0 rgba(90, 80, 45, .35),
    0 6px 10px rgba(40, 60, 20, .28);
  text-decoration: none;
  transition: transform .12s ease-out, box-shadow .12s ease-out;
}
/* sized by WIDTH: a percentage height on a replaced element does not resolve here and
   the raw 238x346 logo blows the button out of square */
.lnk svg, .lnk img { display: block; height: auto; }
.lnk svg { width: 40%; fill: #23211d; }
.lnk img { width: 30%; filter: drop-shadow(0 1px 1px rgba(60, 50, 20, .4)); }
.lnk-text { font-size: clamp(12px, 1vw, 17px); color: #23211d; letter-spacing: .04em; }

.lnk:hover, .lnk:focus-visible {
  transform: translateY(-2px);
  box-shadow:
    inset 0 0 0 clamp(2px, .22vw, 4px) #a8a3cd,
    0 5px 0 rgba(90, 80, 45, .35),
    0 8px 12px rgba(40, 60, 20, .3);
}
.lnk:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 0 0 clamp(2px, .22vw, 4px) #a8a3cd,
    0 1px 0 rgba(90, 80, 45, .35),
    0 2px 5px rgba(40, 60, 20, .3);
}
.lnk[aria-disabled="true"] { background: linear-gradient(#efeada, #ddd7c1); }
.lnk[aria-disabled="true"] svg, .lnk[aria-disabled="true"] img { opacity: .38; }

/* ── the stereo is the sound control ────────────────────────────────────── */

.stereo {
  left: var(--stereo-x);
  top: var(--stereo-y);
  width: var(--stereo-w);
  z-index: 7;
}
.stereo-hit, .stereo-vol {
  position: absolute;
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 50%;
}
.stereo-hit { left: 3%; top: 10%; width: 94%; height: 88%; border-radius: 7%; }
.stereo-vol { width: 11%; height: 15%; top: 27%; border-radius: 20%; }
.stereo-vol-down { left: 36.5%; }
.stereo-vol-up { left: 54.5%; }
.stereo-hit:hover ~ .stereo-note, .stereo.on .stereo-note { opacity: 1; }
.stereo-note {
  position: absolute;
  left: 6%;
  top: -22%;
  width: 26%;
  aspect-ratio: 1;
  background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23f4f0d8' stroke='%233a3326' stroke-width='1.6' d='M9 18V5l10-2v13'/%3E%3Ccircle cx='6' cy='18' r='3' fill='%23f4f0d8' stroke='%233a3326' stroke-width='1.6'/%3E%3Ccircle cx='16' cy='16' r='3' fill='%23f4f0d8' stroke='%233a3326' stroke-width='1.6'/%3E%3C/svg%3E");
  opacity: 0;
  transition: opacity .2s;
}
.stereo.on .stereo-note { animation: note 2.2s linear infinite; }
@keyframes note {
  0% { opacity: 0; transform: translate(0, 10%) scale(.7); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(40%, -90%) scale(1.1); }
}
.stereo:not(.on) .obj-art { filter: drop-shadow(0 6px 5px var(--shadow)) saturate(.45); }

.doof-hit {
  position: absolute;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 44% 44% 30% 30%;
  z-index: 4;
}

/* ── holes, dirt and the things that come out of them ───────────────────── */

.dug { position: absolute; inset: 0; pointer-events: none; }

.hole, .item, .clod {
  position: absolute;
  transform-origin: 50% 100%;
}
.hole {
  transform: translate(-50%, -72%) scale(var(--s));
  width: var(--hole-w);
  pointer-events: none;
}
.hole img { width: 100%; height: auto; display: block; }

.item {
  transform: translate(-50%, -100%) scale(var(--s));
  width: var(--item-w);
  padding: 0;
  border: 0;
  background: none;
  pointer-events: auto;
  animation: rise .55s cubic-bezier(.2, 1.5, .5, 1) both;
}
.item::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4%;
  width: 78%;
  height: 16%;
  transform: translateX(-50%);
  background: radial-gradient(50% 50% at 50% 50%, rgba(28, 52, 10, .5), rgba(28, 52, 10, 0) 70%);
  pointer-events: none;
}
.item img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 4px 3px var(--shadow));
  transition: transform .12s ease-out;
}
.item:hover img, .item:focus-visible img { transform: translateY(-6%) rotate(-2deg); }
@keyframes rise {
  0% { transform: translate(-50%, -20%) scale(calc(var(--s) * .4)); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: translate(-50%, -100%) scale(var(--s)); opacity: 1; }
}

.clod {
  width: 9px;
  aspect-ratio: 1;
  background: #7a5230;
  border-radius: 15%;
  pointer-events: none;
  animation: clod .7s ease-out forwards;
}
@keyframes clod {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.5) rotate(var(--r)); opacity: 0; }
}

/* ── he talks ───────────────────────────────────────────────────────────── */

/* The dialogue sits beside the contract window rather than on top of it. */
.talk {
  position: fixed;
  left: 42%;
  right: 16%;
  bottom: 3.5%;
  max-width: 760px;
  z-index: 20;
  padding: 1.4% 2.2% 1.8%;
  --bw: clamp(17px, 2.5vw, 34px);
  border-style: solid;
  border-width: calc(var(--bw) * .81) var(--bw) calc(var(--bw) * .95) calc(var(--bw) * .97);
  border-image: url("assets/img/dialogbox.png") 29 36 34 35 fill / calc(var(--bw) * .81) var(--bw) calc(var(--bw) * .95) calc(var(--bw) * .97) / 0 stretch;
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
.talk-name {
  margin: 0 0 .15em;
  font-size: clamp(13px, 1.35vw, 21px);
  color: #8a6b32;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.talk-line {
  margin: 0;
  font-size: clamp(15px, 1.75vw, 27px);
  line-height: 1.28;
  color: #3a3326;
  min-height: 2.56em;
}
.talk-more {
  position: absolute;
  right: 4%;
  bottom: 6%;
  width: 0;
  height: 0;
  border: .5em solid transparent;
  border-top-color: #8a6b32;
  animation: blink 1s steps(2) infinite;
  opacity: 0;
}
.talk.done .talk-more { opacity: 1; }
@keyframes blink { 50% { opacity: .2; } }

.hint {
  position: fixed;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  margin: 0;
  padding: .5em 1.1em;
  font-size: clamp(13px, 1.4vw, 20px);
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .45);
  animation: fadein 1.2s ease-out both, bob 2.6s ease-in-out infinite;
  z-index: 15;
}
@keyframes fadein { from { opacity: 0; } }
@keyframes bob { 50% { transform: translate(-50%, -18%); } }

/* ── the viewer: one thing he dug up, big ───────────────────────────────── */

.viewer {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 100vw;
  max-height: 100vh;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.viewer::backdrop { background: rgba(18, 30, 8, .82); }
.viewer[open] { display: grid; place-items: center; }
.viewer-frame {
  width: min(92vw, 1200px);
  aspect-ratio: 3 / 2;
  display: grid;
  place-items: center;
  animation: pop2 .22s ease-out;
}
@keyframes pop2 { from { transform: scale(.94); opacity: 0; } }
.viewer-frame img, .viewer-frame video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 6px;
}
.viewer-close {
  position: fixed;
  right: 3vw;
  top: 3vh;
  width: 2.4em;
  height: 2.4em;
  font: inherit;
  font-size: clamp(16px, 2vw, 26px);
  color: #3a3326;
  background: var(--cream);
  border: 3px solid #3a3326;
  border-radius: 50%;
  line-height: 1;
}

/* ── the film ───────────────────────────────────────────────────────────── */

.film {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 60;
  display: grid;
  place-items: center;
}
.film-v { width: 100%; height: 100%; object-fit: cover; }
.film-skip {
  position: fixed;
  right: 4vw;
  bottom: 5vh;
  font: inherit;
  font-size: clamp(13px, 1.4vw, 19px);
  color: #fff;
  background: rgba(0, 0, 0, .45);
  border: 2px solid rgba(255, 255, 255, .7);
  border-radius: 999px;
  padding: .5em 1.4em;
}

/* ── the gate ───────────────────────────────────────────────────────────── */

.gate {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: #05060a;
  overflow: hidden;
}
.gate-plate {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: .9;
}
.gate-inner {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 1.2rem;
  text-align: center;
  padding: 6vw;
}
.gate-mark {
  width: min(52vw, 460px);
  height: auto;
  filter: drop-shadow(0 8px 0 rgba(0, 0, 0, .35));
}
.gate-btn {
  font: inherit;
  font-size: clamp(17px, 2.2vw, 28px);
  color: #3a3326;
  background: linear-gradient(#fdfbe9, #e6dfbe);
  border: 0;
  border-bottom: 6px solid #b0a578;
  border-radius: 999px;
  padding: .55em 1.9em;
  letter-spacing: .02em;
}
.gate-btn:active { transform: translateY(3px); border-bottom-width: 3px; }
.gate-note {
  margin: 0;
  font-size: clamp(12px, 1.3vw, 17px);
  color: rgba(255, 255, 255, .82);
  letter-spacing: .16em;
  text-transform: uppercase;
}
.gate.out { animation: gateout .45s ease-in forwards; }
@keyframes gateout { to { opacity: 0; visibility: hidden; } }

/* ── phone: the crop keeps his half of the field, the objects come inboard ── */

@media (max-aspect-ratio: 1/1) {
  :root {
    /* the crop is 26% of a 16:9 world, so slide it until he is the one in it */
    --shift: -18%;
    --wordmark-x: 50%;  --wordmark-y: 33%;  --wordmark-w: min(70vw, 320px);
    --board-x: 35%;     --board-y: 87%;     --board-w: min(66vw, 268px);
    --stereo-x: 85%;    --stereo-y: 87%;    --stereo-w: min(22vw, 104px);
    --item-w: min(19vw, 96px);
    --hole-w: min(23vw, 116px);
  }
  .talk {
    left: 3%;
    right: 3%;
    bottom: 1.5%;
    --bw: clamp(13px, 4.4vw, 26px);
    padding: 1.6% 2.6% 2%;
  }
  .talk-name { font-size: clamp(11px, 2.6vw, 16px); }
  .talk-line { font-size: clamp(13px, 3.2vw, 20px); }
  .viewer-frame { width: 94vw; }
}

@media (prefers-reduced-motion: reduce) {
  .item, .talk, .viewer-frame, .hint { animation: none !important; }
  .stereo.on .stereo-note { animation: none; opacity: 1; }
  .clod { display: none; }
}
