:root {
  --grass-dark: #1b4332;
  --grass-mid: #2d6a4f;
  --grass-light: #40916c;
  --cream: #f4ecd8;
  --gold: #ffd166;
  --loss: #ff6b6b;
  --gain: #6ee7a7;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--grass-dark);
  color: var(--cream);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.topbar {
  text-align: center;
  padding: 18px 16px 8px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.25rem, 5vw, 1.6rem);
  line-height: 1.2;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.85rem;
  opacity: 0.75;
}

.stats {
  display: flex;
  justify-content: space-around;
  gap: 8px;
  padding: 10px 16px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 12px;
  padding: 8px 14px;
  flex: 1;
  min-width: 0;
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 2px;
}

.ground {
  position: relative;
  flex: 1;
  margin: 8px 16px;
  border-radius: 20px;
  background: linear-gradient(180deg, #4a5a60 0%, #6b7b80 28%, #889498 100%);
  overflow: hidden;
  min-height: 260px;
}

.skyline {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  opacity: 0.55;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 80' preserveAspectRatio='none'%3E%3Crect x='0' y='40' width='40' height='40' fill='%23263238'/%3E%3Crect x='45' y='25' width='30' height='55' fill='%23263238'/%3E%3Cpolygon points='90,80 110,8 130,80' fill='%23263238'/%3E%3Crect x='140' y='35' width='35' height='45' fill='%23263238'/%3E%3Crect x='180' y='15' width='25' height='65' fill='%23263238'/%3E%3Crect x='210' y='45' width='40' height='35' fill='%23263238'/%3E%3Crect x='270' y='10' width='8' height='70' fill='%23b33a24'/%3E%3Crect x='330' y='10' width='8' height='70' fill='%23b33a24'/%3E%3Crect x='270' y='20' width='68' height='5' fill='%23b33a24'/%3E%3Crect x='360' y='30' width='30' height='50' fill='%23263238'/%3E%3C/svg%3E");
  background-size: 100% 100%;
}

.sidewalk-texture {
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.14) 0 2px, transparent 2px 72px),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.1) 0 2px, transparent 2px 130px),
    radial-gradient(circle at 20% 80%, rgba(0,0,0,0.1), transparent 40%),
    radial-gradient(circle at 78% 55%, rgba(0,0,0,0.08), transparent 35%);
  pointer-events: none;
}

.clutter {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.clutter-item {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--r, 0deg));
  opacity: 0.92;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
  pointer-events: none;
}

.money-spot {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
}

.money {
  position: relative;
  background: none;
  border: none;
  font-size: clamp(3rem, 18vw, 5rem);
  line-height: 1;
  cursor: pointer;
  padding: 20px;
  border-radius: 50%;
  animation: bob 1.8s ease-in-out infinite;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.35));
}

.money:active {
  transform: scale(0.88);
}

.money.shake {
  animation: shake 0.4s ease;
}

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

@keyframes shake {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  20% { transform: translate(-6px, 2px) rotate(-8deg); }
  40% { transform: translate(6px, -2px) rotate(8deg); }
  60% { transform: translate(-4px, 2px) rotate(-6deg); }
  80% { transform: translate(4px, -1px) rotate(6deg); }
}

.hint {
  position: absolute;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 86%;
  text-align: center;
  font-size: 0.78rem;
  opacity: 0.9;
  background: rgba(0, 0, 0, 0.3);
  padding: 5px 12px;
  border-radius: 999px;
  z-index: 4;
}

.walker {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 30px;
  z-index: 5;
  pointer-events: none;
}

.leg {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: top center;
  animation: step 0.9s ease-in-out infinite;
}

.leg-right {
  animation-delay: 0.45s;
}

.pant {
  width: 20px;
  height: 40px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, #3b5bab, #2c4480);
  box-shadow: inset -4px 0 6px rgba(0, 0, 0, 0.25);
}

.shoe {
  font-size: 1.6rem;
  margin-top: -6px;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.4));
}

@keyframes step {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-9px) rotate(3deg); }
}

.result-card {
  margin: 10px 16px calc(14px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.35);
  border-radius: 18px;
  padding: 18px 16px;
  text-align: center;
  animation: rise 0.25s ease;
}

@keyframes rise {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.result-emoji {
  font-size: 2.6rem;
}

.result-text {
  font-size: 1rem;
  font-weight: 600;
  margin: 8px 0 4px;
}

.result-delta {
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0 0 10px;
}

.result-delta.gain { color: var(--gain); }
.result-delta.loss { color: var(--loss); }
.result-delta.flat { color: var(--cream); opacity: 0.85; }

.lesson {
  margin: 0 0 14px;
  font-size: 0.85rem;
  font-style: italic;
  opacity: 0.9;
  border-left: 3px solid var(--gold);
  padding-left: 10px;
  text-align: left;
}

.again-btn {
  background: var(--gold);
  color: #3a2a00;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 700;
  width: 100%;
  cursor: pointer;
}

.again-btn:active {
  transform: scale(0.97);
}

.footer {
  text-align: center;
  padding: 0 16px 14px;
  font-size: 0.7rem;
  opacity: 0.55;
}

.footer p {
  margin: 0;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}

.confetti-piece {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation: fall linear forwards;
}

@keyframes fall {
  to {
    transform: translateY(110vh) rotate(540deg);
    opacity: 0;
  }
}
