:root {
  color-scheme: dark;
  --grass: #176f3b;
  --grass-dark: #0b3f2a;
  --line: rgba(255,255,255,.82);
  --panel: rgba(9, 28, 31, .88);
  --panel-strong: rgba(8, 18, 22, .96);
  --gold: #ffd45a;
  --mint: #62e6a9;
  --red: #ff6370;
  --blue: #5cc8ff;
  --text: #f7fff9;
  --muted: #b9d4ca;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #062618; color: var(--text); }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }

#app {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 480px;
  background:
    radial-gradient(circle at 30% 20%, rgba(98,230,169,.22), transparent 30%),
    linear-gradient(135deg, #083b25, #0d5934 48%, #0a2a28);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, rgba(5,24,19,.88), rgba(4,42,38,.62));
  z-index: 10;
}
.screen.active { display: grid; }
.screen.overlay { background: rgba(0, 0, 0, .48); backdrop-filter: blur(8px); }

.brand-stack, .menu-panel, .dialog {
  width: min(440px, calc(100vw - 32px));
  text-align: center;
  padding: 30px;
  border: 1px solid rgba(255,255,255,.12);
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0,0,0,.38);
  border-radius: 8px;
}

.dialog {
  opacity: 0;
  transform: translateY(16px) scale(.98);
  animation: pop .28s ease forwards;
}

@keyframes pop {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.brand-stack { background: transparent; border: 0; box-shadow: none; }
h1, h2 { margin: 0 0 12px; letter-spacing: 0; line-height: 1.02; }
h1 { font-size: clamp(2.2rem, 7vw, 4.9rem); }
h2 { font-size: clamp(1.8rem, 4vw, 3rem); }
p { margin: 0; }
.subtitle { color: var(--muted); margin-bottom: 20px; line-height: 1.45; }
.micro { color: var(--muted); font-size: .9rem; }

.ball-mark {
  width: 74px;
  height: 74px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fff 0 16%, #111 17% 24%, #fff 25% 42%, #111 43% 49%, #fff 50%);
  box-shadow: 0 14px 30px rgba(0,0,0,.25);
  animation: float 1.8s ease-in-out infinite;
}

.progress-shell {
  width: min(430px, 82vw);
  height: 12px;
  margin: 22px auto 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.14);
  overflow: hidden;
}
.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--mint), var(--gold));
  border-radius: inherit;
  transition: width .2s ease;
}

.primary-btn, .small-btn, .icon-btn, .hud-btn {
  min-height: 46px;
  border-radius: 8px;
  padding: 0 22px;
  margin: 8px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.13);
  box-shadow: 0 10px 24px rgba(0,0,0,.22);
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.primary-btn {
  min-width: 180px;
  background: linear-gradient(135deg, #18b66a, #11a7a2);
  color: white;
  font-weight: 800;
}
.small-btn, .icon-btn { color: var(--text); background: rgba(255,255,255,.09); }
button:hover { transform: translateY(-2px); background-color: rgba(255,255,255,.16); }
button:active { transform: translateY(1px) scale(.99); }

.wallet {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 14px;
  background: rgba(255,212,90,.13);
  border: 1px solid rgba(255,212,90,.24);
  border-radius: 999px;
  color: #ffe9a1;
}
.wallet.compact { margin: 0; }
.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.top-actions .small-btn { margin: 0; min-height: 40px; padding: 0 14px; }

.topbar {
  align-self: start;
  display: grid;
  grid-template-columns: 110px 1fr auto;
  align-items: center;
  gap: 12px;
  width: min(980px, 100%);
  margin: 0 auto 18px;
}
.topbar h2 { text-align: center; margin: 0; }

.level-grid {
  width: min(980px, 100%);
  max-height: calc(100svh - 120px);
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: 12px;
  padding: 6px 6px 24px;
}
.level-card {
  aspect-ratio: 1;
  border-radius: 8px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.14);
  display: grid;
  place-items: center;
  position: relative;
  font-weight: 900;
}
.level-card.unlocked { background: linear-gradient(145deg, rgba(28,188,109,.9), rgba(20,122,155,.88)); }
.level-card.locked { opacity: .42; cursor: default; }
.level-stars { position: absolute; bottom: 7px; font-size: .78rem; color: var(--gold); }

.shop-topbar { margin-bottom: 8px; }
.shop-grid {
  width: min(980px, 100%);
  max-height: calc(100svh - 120px);
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  padding: 8px 6px 26px;
}
.shop-card {
  min-height: 205px;
  padding: 18px;
  border-radius: 8px;
  background: rgba(8, 28, 31, .86);
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 18px 38px rgba(0,0,0,.24);
  display: grid;
  gap: 8px;
  justify-items: center;
  align-content: center;
  text-align: center;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.shop-card:hover {
  transform: translateY(-4px);
  border-color: rgba(98,230,169,.46);
  box-shadow: 0 24px 52px rgba(0,0,0,.3);
}
.shop-card.selected { border-color: rgba(255,212,90,.62); }
.shop-card h3 { margin: 0; font-size: 1.05rem; }
.shop-card p { color: var(--muted); }
.shop-icon {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: linear-gradient(145deg, rgba(255,255,255,.95), rgba(200,230,235,.78));
  color: #14312c;
  box-shadow: inset 0 -5px 12px rgba(0,0,0,.16), 0 10px 24px rgba(0,0,0,.18);
}
.skin-fire { background: radial-gradient(circle at 35% 30%, #fff1a2, #ff8a28 45%, #a3231a); color: #fff; }
.skin-neon { background: radial-gradient(circle at 35% 30%, #f2ffff, #43f5ff 48%, #2a43ff); color: #061a30; }
.skin-gold { background: radial-gradient(circle at 35% 30%, #fff8bd, #ffd45a 48%, #a86900); color: #321e00; }
.buy-btn {
  min-width: 112px;
  min-height: 38px;
  border-radius: 8px;
  padding: 0 16px;
  background: linear-gradient(135deg, #18b66a, #11a7a2);
  font-weight: 800;
}
.buy-btn:disabled {
  opacity: .65;
  cursor: default;
  transform: none;
  background: rgba(255,255,255,.16);
}
.toast {
  position: absolute;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(24px);
  min-width: 220px;
  padding: 12px 18px;
  border-radius: 8px;
  text-align: center;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: rgba(24,182,106,.94); }
.toast.error { background: rgba(255,99,112,.94); }

.hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(5, 20, 22, .56);
  backdrop-filter: blur(8px);
}
.hud.active { display: flex; }
.hud-pill, .hud-btn {
  min-height: 38px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.12);
  white-space: nowrap;
}

.stars {
  height: 72px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  color: var(--gold);
  font-size: 3rem;
}
.star-pop { animation: starPop .5s cubic-bezier(.2, 1.8, .3, 1) both; }

@keyframes float { 50% { transform: translateY(-9px) rotate(8deg); } }
@keyframes starPop { from { transform: scale(.2) rotate(-20deg); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (max-width: 680px) {
  #app { min-height: 420px; }
  .screen { padding: 16px; }
  .topbar { grid-template-columns: 76px 1fr 88px; gap: 6px; }
  .top-actions { flex-direction: column; align-items: flex-end; gap: 4px; }
  .top-actions .small-btn { min-height: 32px; font-size: .8rem; }
  .wallet.compact { font-size: .8rem; padding: 8px; }
  .level-grid { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; }
  .shop-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .shop-card { min-height: 176px; padding: 14px; }
  .hud { top: auto; bottom: max(10px, env(safe-area-inset-bottom)); max-width: calc(100vw - 16px); flex-wrap: wrap; justify-content: center; }
  .hud-pill, .hud-btn { min-height: 34px; font-size: .85rem; padding: 7px 10px; }
  .brand-stack, .menu-panel, .dialog { padding: 22px; }
}
