:root {
  --sky: #cde7ee;
  --meadow: #93c572;
  --meadow-deep: #6fa556;
  --ink: #24482f;
  --ink-soft: #4f6b55;
  --barn: #b9382f;
  --barn-dark: #8f2a23;
  --straw: #f3d27c;
  --straw-dark: #d9ae3f;
  --soil: #7b4f33;
  --soil-light: #9c6a47;
  --sheet: #f7fbf5;
  --line: #d7e4d2;
  --food: #e39b3b;
  --clean: #4fa3c7;
  --sad: #8d9a8f;

  --dock-h: 132px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.35;
  color: var(--ink);
  background: var(--meadow);
  min-height: 100dvh;
  padding-bottom: calc(var(--dock-h) + var(--safe-b));
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; touch-action: manipulation; }

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

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

/* ---------- sky ---------- */

.sky {
  background: var(--sky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 22px;
  border-bottom-left-radius: 50% 18px;
  border-bottom-right-radius: 50% 18px;
  position: relative;
  z-index: 1;
}

.title {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.01em;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: default;
}

.purse {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 999px;
  padding: 6px 14px 6px 8px;
  font-weight: 800;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 0 var(--straw-dark);
}

.coin {
  width: 24px; height: 24px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3c4 0 18%, var(--straw) 19% 62%, var(--straw-dark) 63%);
  box-shadow: inset 0 0 0 2px var(--straw-dark);
}

.purse.bump { animation: bump .35s ease-out; }
@keyframes bump { 40% { transform: scale(1.12); } }

/* ---------- meadow & animals ---------- */

.meadow {
  position: relative;
  padding: 18px 16px 22px;
  margin-top: -12px;
  padding-top: 30px;
}

.decor {
  display: flex;
  justify-content: space-between;
  align-items: end;
  min-height: 0;
  font-size: 26px;
  line-height: 1;
  pointer-events: none;
}
.decor:not(:empty) { margin-bottom: 10px; }
.decor .flowers { letter-spacing: -4px; }
.decor .pond {
  display: inline-flex; align-items: center; justify-content: center;
  width: 92px; height: 36px; border-radius: 50%;
  background: #7fc3dc; box-shadow: inset 0 -4px 0 #5aa8c5; font-size: 20px;
}

.animals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.animal {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 14px 10px 12px;
  border: 0;
  border-radius: 22px;
  background: rgba(255, 255, 255, .28);
  cursor: pointer;
  text-align: center;
  min-height: 168px;
}
.animal:active { background: rgba(255, 255, 255, .45); }

.critter {
  position: relative;
  font-size: 64px;
  line-height: 1;
  display: inline-block;
  transform-origin: 50% 100%;
  animation: graze 3.2s ease-in-out infinite;
}
.animal:nth-child(2n) .critter { animation-delay: -1.1s; animation-duration: 3.7s; }
.animal:nth-child(3n) .critter { animation-delay: -2s; }

@keyframes graze {
  0%, 100% { transform: translateY(0) rotate(0); }
  45% { transform: translateY(-3px) rotate(-2deg); }
  55% { transform: translateY(-3px) rotate(1.5deg); }
}

.acc {
  position: absolute;
  font-size: 26px;
  top: -8px;
  right: -10px;
}

.animal-name { font-weight: 800; font-size: 18px; }

.meters { display: grid; gap: 4px; width: 100%; max-width: 132px; }
.meter {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}
.bar {
  height: 8px;
  border-radius: 99px;
  background: rgba(36, 72, 47, .18);
  overflow: hidden;
}
.bar > i { display: block; height: 100%; border-radius: inherit; transition: width .4s; }
.meter.food i, .bar.food i { background: var(--food); }
.meter.clean i, .bar.clean i { background: var(--clean); }
.meter.low i, .bar.low i { background: var(--barn); }

.animal-status { font-size: 14px; color: var(--ink-soft); min-height: 1.35em; font-variant-numeric: tabular-nums; }

.badge {
  position: absolute;
  top: 8px;
  left: 8px;
  min-width: 34px;
  padding: 3px 8px;
  border-radius: 99px;
  background: #fff;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 2px 0 rgba(36, 72, 47, .25);
  animation: pop .5s ease-out;
}
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.1); } }

/* unhappy: no production, droopy and grey, but nothing worse */
.animal.sad .critter { animation: none; filter: grayscale(.85) opacity(.8); transform: rotate(6deg) translateY(4px); }
.animal.sad .critter::after {
  content: "💧";
  position: absolute;
  left: -6px; top: 10px;
  font-size: 18px;
  animation: drip 2.4s ease-in infinite;
}
@keyframes drip { 0% { opacity: 0; transform: translateY(-4px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translateY(16px); } }
.animal.sad .animal-status { color: var(--barn-dark); font-weight: 700; }

.animal.empty-slot {
  border: 2px dashed rgba(36, 72, 47, .3);
  background: transparent;
  color: var(--ink-soft);
  align-content: center;
  font-weight: 700;
}

/* ---------- field ---------- */

.field {
  background: var(--meadow-deep);
  padding: 18px 16px 22px;
  border-top-left-radius: 50% 16px;
  border-top-right-radius: 50% 16px;
}

.plots {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.plot {
  aspect-ratio: 1;
  border: 0;
  border-radius: 16px;
  background:
    repeating-linear-gradient(0deg, transparent 0 11px, rgba(0, 0, 0, .08) 11px 13px),
    var(--soil);
  color: #fff;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  padding: 6px;
}
.plot:active { filter: brightness(1.1); }
.plot .crop { font-size: 32px; line-height: 1; transition: transform .3s; }
.plot.growing .crop { transform: scale(.6); opacity: .85; }
.plot.ready .crop { font-size: 40px; animation: ready 1.4s ease-in-out infinite; }
@keyframes ready { 50% { transform: translateY(-4px) scale(1.06); } }
.plot .label { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.plot.empty .label { font-size: 15px; opacity: .9; }
.plot .grow {
  position: absolute; left: 8px; right: 8px; bottom: 8px;
  height: 6px; border-radius: 99px; background: rgba(255, 255, 255, .25); overflow: hidden;
}
.plot .grow > i { display: block; height: 100%; background: var(--straw); border-radius: inherit; }
.plot.locked {
  background: transparent;
  border: 2px dashed rgba(36, 72, 47, .35);
  color: var(--ink);
}
.plot.locked .crop { font-size: 22px; opacity: .6; }

/* ---------- dock ---------- */

.dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 5;
  background: var(--sheet);
  padding: 10px 16px calc(12px + var(--safe-b));
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  box-shadow: 0 -2px 0 rgba(36, 72, 47, .12);
  display: grid;
  gap: 10px;
}

.inventory {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  min-height: 34px;
}
.inventory::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 99px;
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.chip.zero { opacity: .45; }

.shop-btn, .btn {
  border: 0;
  border-radius: 16px;
  min-height: 52px;
  padding: 12px 18px;
  font-weight: 800;
  font-size: 18px;
  cursor: pointer;
}
.shop-btn {
  background: var(--barn);
  color: #fff;
  box-shadow: 0 4px 0 var(--barn-dark);
}
.shop-btn:active, .btn:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }

/* ---------- sheet ---------- */

.scrim {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(36, 72, 47, .45);
}

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 11;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--sheet);
  border-top-left-radius: 26px;
  border-top-right-radius: 26px;
  padding: 8px 16px calc(20px + var(--safe-b));
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }

@media (min-width: 560px) {
  .sheet, .dock { left: 50%; right: auto; width: 520px; transform: translateX(-50%); }
  .sheet { animation: none; }
  main, .sky { max-width: 520px; margin-left: auto; margin-right: auto; }
}

.sheet-grip { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }

.sheet h2 { margin: 0 0 4px; font-size: 24px; font-weight: 800; }
.sheet h3 { margin: 22px 0 8px; font-size: 17px; font-weight: 800; }
.sheet p { margin: 0 0 10px; color: var(--ink-soft); }
.sheet .lede { font-size: 16px; }

.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-head .big { font-size: 52px; line-height: 1; position: relative; }
.sheet-head .big .acc { font-size: 22px; top: -6px; right: -12px; }

.row-list { display: grid; gap: 8px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 2px solid var(--line);
  min-height: 60px;
  font-size: 17px;
}
.btn .what { display: flex; align-items: center; gap: 10px; }
.btn .em { font-size: 28px; line-height: 1; }
.btn small { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.btn .price { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.btn .price .coin { width: 18px; height: 18px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--barn); border-color: var(--barn); color: #fff; box-shadow: 0 4px 0 var(--barn-dark); }
.btn.primary small { color: rgba(255, 255, 255, .85); }
.btn.go { background: var(--straw); border-color: var(--straw-dark); box-shadow: 0 4px 0 var(--straw-dark); }
.btn.center { justify-content: center; text-align: center; }
.btn.owned { background: transparent; border-style: dashed; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid-3 .btn, .grid-2 .btn { flex-direction: column; justify-content: center; text-align: center; gap: 4px; padding: 10px 6px; }

.sheet-meters { display: grid; gap: 10px; margin: 16px 0 4px; }
.sheet-meter { display: grid; grid-template-columns: 70px 1fr auto; align-items: center; gap: 10px; font-weight: 700; }
.sheet-meter .bar { height: 12px; }
.sheet-meter .when { font-size: 14px; color: var(--ink-soft); font-weight: 600; min-width: 92px; text-align: right; font-variant-numeric: tabular-nums; }

.away-list { list-style: none; padding: 0; margin: 14px 0 18px; display: grid; gap: 10px; }
.away-list li { display: flex; gap: 12px; align-items: center; background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 10px 12px; }
.away-list .em { font-size: 30px; line-height: 1; flex: none; width: 36px; text-align: center; }

/* stats */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.stat { background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.days { display: grid; gap: 4px; margin-bottom: 14px; }
.day { display: grid; grid-template-columns: 82px 1fr 26px; gap: 8px; align-items: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.day .bar { height: 10px; }
.day .bar i { background: var(--ink); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + var(--safe-b) + 12px);
  transform: translate(-50%, 20px);
  z-index: 20;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 99px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.storage-warn {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30; margin: 0;
  background: var(--barn); color: #fff; font-size: 14px; padding: 8px 16px; text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
