:root {
  --bg: #f4ecd8;
  --panel: #fff7eb;
  --panel-strong: #fffaf1;
  --line: #d8cbb3;
  --ink: #244631;
  --text: #4d584f;
  --muted: #6f786f;
  --green: #5f8b52;
  --green-dark: #2f5a3d;
  --green-soft: #dceec8;
  --green-soft-2: #eef8e0;
  --accent: #f6c67a;
  --danger: #895147;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow: 0 10px 0 rgba(82, 73, 48, .06), 0 0 0 3px rgba(255,255,255,.38) inset;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, #fcf7ea 0%, #f5ecd8 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }

.app {
  width: min(100%, 480px);
  height: 100dvh;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 14px calc(12px + var(--safe-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1.45fr) auto auto auto auto;
  gap: 10px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .14em;
  color: var(--green);
}

h1 {
  margin: 0;
  font-size: clamp(24px, 6vw, 30px);
  line-height: 1;
  color: var(--ink);
}

.device-note {
  margin: 2px 0 0;
  max-width: 112px;
  text-align: right;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.plant-panel,
.status-card,
.goal-card,
.controls,
.reset-btn {
  border: 3px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.plant-panel {
  position: relative;
  overflow: hidden;
  padding: 8px;
  display: grid;
  place-items: center;
  min-height: 0;
}

.sky {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, #eef8df 0%, #f9f2e3 100%);
}

.sky::before,
.sky::after {
  content: "";
  position: absolute;
  background: rgba(255,255,255,.42);
  image-rendering: pixelated;
}

.sky::before {
  width: 52px;
  height: 16px;
  top: 18px;
  left: 24px;
  box-shadow:
    8px 0 0 rgba(255,255,255,.42),
    16px 0 0 rgba(255,255,255,.42),
    8px -8px 0 rgba(255,255,255,.42);
}

.sky::after {
  width: 40px;
  height: 16px;
  top: 34px;
  right: 26px;
  box-shadow:
    8px 0 0 rgba(255,255,255,.42),
    16px 0 0 rgba(255,255,255,.42),
    8px -8px 0 rgba(255,255,255,.42);
}

.plant-stage {
  position: relative;
  z-index: 1;
  width: min(60vw, 220px);
  aspect-ratio: 6 / 7;
  display: grid;
  place-items: center;
  image-rendering: pixelated;
}

.plant-stage svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.plant-sprite {
  transform-origin: 50% 80%;
  animation: bob 1.8s steps(2, end) infinite;
}

.sparkle {
  animation: twinkle 1.5s steps(2, end) infinite;
}

.sparkle-b { animation-delay: .65s; }

.status-card {
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}

.label {
  margin: 0 0 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  font-weight: 800;
}

.count-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  line-height: 1;
}

.count-row > span {
  font-size: clamp(44px, 12vw, 64px);
  color: var(--ink);
  font-weight: 800;
}

.count-row small {
  color: var(--ink);
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 700;
}

.stage-label {
  margin: 4px 0 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--green-dark);
}

.progress-block {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.progress-track {
  height: 18px;
  border-radius: 999px;
  border: 3px solid #d9ceb6;
  overflow: hidden;
  background: #f3ecdf;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: repeating-linear-gradient(
    90deg,
    var(--green-soft) 0 10px,
    var(--green) 10px 20px
  );
  transition: width .18s linear;
}

.progress-block strong {
  min-width: 46px;
  text-align: right;
  font-size: 18px;
  color: var(--green-dark);
}

.goal-card {
  padding: 10px 12px;
}

.goal-card label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.goal-row {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
}

input {
  width: 100%;
  min-height: 46px;
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 0 12px;
  background: var(--panel-strong);
  color: var(--ink);
  font-size: 21px;
  font-weight: 800;
  outline: none;
}

input:focus {
  border-color: #91bc6c;
}

.goal-row button,
.control-btn,
.reset-btn {
  border: 0;
  border-radius: 14px;
  font-weight: 800;
}

.goal-row button {
  min-height: 46px;
  color: white;
  background: var(--green-dark);
}

.controls {
  padding: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: #f8f0df;
}

.control-btn {
  min-height: 66px;
  font-size: 44px;
  line-height: 1;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.08);
  touch-action: manipulation;
}

.control-btn.minus {
  color: var(--green-dark);
  background: var(--green-soft-2);
}

.control-btn.plus {
  color: white;
  background: #7bb069;
}

.control-btn:active,
.goal-row button:active,
.reset-btn:active {
  transform: translateY(1px);
}

.reset-btn {
  min-height: 42px;
  color: var(--danger);
  background: #fff0eb;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  transform: translateX(-50%) translateY(160%);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(36,70,49,.96);
  color: #fff;
  font-size: 14px;
  transition: transform .18s ease;
  z-index: 40;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

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

@keyframes twinkle {
  0%, 100% { opacity: .35; }
  50% { opacity: 1; }
}

@media (max-height: 740px) {
  .app {
    gap: 8px;
    padding-top: calc(10px + var(--safe-top));
    padding-bottom: calc(10px + var(--safe-bottom));
  }

  .plant-stage {
    width: min(51vw, 188px);
  }

  .count-row > span {
    font-size: 42px;
  }

  .control-btn {
    min-height: 58px;
    font-size: 40px;
  }
}

@media (min-width: 700px) {
  body {
    display: grid;
    place-items: center;
  }

  .app {
    height: min(920px, 100dvh);
    border-inline: 3px solid rgba(216,203,179,.55);
    background: rgba(255, 252, 245, .35);
  }
}
