* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', Verdana, Arial, sans-serif;
  background: #9fd3f5;
  color: #eef4fb;
  -webkit-user-select: none;
  user-select: none;
}

#scene-container {
  position: fixed;
  inset: 0;
  cursor: grab;
  touch-action: none;
}
#scene-container canvas { display: block; touch-action: none; }

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.panel, #stats, #customer, #shop-panel {
  background: rgba(14, 28, 48, 0.78);
  border: 1px solid rgba(140, 200, 255, 0.35);
  border-radius: 12px;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

#stats {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 8px 12px;
  min-width: 140px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  padding: 2px 0;
}
.stat-label { opacity: 0.85; }
#stat-money { color: #8dff8a; font-weight: 700; }

.corner-btn {
  pointer-events: auto;
  position: absolute;
  top: 12px;
  right: 12px;
  background: linear-gradient(#2e9be6, #1a73b8);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}
.corner-btn:hover { filter: brightness(1.1); }

#customer {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(340px, calc(100vw - 340px));
  min-width: 220px;
  padding: 8px 12px 10px;
  font-size: 13px;
}
#customer.hidden { display: none; }
.cust-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}
#cust-pay { color: #8dff8a; white-space: nowrap; }
.bar-label { margin-top: 4px; opacity: 0.9; display: flex; justify-content: space-between; }
.bar {
  height: 10px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 2px;
}
.bar-fill { height: 100%; width: 0; border-radius: 6px; transition: width 0.15s linear; }
.bar-fill.patience { background: linear-gradient(90deg, #ffd23f, #7be37b); width: 100%; }
.bar-fill.patience.low { background: #ff5252; animation: blink 0.6s infinite alternate; }
.bar-fill.clean { background: linear-gradient(90deg, #4fc3f7, #b3f0ff); }
@keyframes blink { from { opacity: 1; } to { opacity: 0.45; } }

#narration {
  position: absolute;
  top: 128px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  max-width: min(560px, calc(100vw - 32px));
  text-align: center;
  background: rgba(14, 28, 48, 0.82);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 15px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
}
#narration.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#pops { position: absolute; inset: 0; overflow: hidden; }
.pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 26px;
  font-weight: 900;
  color: #8dff8a;
  text-shadow: 0 3px 0 #0b3d17, 0 0 12px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  animation: pop-up 1.6s ease-out forwards;
}
.pop.yeet { color: #ffffff; text-shadow: 0 3px 0 #b3261e, 0 0 12px rgba(0, 0, 0, 0.5); }
.pop.gold { color: #ffd23f; font-size: 32px; text-shadow: 0 3px 0 #7a4a00, 0 0 16px rgba(255, 210, 63, 0.7); }
.pop.angry { color: #ff8a80; text-shadow: 0 3px 0 #5d0000; }
@keyframes pop-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -260%) scale(1); }
}

#toolbar {
  position: absolute;
  bottom: 34px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}
.tools { display: flex; gap: 8px; }
.tool-btn, .rot-btn {
  pointer-events: auto;
  background: rgba(14, 28, 48, 0.82);
  color: #fff;
  border: 2px solid rgba(140, 200, 255, 0.35);
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
}
.tool-btn {
  width: 92px;
  padding: 6px 4px 8px;
  font-size: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tool-btn span { font-size: 12px; font-weight: 600; }
.tool-btn.active { border-color: #ffd23f; background: rgba(40, 70, 110, 0.92); box-shadow: 0 0 12px rgba(255, 210, 63, 0.5); }
.rot-btn { width: 48px; height: 48px; font-size: 24px; }
.rot-btn:active, .tool-btn:active { transform: scale(0.95); }
.water {
  width: 70px;
  height: 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
  overflow: hidden;
}
#water-fill { height: 100%; width: 100%; background: #4fc3f7; }
#water-fill.low { background: #ff7043; }

#controls-hint {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  color: #0e2238;
  font-weight: 600;
  padding: 0 16px;
}

#shop-panel {
  pointer-events: auto;
  position: absolute;
  top: 64px;
  right: 12px;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  padding: 10px 12px;
}
#shop-panel.hidden { display: none; }
#shop-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 8px;
}
#shop-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.shop-info { flex: 1; }
.shop-name { font-weight: 700; font-size: 14px; }
.shop-level { font-weight: 400; opacity: 0.75; font-size: 12px; }
.shop-desc { font-size: 12px; opacity: 0.8; margin-top: 2px; }
.shop-buy {
  background: linear-gradient(#43c25a, #2a9a40);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
  min-width: 64px;
}
.shop-buy:disabled { background: #556070; cursor: not-allowed; opacity: 0.7; }

@media (max-width: 640px) {
  #stats { padding: 6px 10px; min-width: 0; }
  .stat-row { font-size: 12px; }
  #customer { top: auto; bottom: 120px; width: calc(100vw - 32px); }
  #narration { top: 96px; font-size: 13px; }
  .corner-btn { padding: 8px 12px; font-size: 14px; }
  .tool-btn { width: 80px; font-size: 22px; }
  #toolbar { bottom: 28px; }
  #controls-hint { display: none; }
}
