/* ===== Base ===== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #fff;
}

body {
  background: linear-gradient(160deg, #2b8a57 0%, #14573a 60%, #0c3a28 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

.screen {
  display: none;
  min-height: 100vh;
  padding: 16px;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeIn .5s ease;
}

#welcome.active {
  justify-content: center;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  
  to {
    opacity: 1;
    transform: none;
  }
}

/* ===== Welcome ===== */
.welcome-card {
  text-align: center;
  max-width: 380px;
  padding: 32px 24px;
  border-radius: 28px;
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(255, 255, 255, .18);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .4);
}

.welcome-card h1 {
  margin: 10px 0 8px;
  font-size: 40px;
  letter-spacing: 1px;
}

.welcome-card p {
  opacity: .85;
  line-height: 1.5;
  margin: 0 0 24px;
}

.veg-row {
  font-size: 34px;
  display: flex;
  justify-content: center;
  gap: 6px;
}

.veg-row span {
  animation: bob 1.6s ease-in-out infinite;
}

.veg-row span:nth-child(2) {
  animation-delay: .15s;
}

.veg-row span:nth-child(3) {
  animation-delay: .3s;
}

.veg-row span:nth-child(4) {
  animation-delay: .45s;
}

.veg-row span:nth-child(5) {
  animation-delay: .6s;
}

.veg-row span:nth-child(6) {
  animation-delay: .75s;
}

@keyframes bob {

  0%,
  100% {
    transform: translateY(0);
  }
  
  50% {
    transform: translateY(-10px);
  }
}

.btn {
  padding: 14px 40px;
  border: 0;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  color: #4a2a00;
  background: linear-gradient(#ffe27a, #ffb52e);
  box-shadow: 0 6px 0 #c57d00, 0 10px 20px rgba(0, 0, 0, .3);
  transition: transform .12s, box-shadow .12s;
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #c57d00;
}

/* ===== HUD ===== */
.hud {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 480px;
  margin-top: 6px;
}

.stat {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  border-radius: 16px;
  background: rgba(0, 0, 0, .3);
}

.stat small {
  display: block;
  opacity: .7;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat b {
  font-size: 24px;
  display: inline-block;
}

.stat b.bump {
  animation: bump .3s ease;
}

@keyframes bump {
  50% {
    transform: scale(1.35);
    color: #ffe27a;
  }
}

.goal {
  width: 100%;
  max-width: 480px;
  margin: 10px 0 14px;
  text-align: center;
}

.bar {
  height: 12px;
  border-radius: 99px;
  background: rgba(0, 0, 0, .35);
  overflow: hidden;
  margin-bottom: 4px;
}

.bar i {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left;
  transform: scaleX(0);
  background: linear-gradient(90deg, #ffe27a, #ff9f1c);
  transition: transform .5s cubic-bezier(.2, .8, .2, 1);
}

.goal small {
  opacity: .8;
}

/* ===== Board ===== */
#wrap {
  width: 100%;
  max-width: 480px;
}

#board {
  --s: 56px;
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
  border-radius: 20px;
  overflow: hidden;
  background: repeating-conic-gradient(rgba(255, 255, 255, .09) 0 25%, rgba(255, 255, 255, .03) 0 50%) 0 0 / calc(var(--s) * 2) calc(var(--s) * 2), rgba(0, 0, 0, .35);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .12), 0 14px 30px rgba(0, 0, 0, .4);
}

/* Tile = outer positioned element (transform only), face = inner visual (pop/select) */
.tile {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--s);
  height: var(--s);
  padding: 3px;
  will-change: transform;
  cursor: pointer;
  transition: transform 300ms cubic-bezier(.34, 1.3, .64, 1);
}

.tile.sel {
  z-index: 5;
}

.face {
  width: 100%;
  height: 100%;
  border-radius: 30%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--s) * .56);
  line-height: 1;
  background: radial-gradient(circle at 30% 22%, rgba(255, 255, 255, .6), rgba(255, 255, 255, 0) 52%), var(--c);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18), 0 3px 6px rgba(0, 0, 0, .35);
  transition: transform .18s cubic-bezier(.34, 1.56, .64, 1), box-shadow .18s;
}

.tile:hover .face {
  transform: scale(1.06);
}

.tile.sel .face {
  transform: scale(1.14);
  box-shadow: 0 0 0 3px #fff, 0 0 18px 6px var(--c);
  animation: pulse .8s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.2);
  }
}

.tile.pop {
  z-index: 4;
  pointer-events: none;
}

.tile.pop .face {
  animation: pop .32s ease-in forwards;
}

@keyframes pop {
  0% {
    transform: scale(1);
    opacity: 1;
    filter: brightness(1);
  }
  
  40% {
    transform: scale(1.35);
    opacity: 1;
    filter: brightness(1.7);
  }
  
  100% {
    transform: scale(0) rotate(45deg);
    opacity: 0;
  }
}

.tile.spawn .face {
  animation: land .3s ease-out;
}

@keyframes land {
  0% {
    transform: scale(1, .8);
  }
  
  60% {
    transform: scale(1, 1.1);
  }
  
  100% {
    transform: scale(1);
  }
}

/* ===== Floating score & toast ===== */
.float {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  font-weight: 900;
  font-size: 24px;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .6);
  animation: floatUp .9s ease-out forwards;
}

@keyframes floatUp {
  from {
    transform: translate(-50%, 0) scale(.6);
    opacity: 1;
  }
  
  to {
    transform: translate(-50%, -60px) scale(1.2);
    opacity: 0;
  }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 99px;
  background: rgba(0, 0, 0, .7);
  opacity: 0;
  transition: opacity .3s, transform .3s;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
  padding: 20px;
  z-index: 100;
}

.modal.open {
  display: flex;
  animation: fadeOnly .3s ease;
}

@keyframes fadeOnly {
  from {
    opacity: 0;
  }
}

.modal-card {
  text-align: center;
  max-width: 340px;
  width: 100%;
  padding: 28px 22px;
  border-radius: 24px;
  background: linear-gradient(#2b8a57, #14573a);
  border: 2px solid #ffe27a;
  animation: zoom .45s cubic-bezier(.2, 1.4, .4, 1);
}

@keyframes zoom {
  from {
    transform: scale(.6);
    opacity: 0;
  }
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 28px;
  color: #ffe27a;
}

.modal-card p {
  margin: 0 0 20px;
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {

  .veg-row span,
  .tile.sel .face {
    animation: none;
  }
}