@import url("https://fonts.googleapis.com/css2?family=Pixelify+Sans:wght@400..700&display=swap");

:root {
  --bg: #242526;
  --panel: rgba(14, 15, 18, 0.62);
  --text: #d6d6d6;
  --muted: #8a8b92;
  --magenta: #ff38f8;
  --coral: #ef705b;
  --violet: #817bd7;
  --blue: #465d78;
  --cyan: #416a6c;
  --olive: #778b68;
  --ochre: #a2713f;
}

* {
  box-sizing: border-box;
}

html,
body,
#game {
  width: 100%;
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Pixelify Sans", "Silkscreen", "Press Start 2P", "SFMono-Regular", "Consolas", monospace;
  -webkit-font-smoothing: none;
  font-smooth: never;
  text-rendering: geometricPrecision;
}

button {
  touch-action: manipulation;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(22, 23, 28, 0.72);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  padding: 13px 20px;
  text-transform: uppercase;
}

button:hover {
  border-color: rgba(255, 56, 248, 0.55);
  color: var(--magenta);
}

#game {
  position: relative;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 42%, rgba(86, 96, 122, 0.22), transparent 28%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.46));
}

#game::before,
#game::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

#game::before {
  background: rgba(31, 32, 34, 0.46);
  mix-blend-mode: multiply;
}

#game::after {
  background-image:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px),
    radial-gradient(circle at center, transparent 26%, rgba(0, 0, 0, 0.54) 72%, rgba(0, 0, 0, 0.86));
}

.stage-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  perspective: 1400px;
  perspective-origin: 50% 50%;
  place-items: center;
  transform-style: preserve-3d;
  z-index: 3;
}

.stage {
  --tilt-x: 0deg;
  --tilt-y: 0deg;
  position: relative;
  width: min(78vh, 62vw, 820px);
  aspect-ratio: 1;
  transform:
    rotateX(var(--tilt-x))
    rotateZ(0deg)
    rotateY(var(--tilt-y))
    translateZ(0);
  transform-style: preserve-3d;
  transition: transform 220ms ease;
}

.layer {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 10), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-size, 10), minmax(0, 1fr));
  transform-style: preserve-3d;
  will-change: transform, filter, opacity;
}

.cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  font-size: clamp(28px, 5.4vw, 80px);
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 12px currentColor;
  transform: translateZ(0);
}

@keyframes soft-sway {
  0%,
  100% {
    transform: translateX(-1px);
  }

  50% {
    transform: translateX(2px);
  }
}

@keyframes idle-bob {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-3px);
  }
}

.layer.back .cell {
  font-size: clamp(18px, 2.6vw, 42px);
  opacity: 0.7;
}

.layer.focus .cell {
  text-shadow:
    0 0 8px currentColor,
    0 0 18px rgba(129, 123, 215, 0.16);
}

.layer.leaf-layer {
  pointer-events: none;
  mask-image: radial-gradient(circle at center, transparent 0 16%, black 34%, black 62%, transparent 86%);
  -webkit-mask-image: radial-gradient(circle at center, transparent 0 16%, black 34%, black 62%, transparent 86%);
}

.leaf-layer-1 {
  filter: blur(0.3px) drop-shadow(2px 5px 1px rgba(0, 0, 0, 0.22));
}

.leaf-layer-2 {
  filter: blur(0.65px) drop-shadow(4px 9px 1px rgba(0, 0, 0, 0.25));
}

.leaf-layer-3 {
  filter: blur(1px) drop-shadow(6px 13px 2px rgba(0, 0, 0, 0.28));
}

.leaf {
  color: rgba(92, 139, 113, 0.82);
}

.canopy-leaf {
  font-size: clamp(24px, 4.5vw, 72px);
  font-weight: 700;
  line-height: 1;
  animation: soft-sway 2.9s steps(2, end) infinite;
  animation-delay: calc(var(--phase) * -1);
  text-shadow:
    3px 7px 0 rgba(0, 0, 0, 0.18),
    0 0 10px rgba(92, 139, 113, 0.12);
}

.leaf-1 {
  color: rgba(82, 132, 111, 0.68);
}

.leaf-2 {
  color: rgba(105, 156, 123, 0.74);
}

.leaf-3 {
  color: rgba(143, 181, 132, 0.82);
}

.empty {
  opacity: 0;
}

.floor { color: rgba(45, 58, 86, 0.7); }
.tree {
  color: rgba(65, 106, 108, 0.88);
  animation: soft-sway 3.4s steps(2, end) infinite;
  animation-delay: calc(var(--phase) * -1);
}
.rock { color: rgba(129, 123, 215, 0.78); }
.hero {
  color: #dde2ff;
  animation: idle-bob 1.35s steps(2, end) infinite;
}
.monster {
  color: var(--coral);
  animation: idle-bob 1.5s steps(2, end) infinite;
  animation-delay: calc(var(--phase) * -1);
}
.chest { color: var(--ochre); }
.bush { color: var(--olive); }

.stats {
  position: absolute;
  left: 28px;
  top: 22px;
  z-index: 30;
  color: #9b82ff;
  font-size: clamp(16px, 1.5vw, 24px);
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 9px rgba(155, 130, 255, 0.25);
}

.stats p {
  margin: 0 0 2px;
}

.legend {
  position: absolute;
  right: clamp(28px, 6vw, 90px);
  top: 29%;
  z-index: 30;
  font-size: clamp(22px, 2.6vw, 40px);
  font-weight: 700;
  line-height: 1.34;
}

.legend p {
  margin: 0;
}

.legend span {
  display: inline-block;
  width: 1.15em;
}

.hud {
  position: absolute;
  inset: auto clamp(28px, 6vw, 84px) 26px clamp(28px, 6vw, 84px);
  z-index: 30;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  pointer-events: none;
}

.level,
.hp {
  margin: 0;
  font-size: clamp(38px, 5vw, 64px);
  font-weight: 700;
  line-height: 1.12;
}

.hp {
  color: var(--coral);
}

.log {
  max-width: 330px;
  text-align: right;
  font-size: clamp(20px, 2.4vw, 34px);
  font-weight: 700;
  line-height: 1.16;
}

.log p {
  margin: 0;
}

.log p + p {
  color: var(--muted);
}

.controls {
  position: absolute;
  right: 18px;
  top: 17px;
  z-index: 35;
  display: flex;
  gap: 8px;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 32, 34, 0.78);
  backdrop-filter: blur(8px);
}

.overlay[hidden] {
  display: none;
}

.overlay > div {
  width: min(430px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(18, 19, 24, 0.92);
  padding: 30px;
  text-align: center;
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.55);
}

.overlay-kicker {
  margin: 0;
  color: var(--magenta);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.35em;
  text-transform: uppercase;
}

.overlay-title {
  margin: 12px 0;
  font-size: 42px;
}

.overlay-copy {
  color: var(--muted);
}

@media (max-width: 820px) {
  .stage {
    width: min(92vw, 62vh);
  }

  .stats {
    font-size: 18px;
    left: 16px;
    top: 18px;
  }

  .legend {
    right: 16px;
    top: 18px;
    font-size: clamp(17px, 6vw, 23px);
    line-height: 1.18;
  }

  .controls {
    inset: auto 14px 14px auto;
    transform: scale(0.82);
    transform-origin: bottom right;
  }

  .controls [data-action="interact"] {
    display: none;
  }

  .hud {
    inset: auto 18px 18px 18px;
  }

  .level,
  .hp {
    font-size: clamp(34px, 14vw, 56px);
  }

  .log {
    display: none;
  }
}
