.tree-page {
  background: #210819;
}

.tree-game {
  position: relative;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: radial-gradient(ellipse at 50% 50%, #622944, #210819 76%);
}

.tree-header {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  padding: max(1rem, env(safe-area-inset-top)) clamp(.8rem, 3vw, 2rem) .6rem;
  text-align: center;
}

.tree-header h1 {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: clamp(1.65rem, 3.5vw, 2.8rem);
}

.tree-header p {
  margin: .45rem 0 0;
  color: #f9d1e4;
  font-size: .92rem;
}

.tree-link, .tree-pill, .tree-counter {
  border: 1px solid #ffbdce66;
  border-radius: 999px;
  padding: .55rem .85rem;
  color: #fff0eb;
  background: #3d1029;
  font: 600 .85rem/1.2 system-ui, sans-serif;
}

.tree-link { text-decoration: none; cursor: pointer; }
.tree-link:hover { background: #672342; }
.tree-link:focus-visible, .ornament:focus-visible {
  outline: 2px solid #ffe6a3;
  outline-offset: 2px;
}

.tree-back { justify-self: start; }
.tree-counter { justify-self: end; margin-inline-end: 6rem; white-space: nowrap; color: #ffcf91; }
.tree-page :is(.settings-toggle, .sound-toggle) { top: calc(max(1rem, env(safe-area-inset-top)) + 1.1rem); }
.tree-stage {
  display: grid;
  justify-items: center;
  align-content: start;
  grid-template-columns: minmax(0, 1fr);
}

.tree-scene {
  position: relative;
  width: min(100%, clamp(29rem, calc((100dvh - 6.5rem) * .96), 56rem));
  aspect-ratio: 1 / 1.04;
  isolation: isolate;
}

.tree-art {
  width: 100%;
  height: 100%;
  display: block;
  mask-image: radial-gradient(ellipse 59% 64% at 50% 51%, #000 61%, transparent 100%);
}

.tree-ornaments { position: absolute; inset: 0; }

.ornament {
  position: absolute;
  left: var(--x);
  top: var(--y);
  translate: -50% -50%;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  width: clamp(1.45rem, 8.1%, 4.2rem);
  aspect-ratio: 1;
  background: none;
  padding: 0;
  border: 0;
  border-radius: 45%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ornament img {
  width: 95%;
  height: 95%;
  object-fit: contain;
  filter: drop-shadow(0 3px 4px #160918b0);
  pointer-events: none;
}

.ornament > * {
  grid-area: 1 / 1;
  pointer-events: none;
  transition: filter .16s ease, scale .16s ease;
}

.ornament-tucked img {
  width: 82%;
  height: 82%;
  filter: brightness(.81) saturate(.9) drop-shadow(0 2px 3px #160918b0);
}

.ornament-tucked:not(.found)::before {
  content: "";
  position: absolute;
  z-index: 1;
  width: 108%;
  height: 47%;
  top: 62%;
  background: url("assets/choinka/galazka.webp") center / contain no-repeat;
  rotate: var(--branch-angle);
  pointer-events: none;
}

.ornament:focus-visible, .ornament:active { z-index: 1; }
.ornament:focus-visible > *, .ornament:active > * {
  scale: 1.15;
  filter: brightness(1.23) drop-shadow(0 0 .45rem #ffd27b);
}

@media (hover: hover) {
  .ornament:hover { z-index: 1; }
  .ornament:hover > * {
    scale: 1.16;
    filter: brightness(1.23) drop-shadow(0 0 .45rem #ffd27b);
  }
}

.classic-bauble {
  position: relative;
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 29% 24%, #fff8f1 0%, var(--bauble-color) 25%, #492039 85%);
  box-shadow: inset 0 0 0 1px #ffd9bf80, 0 .2rem .3rem #18091a9c;
}

.classic-bauble::before {
  content: "";
  position: absolute;
  width: 27%;
  height: 18%;
  left: 37%;
  bottom: 94%;
  border-radius: 30% 30% 0 0;
  background: linear-gradient(90deg, #a66330, #ffe2a0, #9d5436);
}

.classic-star {
  width: 61%;
  aspect-ratio: 1;
  background: linear-gradient(145deg, #fff4bf 20%, #eda449 55%, #a34a24);
  clip-path: polygon(50% 1%, 61% 36%, 98% 38%, 69% 59%, 79% 96%, 50% 73%, 21% 96%, 31% 59%, 2% 38%, 39% 36%);
}

.ornament.found { cursor: default; }

.ornament.found::after {
  content: "✓";
  display: grid;
  place-items: center;
  position: absolute;
  right: 0;
  top: 0;
  width: 1.1rem;
  aspect-ratio: 1;
  border-radius: 50%;
  color: #4b2031;
  background: #ffe4a8;
  box-shadow: 0 0 .6rem #ffcf87;
  font-size: .75rem;
  font-weight: 800;
}

.ornament.found img {
  filter: drop-shadow(0 0 .4rem #ffc475);
  animation: dog-found .45s ease-out;
}

@keyframes dog-found {
  45% { scale: 1.22; }
}

.tree-feedback {
  position: fixed;
  z-index: 2;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  white-space: nowrap;
  pointer-events: none;
}

.tree-finish {
  width: min(28rem, calc(100% - 2rem));
  border: 1px solid #ffc7979c;
  border-radius: 1.3rem;
  padding: 1.25rem;
  background: #46152f;
  color: #fff0eb;
  text-align: center;
  box-shadow: 0 .4rem 3rem #200416;
}

.tree-finish::backdrop { background: #1b0718b0; }
.tree-finish-star { color: #ffcf91; font-size: 2rem; margin: 0; }
.tree-finish h2 { font: normal 2rem Georgia, serif; margin: .3rem 0; }
.tree-finish-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; }
.tree-primary { background: #ffd2ad; color: #40152b; }
.tree-primary:hover { background: #ffe3c9; }

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

@media (min-width: 48rem) and (min-height: 32rem) {
  .tree-game { height: 100dvh; grid-template-rows: auto minmax(0, 1fr); }
  .tree-stage { container-type: size; }
  .tree-scene { width: min(100% - 1rem, 56rem, 96cqh); }
}

@media (max-width: 47.99rem) {
  .tree-header { grid-template-rows: 2.75rem auto; gap: .55rem .25rem; padding-inline: .75rem; }
  .tree-heading { grid-row: 2; grid-column: 1 / -1; }
  .tree-counter { grid-column: 2; grid-row: 1; margin-inline-end: 0; }
  .tree-counter, .tree-back { padding-inline: .45rem; font-size: .79rem; }
  .tree-page :is(.settings-toggle, .sound-toggle) { top: max(1rem, env(safe-area-inset-top)); }
}

@media (max-width: 40rem) and (orientation: portrait) {
  .tree-scene { aspect-ratio: 2 / 3; }
  .tree-art { mask-image: linear-gradient(transparent, #000 8%, #000 93%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  .ornament.found img { animation: none; }
  .ornament > * { transition: none; }
}
