:root {
  --bg: #fbf1dc;
  --panel: #fffaf0;
  --ink: #3b2a1a;
  --muted: #8a6f55;
  --line: #e6d3b3;
  --wood-dark: #5a3518;
  --wood: #8b5a2b;
  --wood-light: #b77b3e;
  --accent: #e8893a;
  --accent-dark: #c9681f;
  --error: #c2412d;
  --pixel: "Press Start 2P", monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

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

/* Layout */
.app {
  position: relative;
  max-width: 640px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Decorative pixel corners */
.corners span {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 4px double var(--wood-light);
  pointer-events: none;
}

.corners span:nth-child(1) { top: 6px; left: 6px; border-right: 0; border-bottom: 0; }
.corners span:nth-child(2) { top: 6px; right: 6px; border-left: 0; border-bottom: 0; }
.corners span:nth-child(3) { bottom: 6px; left: 6px; border-right: 0; border-top: 0; }
.corners span:nth-child(4) { bottom: 6px; right: 6px; border-left: 0; border-top: 0; }

.top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  font-family: var(--pixel);
  font-size: 1.35rem;
  font-weight: 400;
  color: var(--accent-dark);
  text-shadow: 2px 2px 0 #f3d2a8;
  margin-right: auto;
}

.stats {
  display: flex;
  background: var(--panel);
  border: 3px solid var(--wood-light);
  outline: 2px solid var(--panel);
  box-shadow: 0 0 0 5px var(--wood-light);
  border-radius: 4px;
  margin: 5px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 3px 10px;
}

.stat + .stat {
  border-left: 2px dashed var(--line);
}

/* Pixel-style coin */
.coin {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 4px;
  vertical-align: -1px;
  background: #ffd23f;
  border: 2px solid #b8860b;
  border-radius: 50%;
  box-shadow: inset -2px -2px 0 #e9a700, inset 2px 2px 0 #fff3a8;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
}

.icon-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: var(--accent);
  border: 3px solid var(--wood-dark);
  box-shadow: inset 0 0 0 3px var(--wood-light), 0 4px 0 var(--wood-dark);
  border-radius: 6px;
}

.icon-button:active {
  transform: translateY(2px);
  box-shadow: inset 0 0 0 3px var(--wood-light), 0 2px 0 var(--wood-dark);
}

.icon {
  width: 24px;
  height: 24px;
  fill: #fff4e0;
  stroke: var(--wood-dark);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon .wave {
  fill: none;
  stroke: #fff4e0;
  stroke-width: 2.5;
}

.icon-muted,
.icon-button[aria-pressed="true"] .icon-sound {
  display: none;
}

.icon-button[aria-pressed="true"] .icon-muted {
  display: block;
}

/* Play area */
.stage {
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
}

.yard {
  position: relative;
  border: 4px solid var(--wood-dark);
  border-radius: 14px;
  overflow: hidden;
  background: #6f9a4a;
  box-shadow: 0 8px 20px rgba(90, 53, 24, 0.25);
}

#yard-canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: manipulation;
  cursor: pointer;
}

.hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 7px 14px;
  background: #fffaf0;
  border: 3px solid var(--ink);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 3px 0 rgba(59, 42, 26, 0.35);
}

/* Speech-bubble tail */
.hint::after {
  content: "";
  position: absolute;
  bottom: -9px;
  left: 50%;
  width: 12px;
  height: 12px;
  background: #fffaf0;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: translateX(-50%) rotate(45deg);
}

.hint:empty {
  display: none;
}

.floaters {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.floater {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  font-size: 1.4rem;
  font-weight: 800;
  color: #ffe27a;
  -webkit-text-stroke: 1.5px var(--wood-dark);
  text-shadow: 0 3px 0 var(--wood-dark);
  animation: float-up 1.4s ease-out forwards;
}

@keyframes float-up {
  from { opacity: 1; transform: translate(-50%, 0) scale(0.9); }
  20% { transform: translate(-50%, -10px) scale(1.1); }
  to { opacity: 0; transform: translate(-50%, -60px) scale(1); }
}

/* Growth progress */
.growth {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--panel);
  border: 3px solid var(--wood-light);
  border-radius: 10px;
  padding: 10px 14px;
}

.growth-text {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.growth-text strong {
  font-size: 1rem;
}

.growth-text span {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.growth-bar {
  height: 14px;
  background: #efe2c8;
  border: 2px solid var(--wood-dark);
  border-radius: 999px;
  overflow: hidden;
}

.growth-fill {
  height: 100%;
  width: 0;
  background: repeating-linear-gradient(-45deg, #8fd16a 0 8px, #7cc05a 8px 16px);
  transition: width 0.6s ease-out;
}

/* Wooden buttons */
.actions {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
}

.save-button,
.shop-button,
.primary-button {
  position: relative;
  background: var(--accent);
  color: #fff;
  border: 4px solid var(--wood-dark);
  border-radius: 8px;
  font-weight: 800;
  text-shadow: 0 2px 0 var(--accent-dark);
  box-shadow:
    inset 0 0 0 4px var(--wood-light),
    inset 0 -6px 0 4px rgba(0, 0, 0, 0.08),
    0 6px 0 var(--wood-dark);
  transition: transform 0.08s, box-shadow 0.08s;
}

.save-button,
.shop-button {
  padding: 20px 10px;
  font-size: 1.35rem;
}

.shop-button {
  background: #5fa34a;
  text-shadow: 0 2px 0 #3f7a32;
}

.save-button:hover,
.shop-button:hover,
.primary-button:hover {
  filter: brightness(1.05);
}

.save-button:active,
.shop-button:active,
.primary-button:active {
  transform: translateY(4px);
  box-shadow:
    inset 0 0 0 4px var(--wood-light),
    0 2px 0 var(--wood-dark);
}

.primary-button {
  padding: 10px 22px;
  font-size: 1rem;
}

.text-button {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 8px;
}

.footer {
  text-align: center;
}

/* Dialog */
dialog {
  width: min(92vw, 380px);
  margin: auto;
  border: 4px solid var(--wood-dark);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: inset 0 0 0 4px var(--wood-light);
  padding: 24px;
}

dialog::backdrop {
  background: rgba(59, 42, 26, 0.5);
}

dialog form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

dialog h2 {
  font-size: 1.2rem;
}

dialog label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

dialog select {
  padding: 10px 12px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 1rem;
}

dialog input {
  padding: 12px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 1.2rem;
}

dialog input[aria-invalid="true"] {
  border-color: var(--error);
}

.error {
  color: var(--error);
  font-size: 0.85rem;
  min-height: 1.2em;
}

.quick-amounts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.quick-amounts button {
  padding: 8px 0;
  background: #fff;
  border: 3px solid var(--line);
  border-radius: 8px;
  font-weight: 700;
}

.quick-amounts button:hover {
  border-color: var(--wood-light);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.floater-coins {
  top: 42%;
  font-size: 1.1rem;
  color: #ffd23f;
}

/* Shop */
.shop-dialog {
  width: min(94vw, 440px);
  max-height: 88vh;
  overflow-y: auto;
}

.shop-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.shop-head h2 {
  margin-right: auto;
}

.shop-balance {
  font-weight: 800;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
}

.close-button {
  width: 36px;
  height: 36px;
  border: 3px solid var(--wood-dark);
  border-radius: 6px;
  background: var(--panel);
  font-size: 1.3rem;
  line-height: 1;
}

.shop-message {
  min-height: 1.4em;
  margin: 6px 0 2px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--error);
}

.shop-section {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 8px 0 6px;
}

.shop-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 3px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.shop-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.shop-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.shop-info span {
  font-size: 0.82rem;
  color: var(--muted);
}

.buy-button {
  min-width: 72px;
  padding: 8px 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  border: 3px solid var(--wood-dark);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--wood-dark);
  white-space: nowrap;
}

.buy-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--wood-dark);
}

.shop-item.locked {
  background: #f4ede0;
}

.shop-item.locked .shop-icon {
  filter: grayscale(1) opacity(0.5);
}

.shop-item.locked .buy-button {
  background: #b9ab96;
}

/* Small phones */
@media (max-width: 420px) {
  .app {
    padding: 20px 14px;
  }

  .logo {
    font-size: 1rem;
  }

  .stat {
    padding: 2px 7px;
  }

  .stat-value {
    font-size: 0.9rem;
  }

  .save-button,
  .shop-button {
    font-size: 1.1rem;
    padding: 16px 8px;
  }
}

.floater-grow {
  top: 18%;
  font-size: 1.2rem;
  white-space: nowrap;
  animation-duration: 2.4s;
}

/* Goals */
.goals {
  background: var(--panel);
  border: 3px solid var(--wood-light);
  border-radius: 10px;
  padding: 12px 14px 14px;
}

.goals-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.goals-head h2 {
  font-size: 1.05rem;
}

.small-button {
  padding: 6px 12px;
  background: #5fa34a;
  color: #fff;
  font-weight: 800;
  border: 3px solid var(--wood-dark);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--wood-dark);
}

.small-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--wood-dark);
}

.goals-empty {
  font-size: 0.9rem;
  color: var(--muted);
}

.goal-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.goal-card {
  background: #fff;
  border: 3px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.goal-card.done {
  border-color: #8fd16a;
  background: #f3fbe9;
}

.goal-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.goal-head strong {
  margin-right: auto;
  overflow-wrap: anywhere;
}

.goal-badge {
  font-size: 0.75rem;
  font-weight: 800;
  color: #2f6b1f;
  background: #d6f0c2;
  border-radius: 999px;
  padding: 1px 8px;
}

.goal-delete {
  width: 28px;
  height: 28px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  line-height: 1;
}

.goal-amounts {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  margin: 2px 0 6px;
}

.goal-bar {
  position: relative;
  height: 14px;
  background: #efe2c8;
  border: 2px solid var(--wood-dark);
  border-radius: 999px;
  overflow: hidden;
}

.goal-fill {
  height: 100%;
  background: repeating-linear-gradient(-45deg, #f2b45a 0 8px, #e8a040 8px 16px);
  transition: width 0.6s ease-out;
}

.goal-card.done .goal-fill {
  background: repeating-linear-gradient(-45deg, #8fd16a 0 8px, #7cc05a 8px 16px);
}

.goal-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(90, 53, 24, 0.45);
}

.goal-tick.reached {
  background: #fffaf0;
}

.goal-next {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.dialog-note {
  font-size: 0.9rem;
  color: var(--muted);
}

/* Reward card */
.reward-dialog {
  text-align: center;
}

.reward-star {
  font-size: 2.6rem;
  line-height: 1;
  color: #ffd23f;
  -webkit-text-stroke: 2px var(--wood-dark);
}

.reward-dialog h2 {
  margin: 6px 0 10px;
}

.reward-lines {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.reward-lines li {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-weight: 600;
}
