:root {
  --bg: #17240f;
  --panel: rgba(28, 43, 21, 0.9);
  --panel-strong: rgba(46, 59, 28, 0.94);
  --line: rgba(244, 241, 208, 0.22);
  --text: #fffbea;
  --muted: #d9dfb7;
  --leaf: #78c850;
  --berry: #e85561;
  --gold: #f6c35b;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(130deg, rgba(232, 85, 97, 0.16), transparent 34%),
    linear-gradient(230deg, rgba(246, 195, 91, 0.16), transparent 38%),
    linear-gradient(180deg, #254115 0%, #17240f 62%, #111a0c 100%);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

body { display: flex; justify-content: center; }

.wrap {
  width: min(980px, 100vw);
  padding: 12px;
}

.topbar,
.stat,
.controls {
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(14px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 13px 14px;
  background: linear-gradient(180deg, rgba(45, 67, 25, 0.95), rgba(25, 39, 17, 0.95));
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2.1rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar p {
  margin: 6px 0 0;
  max-width: 58ch;
  color: var(--muted);
  font-size: 0.95rem;
}

.topbar-actions,
.control-actions {
  display: flex;
  gap: 8px;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  color: #fffdf4;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, opacity 120ms ease;
}

button:hover { transform: translateY(-1px); filter: brightness(1.04); }
button:active { transform: translateY(0); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

#shuffleBtn { padding: 10px 14px; background: linear-gradient(135deg, #e85561, #bb3e56); }
#restartBtn { padding: 10px 14px; background: linear-gradient(135deg, #69b84a, #2e7d32); }
#undoBtn { padding: 10px 14px; background: linear-gradient(135deg, #4f8fe8, #315aa8); }
#rewardBtn { padding: 10px 14px; background: linear-gradient(135deg, #f2b84b, #c96f24); }
#rewardBtn span { color: #fff7cf; font-weight: 950; white-space: nowrap; }

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 9px 10px;
  background: var(--panel);
}

.stat span {
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.stat strong { font-size: 1.02rem; text-align: right; }

.stage-shell {
  width: min(100%, 620px);
  margin: 0 auto;
  aspect-ratio: 9 / 14;
  border: 1px solid rgba(244, 241, 208, 0.28);
  border-radius: 8px;
  overflow: hidden;
  background: #4d8e37;
  box-shadow: 0 24px 60px rgba(7, 12, 5, 0.4);
  touch-action: none;
}

#game-stage,
#game-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding: 11px 12px;
  background: var(--panel-strong);
}

#message {
  margin: 0;
  font-weight: 750;
  color: var(--text);
}

@media (max-width: 720px) {
  .topbar,
  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions,
  .control-actions {
    width: 100%;
  }

  .topbar-actions button,
  .control-actions button {
    flex: 1 1 0;
  }

  .hud { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-shell { width: min(100%, 520px); }
}
