:root {
  color-scheme: light;
  --sky: #b8d0e6;
  --dialogue: #fff4b2;
  --dialogue-shadow: #5f5123;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--sky);
  font-family: Georgia, "Times New Roman", serif;
}

button {
  font: inherit;
}

.world {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 520px;
  overflow: hidden;
  background: linear-gradient(#a9c8e4 0%, #b8d0e6 44%, #88b747 44%, #5ca617 100%);
}

#scene {
  position: absolute;
  inset: 0;
  touch-action: none;
}

#scene canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.shade {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(19, 27, 9, 0.16), rgba(19, 27, 9, 0.03) 26%, transparent 56%),
    radial-gradient(circle at 50% 56%, transparent 0 42%, rgba(13, 34, 10, 0.2) 100%);
  mix-blend-mode: multiply;
}

.dialogue {
  pointer-events: none;
  position: absolute;
  left: 32.5%;
  top: 28.5%;
  margin: 0;
  color: var(--dialogue);
  text-shadow:
    0 2px 0 var(--dialogue-shadow),
    2px 0 0 rgba(95, 81, 35, 0.4),
    0 0 8px rgba(255, 245, 180, 0.28);
  font-size: clamp(1.08rem, 2vw, 1.8rem);
  line-height: 1.15;
  letter-spacing: 0;
  white-space: nowrap;
  transform: rotate(-1deg);
}

.sound-toggle {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: grid;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 8px;
  color: #fff7c9;
  background: rgba(46, 86, 24, 0.3);
  box-shadow: 0 8px 18px rgba(21, 39, 15, 0.16);
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.sound-toggle svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.sound-toggle .wave {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.sound-toggle[aria-pressed="true"] {
  color: #17330f;
  background: rgba(255, 242, 153, 0.86);
}

.movement-pad {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: calc(max(34px, env(safe-area-inset-bottom)) + 18px);
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 7px;
  pointer-events: none;
  filter: drop-shadow(0 12px 18px rgba(20, 46, 12, 0.18));
}

.move-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  color: #fff7c9;
  background: rgba(44, 83, 24, 0.34);
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  backdrop-filter: blur(6px);
}

.move-button svg {
  width: 23px;
  height: 23px;
  fill: currentColor;
}

.move-button:is(:hover, :focus-visible, [data-active="true"]) {
  color: #17330f;
  background: rgba(255, 242, 153, 0.86);
}

.move-button::after {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: 140px;
  padding: 5px 8px;
  border-radius: 6px;
  color: #fffce8;
  background: rgba(24, 42, 14, 0.72);
  content: attr(aria-label);
  font-family: system-ui, sans-serif;
  font-size: 0.72rem;
  line-height: 1;
  opacity: 0;
  transform: translateX(-50%) translateY(4px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.move-button:hover::after,
.move-button:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.move-button.up {
  grid-column: 2;
  grid-row: 1;
}

.move-button.left {
  grid-column: 1;
  grid-row: 2;
}

.move-button.right {
  grid-column: 3;
  grid-row: 2;
}

.move-button.down {
  grid-column: 2;
  grid-row: 3;
}

.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;
}

@media (max-width: 760px) {
  .world {
    min-height: 620px;
  }

  .dialogue {
    left: 18%;
    top: 31%;
    max-width: 72vw;
    white-space: normal;
  }

  .sound-toggle {
    width: 40px;
  }

  .movement-pad {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
    gap: 6px;
  }

  .move-button {
    width: 44px;
  }
}
