/* Wildhoney Games teaser. One screen, never scrolls.
   Without script the page shows its settled state; html.anim is the opening state. */

:root {
  --night: #0b0504;
  --amber: #f2a24a;
  /* One unit is one pixel of the supplied logo. The lockup is 1223 wide and 723 tall. */
  --u: min(86vw / 1223, 50vh / 723, 1px);
  --backdrop: url('assets/backdrop.webp');
  color-scheme: dark;
}

@supports (height: 1dvh) {
  :root {
    --u: min(86vw / 1223, 50dvh / 723, 1px);
  }
}

/* Tall screens get the tall painting. main.js makes the same choice with the same rule. */
@media (max-aspect-ratio: 4/5) {
  :root {
    --backdrop: url('assets/backdrop-tall.webp');
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--night);
}

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--night);
  touch-action: pinch-zoom;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* The painting as every still page shows it: darker at the corners, deeper behind the logo. */
.stage::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 62% 36% at 50% 47%, rgba(11, 5, 4, 0.55), transparent 72%),
    radial-gradient(ellipse 120% 120% at 50% 50%, transparent 55%, rgba(11, 5, 4, 0.55) 100%),
    var(--backdrop) center / cover no-repeat;
}

/* With the intro, the shader paints it; the still copy shows only where WebGL is missing,
   and then it fades up out of the dark. */
html.anim .stage::before {
  opacity: 0;
}

html.anim.no-gl .stage::before {
  transition: opacity calc(4.5s * var(--pace, 1)) ease-in-out;
}

html.anim.no-gl.dawn .stage::before {
  opacity: 1;
}

.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.lockup {
  position: relative;
  margin: 0;
  width: calc(1223 * var(--u));
  height: calc(723 * var(--u));
  transform: translate3d(var(--shift-x, 0px), calc(-2vh + var(--shift-y, 0px)), 0);
  font-size: 0;
}

/* The logo gives off its own warmth against the dark. The glow sits on the two wrappers whose
   own contents never change, so it is worked out once and not on every frame. */
.flower-pulse,
.ink {
  filter: drop-shadow(0 0 calc(30 * var(--u)) rgba(255, 132, 24, 0.34))
    drop-shadow(0 calc(4 * var(--u)) calc(10 * var(--u)) rgba(11, 5, 4, 0.55));
}

.ink {
  position: absolute;
  inset: 0;
  display: block;
}

.flower {
  position: absolute;
  top: 0;
  left: calc(420.4 * var(--u));
  width: calc(414 * var(--u));
  height: calc(414 * var(--u));
  display: block;
}

.flower-turn,
.flower-pulse {
  position: absolute;
  inset: 0;
  display: block;
}

.whole,
.petal {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.petal {
  background: url('assets/flower.webp') center / 100% 100% no-repeat;
  transform-origin: 50% 50%;
  will-change: transform, opacity;
}

.word {
  position: absolute;
  left: 0;
  top: calc(358 * var(--u));
  width: 100%;
  height: calc(365 * var(--u));
  display: block;
}

.word img {
  width: 100%;
  height: 100%;
  display: block;
}

/* One slow line of light across the wordmark, cut to its letters. */
.sheen {
  position: absolute;
  inset: 0;
  display: block;
  opacity: 0;
  background: linear-gradient(
      100deg,
      transparent 46%,
      rgba(255, 232, 180, 0.55) 50%,
      transparent 54%
    )
    130% 0 / 260% 100% no-repeat;
  -webkit-mask: url('assets/wordmark.webp') center / 100% 100% no-repeat;
  mask: url('assets/wordmark.webp') center / 100% 100% no-repeat;
  mix-blend-mode: screen;
  pointer-events: none;
}

/* Opening state */

html.anim .whole {
  opacity: 0;
}

html.anim .petal {
  opacity: 0;
  transform: scale(0.02) rotate(-55deg);
}

html.anim .bloom .petal {
  /* --pace shortens the intro for someone who has seen it; main.js sets it. */
  animation: petal calc(2.1s * var(--pace, 1)) cubic-bezier(0.19, 0.9, 0.22, 1) both;
  animation-delay: calc(var(--i) * 0.22s * var(--pace, 1));
}

html.anim .settled .whole {
  opacity: 1;
}

html.anim .settled .petal {
  display: none;
}

html.anim .word img {
  opacity: 0;
  transform: scale(1.05);
  filter: blur(calc(16 * var(--u)));
}

html.anim .rise .word img {
  animation: focus calc(3s * var(--pace, 1)) cubic-bezier(0.22, 0.7, 0.2, 1) both;
}

html.anim .settled .sheen {
  animation: sheen 15s ease-in-out 0.4s infinite;
}

html.anim .settled .flower-turn {
  animation: breathe 11s ease-in-out infinite;
}

@keyframes petal {
  from {
    opacity: 0;
    transform: scale(0.02) rotate(-55deg);
  }
  22% {
    opacity: 1;
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes focus {
  from {
    opacity: 0;
    transform: scale(1.05);
    filter: blur(calc(16 * var(--u)));
  }
  to {
    opacity: 1;
    transform: none;
    filter: blur(0);
  }
}

@keyframes sheen {
  0% {
    opacity: 0;
    background-position: 130% 0;
  }
  2% {
    opacity: 1;
  }
  16% {
    opacity: 1;
    background-position: -30% 0;
  }
  18%,
  100% {
    opacity: 0;
    background-position: -30% 0;
  }
}

@keyframes breathe {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  25% {
    transform: rotate(0.9deg) scale(1.014);
  }
  75% {
    transform: rotate(-0.9deg) scale(1.014);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* Sound: a quiet button in the corner, shown once the page has settled. */
.sound {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 2;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 1px solid rgba(242, 162, 74, 0.34);
  border-radius: 50%;
  background: rgba(11, 5, 4, 0.62);
  color: var(--amber);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 1.2s ease,
    visibility 0s 1.2s,
    background-color 0.2s ease;
}

html.settled .sound {
  opacity: 0.85;
  visibility: visible;
  transition:
    opacity 1.2s ease 0.6s,
    background-color 0.2s ease;
}

html.settled .sound:hover,
html.settled .sound:focus-visible,
html.settled .sound[aria-pressed='true'] {
  opacity: 1;
  background: rgba(11, 5, 4, 0.85);
}

.sound:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.sound svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound .cone {
  fill: currentColor;
}

.sound[aria-pressed='true'] .cross,
.sound[aria-pressed='false'] .waves {
  display: none;
}

/* 404: the flower alone, leading home. */
.lost {
  position: relative;
  display: block;
  width: min(40vw, 30vh, 220px);
  filter: drop-shadow(0 0 28px rgba(255, 132, 24, 0.4));
}

.lost img {
  width: 100%;
  height: auto;
  display: block;
}
