:root {
  --ink: #3d2914;
  --cream: #fff8ee;
  --wood: #c47a3a;
  --wood-dark: #8a4b24;
  --leaf: #5f9a32;
  --gold: #e6a317;
  --rose: #e25d4a;
  --sky1: #79c6ea;
  --sky2: #ffe7b8;
  color: var(--ink);
  font-family: "Segoe UI", "PT Sans", "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--sky1);
}

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

#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 4px;
}

.coins {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: var(--cream);
  border: 3px solid var(--wood-dark);
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 44px;
}

.coins strong {
  font-size: 22px;
  line-height: 1;
}

.coins span {
  font-size: 12px;
  opacity: 0.75;
}

.icon-btn {
  margin-left: auto;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 3px solid var(--wood-dark);
  background: var(--cream);
  font-size: 18px;
  cursor: pointer;
}

.icon-btn + .icon-btn { margin-left: 0; }

main {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  position: relative;
  background:
    linear-gradient(180deg, var(--sky1) 0 28%, var(--sky2) 28% 46%, #b7e07a 46% 78%, #6aaa38 78%);
}

.sun {
  position: absolute;
  right: 8%;
  top: 18px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #ffe08a;
  box-shadow: 0 0 0 10px rgba(255, 224, 138, 0.35);
}

#scenery {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.decor {
  position: absolute;
  pointer-events: none;
}

.tree { left: 6%; top: 10%; width: 92px; height: 110px; z-index: 2; }
.bush { right: 6%; top: 22%; width: 86px; height: 48px; z-index: 2; }

.scene {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px 12px 8px;
  gap: 8px;
}

.places {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.places button {
  min-height: 40px;
  border-radius: 999px;
  border: 3px solid var(--wood-dark);
  background: #fff;
  padding: 6px 14px;
  font-weight: 800;
  cursor: pointer;
}

.places button.active { background: #ffe08a; }
.places button.buy { background: #d8f5d0; }

.shop .span {
  grid-column: 1 / -1;
  text-align: center;
}

#boosts {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 800;
  color: #8a4b24;
}

.shop button.solo em,
.shop button.solo small { display: none; }
.shop button.solo strong { font-size: 16px; }

.card.shop-card {
  width: min(520px, 100%);
  max-height: min(86vh, 640px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card.shop-card .stack { margin-top: 10px; }
.shop-body {
  overflow: auto;
  max-height: min(46vh, 420px);
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: #c4a574 transparent;
}
.shop-body::-webkit-scrollbar { width: 8px; }
.shop-body::-webkit-scrollbar-button { display: none; height: 0; }
.shop-body::-webkit-scrollbar-track { background: transparent; }
.shop-body::-webkit-scrollbar-thumb {
  background: #e7c99a;
  border: 2px solid var(--cream);
  border-radius: 99px;
}
.shop-tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.shop-tabs button { flex: 1; font-weight: 800; }
.shop-tabs button.active { background: #ffe08a; }
.shop-place { margin: 12px 0 4px; font-size: 16px; }
.shop-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #efe2cf;
}
.shop-row.premium { grid-template-columns: minmax(0, 1fr) auto; }
.shop-row strong, .shop-row em { display: block; }
.shop-row em { font-style: normal; font-weight: 650; font-size: 12px; opacity: 0.75; }
.shop-icon { width: 46px; height: 52px; }
.shop-icon svg { width: 46px; height: 52px; }
.shop-row button { min-height: 44px; min-width: 108px; font-weight: 800; }

#app[data-place="green"] main {
  background: linear-gradient(180deg, #7ee0d0 0 26%, #d8ffe8 26% 44%, #8fd96a 44% 76%, #2f8f45 76%);
}
#app[data-place="green"] .awning {
  background: repeating-linear-gradient(90deg, #0f766e 0 16px, #ecfdf5 16px 32px);
}
#app[data-place="roof"] main {
  background: linear-gradient(180deg, #7c6cff 0 24%, #ffb4d8 24% 44%, #9be07a 44% 76%, #2f7d46 76%);
}
#app[data-place="roof"] .sun {
  background: #f8f5ff;
  box-shadow: 0 0 0 10px rgba(248, 245, 255, 0.45);
}
#app[data-place="roof"] .awning {
  background: repeating-linear-gradient(90deg, #7c3aed 0 16px, #ffe4f3 16px 32px);
}

.sign {
  align-self: center;
  position: relative;
  z-index: 2;
  margin-bottom: -16px;
  background: #f4e2c2;
  border: 4px solid var(--wood-dark);
  border-radius: 12px;
  padding: 6px 16px 8px;
  box-shadow: 0 6px 0 rgba(61, 41, 20, 0.12);
  text-align: center;
}

.sign h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.2px;
}

.sign p {
  margin: 2px 0 0;
  font-size: 13px;
}

.stall {
  display: flex;
  flex-direction: column;
  background: linear-gradient(#e7b56a, var(--wood));
  border: 4px solid var(--wood-dark);
  border-radius: 18px 18px 12px 12px;
  padding: 0 8px 12px;
  box-shadow: 0 10px 0 rgba(90, 48, 18, 0.18);
}

.awning {
  height: 22px;
  margin: 0 -8px 8px;
  border-radius: 12px 12px 0 0;
  background: repeating-linear-gradient(
    90deg,
    var(--rose) 0 16px,
    #fff6ea 16px 32px
  );
  border-bottom: 4px solid var(--wood-dark);
}

.pots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 8px;
}

.empty {
  width: 100%;
  margin: 4px 0;
  padding: 22px 12px;
  text-align: center;
  font-weight: 800;
  background: rgba(255, 248, 238, 0.55);
  border: 3px dashed var(--wood-dark);
  border-radius: 16px;
}

.coach {
  margin-bottom: 8px;
  background: #ffe08a;
  border: 3px solid var(--wood-dark);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 800;
  text-align: center;
}

.shop button.guide-target,
.pot.guide-target {
  box-shadow: 0 0 0 3px #ffe08a;
  animation: bob 0.9s ease-in-out infinite;
}

.pot {
  width: 84px;
  background: rgba(255, 248, 238, 0.92);
  border: 3px solid var(--wood-dark);
  border-radius: 16px;
  padding: 6px 6px 8px;
  text-align: center;
  cursor: pointer;
  position: relative;
}

.pot.ready {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px #ffe08a;
  animation: bob 0.9s ease-in-out infinite;
}

.sprite-wrap {
  height: 92px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sprite-wrap svg {
  height: calc(46px + 44px * var(--g, 0.45));
  width: auto;
  filter: drop-shadow(0 8px 0 rgba(80, 40, 10, 0.08));
}

.bar {
  height: 8px;
  background: #efe2cf;
  border-radius: 99px;
  overflow: hidden;
  border: 2px solid var(--wood-dark);
}

.bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--leaf);
}

.pname, .time {
  font-size: 12px;
  margin-top: 3px;
  font-weight: 700;
}

.time { font-weight: 600; opacity: 0.8; }

.cycle {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid var(--wood-dark);
  background: #fff;
  cursor: pointer;
}

.actions {
  display: flex;
  gap: 8px;
}

.wide, .shop button, .modal button {
  min-height: 48px;
  border-radius: 14px;
  border: 3px solid var(--wood-dark);
  background: var(--cream);
  cursor: pointer;
  padding: 8px 10px;
  text-align: left;
}

.wide {
  flex: 1;
  text-align: center;
  font-weight: 700;
  background: #fff1c9;
}

.wide.ghost { background: var(--cream); }

.wide:disabled, .shop button:disabled {
  opacity: 0.55;
  cursor: default;
}

footer {
  padding: 8px;
  background: #f6e7cf;
  border-top: 4px solid var(--wood-dark);
}

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

.shop button strong, .shop button em, .shop button small {
  display: block;
  font-style: normal;
}

.shop button strong { font-size: 14px; }
.shop button em { font-size: 12px; opacity: 0.75; margin: 2px 0; }
.shop button small { font-weight: 800; color: #8a4b24; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(61, 41, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 5;
}

.modal.hidden { display: none; }

.card {
  width: min(440px, 100%);
  max-height: min(88vh, 640px);
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #c4a574 transparent;
  background: var(--cream);
  border: 4px solid var(--wood-dark);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 12px 0 rgba(61, 41, 20, 0.15);
}

.card::-webkit-scrollbar { width: 8px; }
.card::-webkit-scrollbar-button { display: none; height: 0; }
.card::-webkit-scrollbar-track { background: transparent; }
.card::-webkit-scrollbar-thumb {
  background: #e7c99a;
  border: 2px solid var(--cream);
  border-radius: 99px;
}
.card h2 { margin: 0 0 8px; font-size: 22px; }
.card p { margin: 0 0 10px; line-height: 1.35; }
.card .stack { display: flex; flex-direction: column; gap: 8px; }
.card .stack button { text-align: center; font-weight: 700; }
.board {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
}
.board li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid #efe2cf;
  font-weight: 700;
}
.board li.me { background: #ffe08a; margin: 0 -8px; padding: 6px 8px; border-radius: 8px; }
.board-name {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 700;
  margin-bottom: 8px;
}
.board-name input {
  min-height: 44px;
  border: 3px solid var(--wood-dark);
  border-radius: 12px;
  padding: 6px 10px;
  background: #fff;
}
.primary { background: #ffe08a !important; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 118px;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 14px;
  border-radius: 12px;
  z-index: 6;
  max-width: 90%;
  text-align: center;
}

.floater {
  position: fixed;
  z-index: 4;
  font-weight: 800;
  color: #8a4b24;
  pointer-events: none;
  animation: rise 0.8s ease forwards;
}

.bubble {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  background: white;
  border: 3px solid var(--wood-dark);
  border-radius: 14px;
  padding: 6px 10px;
  font-weight: 800;
  animation: rise 1.1s ease forwards;
}

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

@keyframes rise {
  to { opacity: 0; transform: translate(-50%, -28px); }
}

@media (max-width: 640px) {
  .actions { flex-direction: column; }
  .shop { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pot { width: 78px; }
  .sprite-wrap { height: 84px; }
  .tree { top: 4px; width: 54px; height: 64px; }
  .bush { display: none; }
  .sun { top: 6px; width: 40px; height: 40px; }
  .scene { padding-top: 58px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  #app {
    grid-template-columns: minmax(0, 1fr) 280px;
    grid-template-rows: auto minmax(0, 1fr);
  }
  header { grid-column: 1 / -1; }
  main { grid-column: 1; grid-row: 2; }
  footer { grid-column: 2; grid-row: 2; overflow: auto; }
  .shop { grid-template-columns: 1fr; }
  .tree { height: 80px; }
  .sprite-wrap { height: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  .pot.ready, .floater, .bubble { animation: none; }
}
