.forest-grid {
  --rows: 8;
  --columns: 12;
  position: absolute;
  inset: clamp(16px, 3vw, 44px);
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  align-items: end;
  overflow: visible;
}

.forest-cell {
  position: relative;
  display: grid;
  place-items: end center;
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 30%;
  color: inherit;
  background: transparent;
  overflow: visible;
  -webkit-tap-highlight-color: transparent;
}

button.forest-cell {
  cursor: pointer;
  touch-action: manipulation;
}

button.forest-cell:disabled {
  cursor: default;
}

.tree-visual {
  position: absolute;
  left: 50%;
  bottom: -3%;
  display: block;
  width: min(108%, 110px);
  aspect-ratio: 1 / 1.1;
  transform: translateX(-50%);
  transform-origin: 50% 100%;
  transition: transform 180ms ease, filter 180ms ease, opacity 180ms ease;
  pointer-events: none;
}

.tree-art {
  width: 100%;
  height: 100%;
  overflow: visible;
  transform-origin: 50% 92%;
}

.tree-shadow {
  fill: rgba(9, 39, 20, 0.22);
}

.seedling-art,
.sapling-art,
.grown-art,
.stump-art {
  display: none;
}

.is-stump .stump-art,
.is-tree.stage-0 .seedling-art,
.is-tree.stage-1 .sapling-art,
.is-tree.stage-2 .grown-art,
.is-tree.stage-3 .grown-art,
.is-tree.stage-4 .grown-art {
  display: block;
}

.is-empty .tree-visual {
  opacity: 0;
  transform: translateX(-50%) scale(0.5);
}

.is-stump .tree-visual {
  width: min(72%, 72px);
  opacity: 0.86;
}

.stage-0 .tree-visual {
  width: min(52%, 54px);
}

.stage-1 .tree-visual {
  width: min(72%, 70px);
}

.stage-2 .tree-visual {
  width: min(98%, 94px);
}

.stage-3 .tree-visual {
  width: min(124%, 124px);
}

.stage-4 .tree-visual {
  width: min(154%, 154px);
  bottom: -5%;
}

.stem,
.branch {
  fill: none;
  stroke: #6b4221;
  stroke-width: 5;
  stroke-linecap: round;
}

.leaf {
  fill: #65ad42;
  stroke: #377b32;
  stroke-width: 1.4;
}

.trunk-shadow,
.stump-side {
  fill: #5b371d;
}

.trunk,
.sapling-trunk {
  fill: #8c572d;
}

.branch-left,
.branch-right,
.sapling-art .branch {
  stroke: #714522;
  stroke-width: 7;
}

.leaf-dark {
  fill: #286f38;
}

.leaf-mid {
  fill: #3f8d3f;
}

.leaf-light {
  fill: #67aa45;
}

.stump-top {
  fill: #b8793e;
}

.stump-ring {
  fill: none;
  stroke: #75451f;
  stroke-width: 2;
}

.stump-root {
  fill: none;
  stroke: #5b371d;
  stroke-width: 7;
  stroke-linecap: round;
}

.stage-2 .crown-mature,
.stage-2 .crown-ancient,
.stage-3 .crown-young,
.stage-3 .crown-ancient,
.stage-4 .crown-young,
.stage-4 .crown-mature {
  display: none;
}

.stage-3 .crown-mature,
.stage-4 .crown-ancient {
  display: block;
}

.is-tree:not(.is-claimed) .tree-art {
  animation: tree-breathe 2.7s ease-in-out var(--sway-delay) infinite alternate;
}

button.forest-cell.is-tree:not(:disabled):hover .tree-visual,
button.forest-cell.is-tree:focus-visible .tree-visual {
  filter: brightness(1.08) drop-shadow(0 6px 5px rgba(10, 37, 18, 0.2));
  transform: translateX(-50%) translateY(-5px) scale(1.035);
}

button.forest-cell:focus-visible {
  outline: 3px solid rgba(255, 218, 116, 0.95);
  outline-offset: -4px;
}

.is-claimed .tree-art {
  animation: tree-chop 150ms ease-in-out infinite alternate;
}

.wood-chip {
  position: absolute;
  left: 50%;
  bottom: 14%;
  width: 6px;
  height: 3px;
  border-radius: 60% 10%;
  background: #dfaf66;
  opacity: 0;
}

.is-claimed .wood-chip {
  animation: chip-fly 520ms ease-out infinite;
}

.is-claimed .chip-two {
  animation-delay: 170ms;
}

.is-claimed .chip-three {
  animation-delay: 340ms;
}

.cut-meter {
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: 3%;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(13, 45, 24, 0.42);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.34);
  opacity: 0;
}

.cut-meter i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: #ffd978;
  transform-origin: left center;
  animation-name: cut-fill;
  animation-timing-function: linear;
  animation-fill-mode: both;
}

.is-claimed .cut-meter {
  opacity: 1;
}

.is-own-claim .cut-meter {
  height: 7px;
  background: rgba(12, 34, 20, 0.68);
  box-shadow: 0 0 0 2px rgba(255, 239, 181, 0.7);
}

.forest-grid[data-paused="true"] .tree-art,
.forest-grid[data-paused="true"] .wood-chip,
.forest-grid[data-paused="true"] .cut-meter i {
  animation-play-state: paused !important;
}

@keyframes tree-breathe {
  from { transform: rotate(-0.7deg) translateY(0); }
  to { transform: rotate(0.8deg) translateY(-1px); }
}

@keyframes tree-chop {
  from { transform: rotate(-2.5deg); }
  to { transform: rotate(2.5deg); }
}

@keyframes chip-fly {
  0% { opacity: 0; transform: translate(0, 0) rotate(0); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(24px, -18px) rotate(140deg); }
}

@keyframes cut-fill {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@media (prefers-reduced-motion: reduce) {
  .tree-art,
  .wood-chip,
  .cut-meter i {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }
}
