:root {
  --ink: #252018;
  --paper: #fff7df;
  --panel: #fff1bf;
  --panel-deep: #ffd36b;
  --grass: #74c967;
  --grass-deep: #3f9346;
  --soil: #8b5936;
  --blue: #356caa;
  --red: #d04b3d;
  --line: #4a3826;
  --shadow: 0 0.55rem 0 #5b3c25;
  --pixel-font: "Trebuchet MS", Verdana, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: var(--pixel-font);
  background:
    linear-gradient(90deg, rgba(37, 32, 24, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(37, 32, 24, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, #9bdc7d 0%, #64b866 48%, #3f9346 100%);
  background-size: 18px 18px, 18px 18px, auto;
}

button,
a {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

img {
  display: block;
  image-rendering: pixelated;
}

.game-shell {
  display: grid;
  min-height: 100svh;
  grid-template-rows: auto 1fr;
  gap: 1rem;
  padding: clamp(0.75rem, 2vw, 1.25rem);
}

.game-topbar,
.tool-panel,
.status-panel,
.garden-scene,
.game-dialog {
  border: 4px solid var(--line);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.game-topbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem;
}

.player-panel {
  display: grid;
  min-width: min(100%, 25rem);
  gap: 0.45rem;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.1rem, 2vw, 1.6rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 0.55rem;
  font-size: 0.98rem;
}

.level-line,
.wallet,
.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.level-line span,
.wallet span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 1.8rem;
  padding: 0.2rem 0.45rem;
  border: 3px solid var(--line);
  background: #fffaf0;
}

.wallet img {
  width: 1.25rem;
  height: 1.25rem;
}

.xp-track {
  overflow: hidden;
  width: min(22rem, 100%);
  height: 1rem;
  border: 3px solid var(--line);
  background: #ead9a6;
}

.xp-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: repeating-linear-gradient(
    90deg,
    #6eb6ff 0 12px,
    #4b92de 12px 16px
  );
  transition: width 0.25s ease;
}

.top-actions {
  justify-content: flex-end;
}

.top-actions button,
.home-link,
.tool,
.shop-card button,
.primary-action {
  min-height: 2.75rem;
  border: 3px solid var(--line);
  background: var(--panel-deep);
  box-shadow: 0 0.25rem 0 #8e5d25;
  text-decoration: none;
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease;
}

.top-actions button,
.home-link {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
}

.top-actions button:active,
.home-link:active,
.tool:active,
.shop-card button:active,
.primary-action:active {
  transform: translateY(0.2rem);
  box-shadow: 0 0.05rem 0 #8e5d25;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(5.5rem, 7rem) minmax(18rem, 1fr) minmax(14rem, 19rem);
  gap: 1rem;
  min-height: 0;
}

.tool-panel,
.status-panel {
  align-self: start;
  padding: 0.7rem;
}

.tool-panel {
  display: grid;
  gap: 0.55rem;
}

.tool {
  display: grid;
  justify-items: center;
  gap: 0.2rem;
  min-height: 4.4rem;
  padding: 0.35rem;
}

.tool[disabled] {
  cursor: not-allowed;
  filter: grayscale(0.9);
  opacity: 0.55;
}

.tool.is-active {
  background: #8fe06a;
  box-shadow: inset 0 0 0 3px #fff6bd, 0 0.25rem 0 #4f762e;
}

.tool img,
.tool-icon {
  width: 2rem;
  height: 2rem;
}

.tool-icon {
  display: grid;
  place-items: center;
  border: 3px solid var(--line);
  background: #fff6bd;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1;
}

.garden-wrap {
  display: grid;
  min-width: 0;
  place-items: center;
}

.garden-scene {
  position: relative;
  display: grid;
  width: min(100%, 42rem);
  min-height: min(72svh, 42rem);
  align-content: center;
  justify-items: center;
  overflow: hidden;
  padding: clamp(1rem, 3vw, 2rem);
  background:
    linear-gradient(#8fd46f 0 17%, transparent 17%),
    linear-gradient(#5a635d 17% 27%, transparent 27%),
    linear-gradient(#e8d5a2 27% 32%, transparent 32%),
    linear-gradient(180deg, #79c762 31%, #56aa51 100%);
}

.road-row {
  position: absolute;
  top: 17%;
  left: 0;
  right: 0;
  height: 4.3rem;
  border: 4px solid var(--line);
  border-inline: 0;
  background:
    linear-gradient(180deg, #6a736d, #4f5853),
    repeating-linear-gradient(90deg, transparent 0 34px, rgba(255, 255, 255, 0.12) 34px 36px);
  overflow: hidden;
}

.school-building {
  position: absolute;
  top: calc(17% - 6.7rem);
  left: 50%;
  width: min(15rem, 48%);
  height: 7rem;
  object-fit: fill;
  transform: translateX(-50%);
  z-index: 1;
  filter: drop-shadow(0 5px 0 rgba(74, 56, 38, 0.35));
}

.lane-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  transform: translateY(-50%);
  background: repeating-linear-gradient(
    90deg,
    #f7e7a3 0 28px,
    transparent 28px 48px
  );
}

.school-bus {
  position: absolute;
  top: 0.65rem;
  left: -4rem;
  width: 4.2rem;
  height: 4.2rem;
  animation: bus-drive 18s linear infinite;
  z-index: 2;
}

.garden-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(4.8rem, 6.3rem));
  gap: clamp(0.35rem, 1vw, 0.65rem);
  margin-top: 5rem;
  padding: 0.7rem;
  border: 4px solid var(--line);
  background: #4d873e;
}

.plot {
  position: relative;
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  place-items: center;
  border: 3px solid var(--line);
  background: url("../img/garden-tycoon/tile-empty.svg") center / cover;
}

.plot[data-state="weed"] {
  background-image: url("../img/garden-tycoon/tile-weed.svg");
}

.plot[data-state="rock"] {
  background-image: url("../img/garden-tycoon/tile-rock.svg");
}

.plot:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 2px;
}

.plot-sprite {
  width: 66%;
  height: 66%;
  object-fit: contain;
  transform: translateY(-4%);
}

.plot[data-ready="true"]::after {
  content: "";
  position: absolute;
  top: 8%;
  right: 8%;
  width: 1.25rem;
  height: 1.25rem;
  border: 3px solid var(--line);
  background: url("../img/garden-tycoon/coin.svg") center / cover #fff6bd;
  animation: bob 0.9s steps(2, end) infinite;
}

.water-meter {
  position: absolute;
  left: 9%;
  right: 9%;
  bottom: 8%;
  height: 0.45rem;
  border: 2px solid var(--line);
  background: #e8d39e;
}

.clear-meter {
  position: absolute;
  left: 9%;
  right: 9%;
  bottom: 8%;
  height: 0.55rem;
  border: 2px solid var(--line);
  background: #ead9a6;
}

.clear-meter span {
  display: block;
  height: 100%;
  background: #ffcf5b;
}

.water-meter span {
  display: block;
  height: 100%;
  background: #52a8e8;
}

.pet-layer,
.float-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.pet {
  position: absolute;
  width: 2.8rem;
  height: 2.8rem;
  image-rendering: pixelated;
  transition:
    left 1.4s linear,
    top 1.4s linear;
}

.float-text {
  position: absolute;
  z-index: 5;
  min-width: max-content;
  color: #fff7df;
  font-weight: 800;
  text-shadow:
    2px 0 var(--line),
    -2px 0 var(--line),
    0 2px var(--line),
    0 -2px var(--line);
  animation: float-up 1.25s ease-out forwards;
}

.status-panel {
  display: grid;
  gap: 1rem;
  max-height: calc(100svh - 8rem);
  overflow: auto;
  background: var(--panel);
}

.plain-list {
  display: grid;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.plain-list li {
  padding: 0.45rem;
  border: 3px solid var(--line);
  background: #fff9df;
  font-size: 0.9rem;
}

.plain-list li.is-done {
  background: #b9ef95;
}

.game-dialog {
  width: min(42rem, calc(100vw - 2rem));
  max-height: calc(100svh - 2rem);
  padding: 1rem;
}

.game-dialog::backdrop {
  background: rgba(32, 26, 15, 0.45);
}

.dialog-close {
  float: right;
  width: 2.2rem;
  height: 2.2rem;
  border: 3px solid var(--line);
  background: #ff8d72;
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1;
}

.dialog-grid,
.shop-grid {
  display: grid;
  gap: 0.75rem;
}

.shop-grid {
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

.shop-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.shop-tab {
  min-height: 2.35rem;
  padding: 0.25rem 0.65rem;
  border: 3px solid var(--line);
  background: #fff6bd;
  box-shadow: 0 0.2rem 0 #8e5d25;
}

.shop-tab.is-active {
  background: #8fe06a;
  box-shadow: inset 0 0 0 3px #fff6bd, 0 0.2rem 0 #4f762e;
}

.shop-card {
  display: grid;
  gap: 0.55rem;
  padding: 0.7rem;
  border: 3px solid var(--line);
  background: #fff9df;
}

.shop-card h3 {
  margin: 0;
  font-size: 1rem;
}

.shop-card p {
  font-size: 0.9rem;
  line-height: 1.35;
}

.shop-card button,
.primary-action {
  padding: 0.35rem 0.6rem;
}

.shop-card.is-locked {
  color: #6b6254;
  background: repeating-linear-gradient(45deg, #eee0b7 0 10px, #e2d09c 10px 20px);
}

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

@keyframes bus-drive {
  0%,
  72% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(calc(100vw + 8rem));
  }
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translateY(0);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-3rem);
  }
}

@media (max-width: 58rem) {
  .game-topbar,
  .play-area {
    grid-template-columns: 1fr;
  }

  .game-topbar {
    display: grid;
  }

  .tool-panel {
    grid-row: 2;
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .garden-wrap {
    grid-row: 1;
  }

  .status-panel {
    grid-row: 3;
    max-height: none;
  }
}

@media (max-width: 38rem) {
  .game-shell {
    padding: 0.55rem;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .top-actions button,
  .home-link {
    justify-content: center;
  }

  .garden-scene {
    min-height: 28rem;
    padding-inline: 0.55rem;
  }

  .garden-grid {
    grid-template-columns: repeat(var(--cols), minmax(3.9rem, 1fr));
    width: 100%;
  }

  .tool {
    min-height: 3.9rem;
    font-size: 0.78rem;
  }
}
