:root {
  --cream: #fff0bd;
  --gold: #e0a72f;
  --ink: #1d140d;
  --green: #0f4637;
  --lapis: #164776;
  --berry: #a53145;
  --moss: #6a8d38;
  --shadow: rgba(8, 10, 7, 0.42);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #102f27;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 0;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

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

.game {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 420px;
  overflow: hidden;
  isolation: isolate;
  user-select: none;
}

.world,
.shade {
  position: absolute;
  inset: 0;
}

.world {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.04);
  z-index: -2;
}

.shade {
  z-index: -1;
  background:
    radial-gradient(circle at 50% 47%, rgba(255, 240, 189, 0.04), transparent 29%),
    radial-gradient(circle at 50% 50%, rgba(8, 24, 18, 0.08), rgba(8, 24, 18, 0.42) 73%, rgba(8, 24, 18, 0.72) 100%);
}

.topbar {
  position: absolute;
  inset: max(0.7rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) auto max(0.75rem, env(safe-area-inset-left));
  z-index: 8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
  pointer-events: none;
}

.player,
.score {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.player,
.score,
.recipe,
.bag,
.round,
.charm {
  border: 2px solid rgba(255, 240, 189, 0.72);
  color: var(--cream);
  background: rgba(29, 20, 13, 0.58);
  box-shadow: 0 0.75rem 1.4rem var(--shadow), inset 0 0 0 1px rgba(224, 167, 47, 0.24);
  backdrop-filter: blur(10px);
}

.player {
  width: 2.8rem;
  height: 2.8rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
}

.player svg {
  width: 62%;
  height: 62%;
  fill: currentColor;
}

.score {
  min-width: 4.6rem;
  min-height: 2.45rem;
  justify-content: center;
  border-radius: 999px;
  font-weight: 950;
}

.score svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
}

.clearing {
  position: absolute;
  inset: 9% 4% 17%;
  z-index: 2;
}

.field {
  position: relative;
  width: 100%;
  height: 100%;
}

.found {
  --size: clamp(48px, 7vw, 5.4rem);
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--size);
  height: var(--size);
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--cream);
  background:
    radial-gradient(circle at 34% 22%, rgba(255, 255, 255, 0.34), transparent 28%),
    linear-gradient(135deg, rgba(17, 96, 71, 0.88), rgba(22, 71, 118, 0.9));
  box-shadow: 0 0.9rem 1.6rem var(--shadow), 0 0 0 2px rgba(255, 240, 189, 0.62);
  transform: translate(-50%, -50%) scale(var(--s));
  cursor: pointer;
  touch-action: manipulation;
}

.found svg,
.slot svg,
.bag svg,
.round svg,
.charm svg {
  width: 58%;
  height: 58%;
  fill: currentColor;
  stroke: currentColor;
}

.found-berry { background: linear-gradient(135deg, rgba(165, 49, 69, 0.92), rgba(224, 167, 47, 0.86)); }
.found-feather { background: linear-gradient(135deg, rgba(22, 71, 118, 0.9), rgba(255, 240, 189, 0.3)); }
.found-shell { background: linear-gradient(135deg, rgba(255, 240, 189, 0.38), rgba(165, 49, 69, 0.86)); }
.found-moss { background: linear-gradient(135deg, rgba(106, 141, 56, 0.96), rgba(17, 96, 71, 0.9)); }

.house {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  width: clamp(14rem, 30vw, 23rem);
  height: clamp(16rem, 34vw, 25rem);
  transform: translate(-50%, -47%);
  pointer-events: none;
}

.slot {
  position: absolute;
  display: grid;
  place-items: center;
  color: rgba(255, 240, 189, 0.86);
  background: rgba(29, 20, 13, 0.42);
  border: 3px dashed rgba(255, 240, 189, 0.58);
  box-shadow: 0 1rem 2rem var(--shadow), inset 0 0 0 0.35rem rgba(29, 20, 13, 0.14);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.slot.filled {
  border-style: solid;
  background:
    radial-gradient(circle at 32% 22%, rgba(255, 255, 255, 0.28), transparent 24%),
    linear-gradient(135deg, rgba(224, 167, 47, 0.82), rgba(17, 96, 71, 0.82));
}

.roof {
  left: 17%;
  top: 0;
  width: 66%;
  height: 34%;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.walls {
  left: 22%;
  top: 28%;
  width: 56%;
  height: 50%;
  border-radius: 8px;
}

.door {
  left: 39%;
  bottom: 5%;
  width: 22%;
  height: 33%;
  border-radius: 999px 999px 8px 8px;
}

.slot.charm {
  right: 3%;
  top: 42%;
  width: 27%;
  height: 27%;
  border-radius: 50%;
}

.recipe {
  position: absolute;
  left: 50%;
  top: max(0.7rem, env(safe-area-inset-top));
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 3.1rem;
  padding: 0.35rem;
  border-radius: 999px;
  transform: translateX(-50%);
}

.recipe-icons {
  display: flex;
  gap: 0.25rem;
}

.recipe-icons span {
  width: clamp(2rem, 5vw, 2.7rem);
  height: clamp(2rem, 5vw, 2.7rem);
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: rgba(255, 240, 189, 0.88);
  background: rgba(16, 47, 39, 0.72);
}

.recipe-icons .ready {
  color: var(--gold);
}

.round,
.charm {
  width: clamp(48px, 6vw, 3.4rem);
  height: clamp(48px, 6vw, 3.4rem);
  display: grid;
  place-items: center;
  border-radius: 50%;
  cursor: pointer;
}

.inventory {
  position: absolute;
  left: max(0.65rem, env(safe-area-inset-left));
  right: max(0.65rem, env(safe-area-inset-right));
  bottom: max(0.6rem, env(safe-area-inset-bottom));
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 0.4rem;
}

.bag {
  min-width: 0;
  min-height: clamp(3.6rem, 8vw, 4.7rem);
  display: grid;
  place-items: center;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
}

.bag.active {
  color: #fff7d7;
  background: rgba(22, 71, 118, 0.82);
  box-shadow: 0 0 0 0.25rem rgba(224, 167, 47, 0.34), 0 0.8rem 1.5rem var(--shadow);
}

.bag span {
  position: absolute;
  right: 0.25rem;
  bottom: 0.18rem;
  min-width: 1.35rem;
  height: 1.35rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--ink);
  background: var(--cream);
  font-size: 0.78rem;
  font-weight: 950;
}

.charms {
  position: absolute;
  right: max(0.7rem, env(safe-area-inset-right));
  top: 50%;
  z-index: 8;
  display: grid;
  gap: 0.45rem;
  transform: translateY(-50%);
}

.charm.active {
  background: rgba(165, 49, 69, 0.84);
  box-shadow: 0 0 0 0.25rem rgba(224, 167, 47, 0.32), 0 0.8rem 1.4rem var(--shadow);
}

@media (max-width: 760px) {
  .world {
    width: 150%;
    max-width: none;
    transform: translateX(-17%) scale(1.03);
  }

  .clearing {
    inset: 12% 2% 20%;
  }

  .recipe {
    top: max(3.6rem, env(safe-area-inset-top));
  }

  .house {
    width: min(63vw, 17rem);
    height: min(68vw, 19rem);
  }

  .inventory {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .bag {
    min-height: 3.25rem;
  }

  .charms {
    top: auto;
    right: max(0.65rem, env(safe-area-inset-right));
    bottom: max(7.8rem, env(safe-area-inset-bottom));
    grid-template-columns: repeat(3, 1fr);
    transform: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .found {
    animation: bob 3.2s ease-in-out infinite;
  }

  .slot.filled {
    animation: glint 2.8s ease-in-out infinite;
  }

  @keyframes bob {
    50% { margin-top: -0.25rem; }
  }

  @keyframes glint {
    50% { filter: brightness(1.12) saturate(1.16); }
  }
}

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